1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/ledger/LedgerToJson.h>
3#include <xrpld/app/misc/DeliverMax.h>
4#include <xrpld/app/misc/TxQ.h>
5#include <xrpld/rpc/Context.h>
6#include <xrpld/rpc/DeliveredAmount.h>
7#include <xrpld/rpc/MPTokenIssuanceID.h>
9#include <xrpl/basics/base_uint.h>
10#include <xrpl/protocol/ApiVersion.h>
11#include <xrpl/protocol/jss.h>
18isFull(LedgerFill
const& fill)
24isExpanded(LedgerFill
const& fill)
30isBinary(LedgerFill
const& fill)
39 LedgerHeader
const& info,
43 json[jss::parent_hash] =
to_string(info.parentHash);
44 json[jss::ledger_index] = (apiVersion > 1)
50 json[jss::closed] =
true;
54 json[jss::closed] =
false;
58 json[jss::ledger_hash] =
to_string(info.hash);
59 json[jss::transaction_hash] =
to_string(info.txHash);
60 json[jss::account_hash] =
to_string(info.accountHash);
61 json[jss::total_coins] =
to_string(info.drops);
63 json[jss::close_flags] = info.closeFlags;
66 json[jss::parent_close_time] =
67 info.parentCloseTime.time_since_epoch().count();
68 json[jss::close_time] = info.closeTime.time_since_epoch().count();
69 json[jss::close_time_resolution] = info.closeTimeResolution.count();
73 json[jss::close_time_human] =
to_string(info.closeTime);
75 json[jss::close_time_estimated] =
true;
81fillJsonBinary(
Json::Value& json,
bool closed, LedgerHeader
const& info)
84 json[jss::closed] =
false;
87 json[jss::closed] =
true;
91 json[jss::ledger_data] =
strHex(s.peekData());
97 LedgerFill
const& fill,
104 return to_string(txn->getTransactionID());
107 auto const txnType = txn->getTxnType();
111 if (
fill.context->apiVersion > 1)
112 txJson[jss::hash] =
to_string(txn->getTransactionID());
114 auto const json_meta =
115 (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
119 else if (
fill.context->apiVersion > 1)
122 txJson[jss::tx_json],
124 txJson[jss::hash] =
to_string(txn->getTransactionID());
126 txJson[jss::tx_json], txnType,
fill.context->apiVersion);
133 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
138 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
144 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
147 if (!
fill.ledger.open())
148 txJson[jss::ledger_hash] =
to_string(
fill.ledger.header().hash);
150 bool const validated =
151 fill.context->ledgerMaster.isValidated(
fill.ledger);
152 txJson[jss::validated] = validated;
155 auto const seq =
fill.ledger.seq();
156 txJson[jss::ledger_index] = seq;
170 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
172 txJson[jss::metaData],
175 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
179 txJson[jss::metaData],
181 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
186 txn->getTxnType() == ttOFFER_CREATE)
188 auto const account = txn->getAccountID(sfAccount);
189 auto const amount = txn->getFieldAmount(sfTakerGets);
193 if (account !=
amount.getIssuer())
201 txJson[jss::owner_funds] = ownerFunds.getText();
209fillJsonTx(
Json::Value& json, LedgerFill
const& fill)
212 auto bBinary = isBinary(fill);
213 auto bExpanded = isExpanded(fill);
217 auto appendAll = [&](
auto const& txs) {
221 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
225 appendAll(
fill.ledger.txs);
232 JLOG(
fill.context->j.error())
233 <<
"Exception in " << __func__ <<
": " << ex.
what();
239fillJsonState(
Json::Value& json, LedgerFill
const& fill)
241 auto& ledger =
fill.ledger;
243 auto expanded = isExpanded(fill);
244 auto binary = isBinary(fill);
246 for (
auto const& sle : ledger.sles)
262fillJsonQueue(
Json::Value& json, LedgerFill
const& fill)
265 auto bBinary = isBinary(fill);
266 auto bExpanded = isExpanded(fill);
268 for (
auto const& tx :
fill.txQueue)
271 txJson[jss::fee_level] =
to_string(tx.feeLevel);
273 txJson[jss::LastLedgerSequence] = *tx.lastValid;
275 txJson[jss::fee] =
to_string(tx.consequences.fee());
277 tx.consequences.potentialSpend() + tx.consequences.fee();
278 txJson[jss::max_spend_drops] =
to_string(spend);
279 txJson[jss::auth_change] = tx.consequences.isBlocker();
281 txJson[jss::account] =
to_string(tx.account);
282 txJson[
"retries_remaining"] = tx.retriesRemaining;
283 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
285 txJson[
"last_result"] =
transToken(*tx.lastResult);
287 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
288 if (
fill.context->apiVersion > 1)
300 auto bFull = isFull(fill);
302 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.header());
307 fill.ledger.header(),
309 (
fill.context ?
fill.context->apiVersion
310 : RPC::apiMaximumSupportedVersion));
313 fillJsonTx(json, fill);
316 fillJsonState(json, fill);
325 fillJson(
object, fill);
328 fillJsonQueue(json, fill);
335 fillJson(json, fill);
348 XRPL_ASSERT(from.
isObjectOrNull(),
"copyFrom : invalid input type");
350 for (
auto const& m : members)
bool isObjectOrNull() const
Members getMemberNames() const
Return a list of the member names.
A generic endpoint for log messages.
std::chrono::time_point< NetClock > time_point
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
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.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
std::string transToken(TER code)
bool getCloseAgree(LedgerHeader const &info)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
std::string to_string_iso(date::sys_time< Duration > tp)
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Value with a description of the ledger.