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)
36fillJson(
Json::Value& json,
bool closed, LedgerHeader
const& info,
bool bFull,
unsigned apiVersion)
38 json[jss::parent_hash] =
to_string(info.parentHash);
39 json[jss::ledger_index] =
44 json[jss::closed] =
true;
48 json[jss::closed] =
false;
52 json[jss::ledger_hash] =
to_string(info.hash);
53 json[jss::transaction_hash] =
to_string(info.txHash);
54 json[jss::account_hash] =
to_string(info.accountHash);
55 json[jss::total_coins] =
to_string(info.drops);
57 json[jss::close_flags] = info.closeFlags;
60 json[jss::parent_close_time] = info.parentCloseTime.time_since_epoch().count();
61 json[jss::close_time] = info.closeTime.time_since_epoch().count();
62 json[jss::close_time_resolution] = info.closeTimeResolution.count();
66 json[jss::close_time_human] =
to_string(info.closeTime);
68 json[jss::close_time_estimated] =
true;
74fillJsonBinary(
Json::Value& json,
bool closed, LedgerHeader
const& info)
77 json[jss::closed] =
false;
80 json[jss::closed] =
true;
84 json[jss::ledger_data] =
strHex(s.peekData());
90 LedgerFill
const& fill,
97 return to_string(txn->getTransactionID());
100 auto const txnType = txn->getTxnType();
104 if (
fill.context->apiVersion > 1)
105 txJson[jss::hash] =
to_string(txn->getTransactionID());
107 auto const json_meta = (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
111 else if (
fill.context->apiVersion > 1)
114 txJson[jss::hash] =
to_string(txn->getTransactionID());
122 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
127 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
131 txJson[jss::meta], txn, {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
134 if (!
fill.ledger.open())
135 txJson[jss::ledger_hash] =
to_string(
fill.ledger.header().hash);
137 bool const validated =
fill.context->ledgerMaster.isValidated(
fill.ledger);
138 txJson[jss::validated] = validated;
141 auto const seq =
fill.ledger.seq();
142 txJson[jss::ledger_index] = seq;
156 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
158 txJson[jss::metaData],
161 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
165 txJson[jss::metaData], txn, {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
171 auto const account = txn->getAccountID(sfAccount);
172 auto const amount = txn->getFieldAmount(sfTakerGets);
176 if (account !=
amount.getIssuer())
184 txJson[jss::owner_funds] = ownerFunds.getText();
192fillJsonTx(
Json::Value& json, LedgerFill
const& fill)
195 auto bBinary = isBinary(fill);
196 auto bExpanded = isExpanded(fill);
200 auto appendAll = [&](
auto const& txs) {
203 txns.append(fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
207 appendAll(
fill.ledger.txs);
214 JLOG(
fill.context->j.error()) <<
"Exception in " << __func__ <<
": " << ex.
what();
220fillJsonState(
Json::Value& json, LedgerFill
const& fill)
222 auto& ledger =
fill.ledger;
224 auto expanded = isExpanded(fill);
225 auto binary = isBinary(fill);
227 for (
auto const& sle : ledger.sles)
243fillJsonQueue(
Json::Value& json, LedgerFill
const& fill)
246 auto bBinary = isBinary(fill);
247 auto bExpanded = isExpanded(fill);
249 for (
auto const& tx :
fill.txQueue)
252 txJson[jss::fee_level] =
to_string(tx.feeLevel);
254 txJson[jss::LastLedgerSequence] = *tx.lastValid;
256 txJson[jss::fee] =
to_string(tx.consequences.fee());
257 auto const spend = tx.consequences.potentialSpend() + tx.consequences.fee();
258 txJson[jss::max_spend_drops] =
to_string(spend);
259 txJson[jss::auth_change] = tx.consequences.isBlocker();
261 txJson[jss::account] =
to_string(tx.account);
262 txJson[
"retries_remaining"] = tx.retriesRemaining;
263 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
265 txJson[
"last_result"] =
transToken(*tx.lastResult);
267 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
268 if (
fill.context->apiVersion > 1)
280 auto bFull = isFull(fill);
282 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.header());
287 fill.ledger.header(),
289 (
fill.context ?
fill.context->apiVersion : RPC::apiMaximumSupportedVersion));
292 fillJsonTx(json, fill);
295 fillJsonState(json, fill);
304 fillJson(
object, fill);
307 fillJsonQueue(json, fill);
314 fillJson(json, fill);
327 XRPL_ASSERT(from.
isObjectOrNull(),
"copyFrom : invalid input type");
329 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.
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.