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>
36 isFull(LedgerFill
const& fill)
42 isExpanded(LedgerFill
const& fill)
48 isBinary(LedgerFill
const& fill)
53 template <
class Object>
55 fillJson(Object& json,
bool closed,
LedgerInfo const& info,
bool bFull)
57 json[jss::parent_hash] =
to_string(info.parentHash);
58 json[jss::ledger_index] =
to_string(info.seq);
62 json[jss::closed] =
true;
66 json[jss::closed] =
false;
70 json[jss::ledger_hash] =
to_string(info.hash);
71 json[jss::transaction_hash] =
to_string(info.txHash);
72 json[jss::account_hash] =
to_string(info.accountHash);
73 json[jss::total_coins] =
to_string(info.drops);
75 json[jss::close_flags] = info.closeFlags;
78 json[jss::parent_close_time] =
79 info.parentCloseTime.time_since_epoch().count();
80 json[jss::close_time] = info.closeTime.time_since_epoch().count();
81 json[jss::close_time_resolution] = info.closeTimeResolution.count();
85 json[jss::close_time_human] =
to_string(info.closeTime);
87 json[jss::close_time_estimated] =
true;
92 template <
class Object>
94 fillJsonBinary(Object& json,
bool closed,
LedgerInfo const& info)
97 json[jss::closed] =
false;
100 json[jss::closed] =
true;
104 json[jss::ledger_data] =
strHex(s.peekData());
110 LedgerFill
const& fill,
124 if (
fill.context->apiVersion > 1)
127 auto const json_meta =
128 (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
132 else if (
fill.context->apiVersion > 1)
135 txJson[jss::tx_json],
139 txJson[jss::tx_json], txnType,
fill.context->apiVersion);
151 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
154 if (!
fill.ledger.open())
155 txJson[jss::ledger_hash] =
to_string(
fill.ledger.info().hash);
157 const bool validated =
158 fill.context->ledgerMaster.isValidated(
fill.ledger);
159 txJson[jss::validated] = validated;
178 txJson[jss::metaData],
181 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
193 if (account != amount.getIssuer())
201 txJson[jss::owner_funds] = ownerFunds.getText();
208 template <
class Object>
210 fillJsonTx(Object& json, LedgerFill
const& fill)
212 auto&& txns =
setArray(json, jss::transactions);
213 auto bBinary = isBinary(fill);
214 auto bExpanded = isExpanded(fill);
218 auto appendAll = [&](
auto const& txs) {
222 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
226 if (
fill.context &&
fill.context->app.config().reporting())
232 appendAll(
fill.ledger.txs);
240 JLOG(
fill.context->j.error())
241 <<
"Exception in " << __func__ <<
": " << ex.
what();
246 template <
class Object>
248 fillJsonState(Object& json, LedgerFill
const& fill)
250 auto& ledger =
fill.ledger;
252 auto expanded = isExpanded(fill);
253 auto binary = isBinary(fill);
255 for (
auto const& sle : ledger.sles)
273 template <
class Object>
275 fillJsonQueue(Object& json, LedgerFill
const& fill)
278 auto bBinary = isBinary(fill);
279 auto bExpanded = isExpanded(fill);
281 for (
auto const& tx :
fill.txQueue)
284 txJson[jss::fee_level] =
to_string(tx.feeLevel);
286 txJson[jss::LastLedgerSequence] = *tx.lastValid;
288 txJson[jss::fee] =
to_string(tx.consequences.fee());
290 tx.consequences.potentialSpend() + tx.consequences.fee();
291 txJson[jss::max_spend_drops] =
to_string(spend);
292 txJson[jss::auth_change] = tx.consequences.isBlocker();
294 txJson[jss::account] =
to_string(tx.account);
295 txJson[
"retries_remaining"] = tx.retriesRemaining;
296 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
298 txJson[
"last_result"] =
transToken(*tx.lastResult);
300 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
301 if (
fill.context->apiVersion > 1)
308 template <
class Object>
310 fillJson(Object& json, LedgerFill
const& fill)
314 auto bFull = isFull(fill);
316 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
318 fillJson(json, !
fill.ledger.open(),
fill.ledger.info(), bFull);
321 fillJsonTx(json, fill);
324 fillJsonState(json, fill);
333 fillJson(
object, fill);
336 fillJsonQueue(json, fill);
343 fillJson(json, fill);