20#include <xrpld/app/ledger/LedgerMaster.h>
21#include <xrpld/app/ledger/LedgerToJson.h>
22#include <xrpld/app/misc/DeliverMax.h>
23#include <xrpld/app/misc/TxQ.h>
24#include <xrpld/rpc/Context.h>
25#include <xrpld/rpc/DeliveredAmount.h>
26#include <xrpld/rpc/MPTokenIssuanceID.h>
28#include <xrpl/basics/base_uint.h>
29#include <xrpl/protocol/ApiVersion.h>
30#include <xrpl/protocol/jss.h>
37isFull(LedgerFill
const& fill)
43isExpanded(LedgerFill
const& fill)
49isBinary(LedgerFill
const& fill)
54template <
class Object>
63 json[jss::parent_hash] =
to_string(info.parentHash);
64 json[jss::ledger_index] = (apiVersion > 1)
70 json[jss::closed] =
true;
74 json[jss::closed] =
false;
78 json[jss::ledger_hash] =
to_string(info.hash);
79 json[jss::transaction_hash] =
to_string(info.txHash);
80 json[jss::account_hash] =
to_string(info.accountHash);
81 json[jss::total_coins] =
to_string(info.drops);
83 json[jss::close_flags] = info.closeFlags;
86 json[jss::parent_close_time] =
87 info.parentCloseTime.time_since_epoch().count();
88 json[jss::close_time] = info.closeTime.time_since_epoch().count();
89 json[jss::close_time_resolution] = info.closeTimeResolution.count();
93 json[jss::close_time_human] =
to_string(info.closeTime);
95 json[jss::close_time_estimated] =
true;
100template <
class Object>
102fillJsonBinary(Object& json,
bool closed,
LedgerInfo const& info)
105 json[jss::closed] =
false;
108 json[jss::closed] =
true;
112 json[jss::ledger_data] =
strHex(s.peekData());
118 LedgerFill
const& fill,
125 return to_string(txn->getTransactionID());
128 auto const txnType = txn->getTxnType();
132 if (
fill.context->apiVersion > 1)
133 txJson[jss::hash] =
to_string(txn->getTransactionID());
135 auto const json_meta =
136 (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
140 else if (
fill.context->apiVersion > 1)
143 txJson[jss::tx_json],
145 txJson[jss::hash] =
to_string(txn->getTransactionID());
147 txJson[jss::tx_json], txnType,
fill.context->apiVersion);
154 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
159 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
165 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
168 if (!
fill.ledger.open())
169 txJson[jss::ledger_hash] =
to_string(
fill.ledger.info().hash);
171 const bool validated =
172 fill.context->ledgerMaster.isValidated(
fill.ledger);
173 txJson[jss::validated] = validated;
176 auto const seq =
fill.ledger.seq();
177 txJson[jss::ledger_index] = seq;
191 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
193 txJson[jss::metaData],
196 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
200 txJson[jss::metaData],
202 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
207 txn->getTxnType() == ttOFFER_CREATE)
209 auto const account = txn->getAccountID(sfAccount);
210 auto const amount = txn->getFieldAmount(sfTakerGets);
214 if (account != amount.getIssuer())
222 txJson[jss::owner_funds] = ownerFunds.getText();
229template <
class Object>
231fillJsonTx(Object& json, LedgerFill
const& fill)
233 auto&& txns =
setArray(json, jss::transactions);
234 auto bBinary = isBinary(fill);
235 auto bExpanded = isExpanded(fill);
239 auto appendAll = [&](
auto const& txs) {
243 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
247 appendAll(
fill.ledger.txs);
254 JLOG(
fill.context->j.error())
255 <<
"Exception in " << __func__ <<
": " << ex.
what();
260template <
class Object>
262fillJsonState(Object& json, LedgerFill
const& fill)
264 auto& ledger =
fill.ledger;
266 auto expanded = isExpanded(fill);
267 auto binary = isBinary(fill);
269 for (
auto const& sle : ledger.sles)
287template <
class Object>
289fillJsonQueue(Object& json, LedgerFill
const& fill)
292 auto bBinary = isBinary(fill);
293 auto bExpanded = isExpanded(fill);
295 for (
auto const& tx :
fill.txQueue)
298 txJson[jss::fee_level] =
to_string(tx.feeLevel);
300 txJson[jss::LastLedgerSequence] = *tx.lastValid;
302 txJson[jss::fee] =
to_string(tx.consequences.fee());
304 tx.consequences.potentialSpend() + tx.consequences.fee();
305 txJson[jss::max_spend_drops] =
to_string(spend);
306 txJson[jss::auth_change] = tx.consequences.isBlocker();
308 txJson[jss::account] =
to_string(tx.account);
309 txJson[
"retries_remaining"] = tx.retriesRemaining;
310 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
312 txJson[
"last_result"] =
transToken(*tx.lastResult);
314 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
315 if (
fill.context->apiVersion > 1)
322template <
class Object>
324fillJson(Object& json, LedgerFill
const& fill)
328 auto bFull = isFull(fill);
330 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
337 (
fill.context ?
fill.context->apiVersion
341 fillJsonTx(json, fill);
344 fillJsonState(json, fill);
353 fillJson(
object, fill);
356 fillJsonQueue(json, fill);
363 fillJson(json, fill);
A generic endpoint for log messages.
std::chrono::time_point< NetClock > time_point
@ objectValue
object value (collection of name/value pairs).
Json::Value & setArray(Json::Value &, Json::StaticString const &key)
Add a new subarray at a named key in a Json object.
Json::Value & addObject(Json::Value &, Json::StaticString const &key)
Add a new subobject at a named key in a Json object.
Json::Value & appendObject(Json::Value &)
Append a new subobject to a Json object.
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
static constexpr auto apiMaximumSupportedVersion
void insertMPTokenIssuanceID(Json::Value &response, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
void insertDeliveredAmount(Json::Value &meta, ReadView const &, std::shared_ptr< STTx const > const &serializedTx, TxMeta const &)
Add a delivered_amount field to the meta input/output parameter.
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool getCloseAgree(LedgerHeader const &info)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Object or Json::Value with a description of the ledger.
std::string strHex(FwdIt begin, FwdIt end)
std::string transToken(TER code)
std::string to_string_iso(date::sys_time< Duration > tp)
std::string to_string(base_uint< Bits, Tag > const &a)
@ ltANY
A special type, matching any ledger entry type.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)