20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/ledger/LedgerToJson.h>
22 #include <ripple/app/main/Application.h>
23 #include <ripple/app/misc/DeliverMax.h>
24 #include <ripple/app/misc/TxQ.h>
25 #include <ripple/basics/base_uint.h>
26 #include <ripple/core/Pg.h>
27 #include <ripple/protocol/jss.h>
28 #include <ripple/rpc/Context.h>
29 #include <ripple/rpc/DeliveredAmount.h>
30 #include <ripple/rpc/impl/RPCHelpers.h>
37 isFull(LedgerFill
const& fill)
43 isExpanded(LedgerFill
const& fill)
49 isBinary(LedgerFill
const& fill)
54 template <
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;
100 template <
class Object>
102 fillJsonBinary(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,
132 if (
fill.context->apiVersion > 1)
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],
147 txJson[jss::tx_json], txnType,
fill.context->apiVersion);
159 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
162 if (!
fill.ledger.open())
163 txJson[jss::ledger_hash] =
to_string(
fill.ledger.info().hash);
165 const bool validated =
166 fill.context->ledgerMaster.isValidated(
fill.ledger);
167 txJson[jss::validated] = validated;
170 auto const seq =
fill.ledger.seq();
171 txJson[jss::ledger_index] = (
fill.context->apiVersion > 1)
189 txJson[jss::metaData],
192 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
204 if (account != amount.getIssuer())
212 txJson[jss::owner_funds] = ownerFunds.getText();
219 template <
class Object>
221 fillJsonTx(Object& json, LedgerFill
const& fill)
223 auto&& txns =
setArray(json, jss::transactions);
224 auto bBinary = isBinary(fill);
225 auto bExpanded = isExpanded(fill);
229 auto appendAll = [&](
auto const& txs) {
233 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
237 if (
fill.context &&
fill.context->app.config().reporting())
243 appendAll(
fill.ledger.txs);
251 JLOG(
fill.context->j.error())
252 <<
"Exception in " << __func__ <<
": " << ex.
what();
257 template <
class Object>
259 fillJsonState(Object& json, LedgerFill
const& fill)
261 auto& ledger =
fill.ledger;
263 auto expanded = isExpanded(fill);
264 auto binary = isBinary(fill);
266 for (
auto const& sle : ledger.sles)
284 template <
class Object>
286 fillJsonQueue(Object& json, LedgerFill
const& fill)
289 auto bBinary = isBinary(fill);
290 auto bExpanded = isExpanded(fill);
292 for (
auto const& tx :
fill.txQueue)
295 txJson[jss::fee_level] =
to_string(tx.feeLevel);
297 txJson[jss::LastLedgerSequence] = *tx.lastValid;
299 txJson[jss::fee] =
to_string(tx.consequences.fee());
301 tx.consequences.potentialSpend() + tx.consequences.fee();
302 txJson[jss::max_spend_drops] =
to_string(spend);
303 txJson[jss::auth_change] = tx.consequences.isBlocker();
305 txJson[jss::account] =
to_string(tx.account);
306 txJson[
"retries_remaining"] = tx.retriesRemaining;
307 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
309 txJson[
"last_result"] =
transToken(*tx.lastResult);
311 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
312 if (
fill.context->apiVersion > 1)
319 template <
class Object>
321 fillJson(Object& json, LedgerFill
const& fill)
325 auto bFull = isFull(fill);
327 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
334 (
fill.context ?
fill.context->apiVersion
338 fillJsonTx(json, fill);
341 fillJsonState(json, fill);
350 fillJson(
object, fill);
353 fillJsonQueue(json, fill);
360 fillJson(json, fill);