20 #include <ripple/app/ledger/LedgerToJson.h>
21 #include <ripple/app/misc/TxQ.h>
22 #include <ripple/basics/base_uint.h>
23 #include <ripple/rpc/Context.h>
24 #include <ripple/rpc/DeliveredAmount.h>
26 #include <date/date.h>
32 bool isFull(LedgerFill
const& fill)
37 bool isExpanded(LedgerFill
const& fill)
42 bool isBinary(LedgerFill
const& fill)
47 template <
class Object>
48 void fillJson(Object& json,
bool closed, LedgerInfo
const& info,
bool bFull)
50 json[jss::parent_hash] =
to_string (info.parentHash);
51 json[jss::ledger_index] =
to_string (info.seq);
56 json[jss::closed] =
true;
60 json[jss::closed] =
false;
64 json[jss::ledger_hash] =
to_string (info.hash);
65 json[jss::transaction_hash] =
to_string (info.txHash);
66 json[jss::account_hash] =
to_string (info.accountHash);
67 json[jss::total_coins] =
to_string (info.drops);
71 json[jss::totalCoins] =
to_string (info.drops);
72 json[jss::accepted] = closed;
73 json[jss::close_flags] = info.closeFlags;
76 json[jss::parent_close_time] = info.parentCloseTime.time_since_epoch().count();
77 json[jss::close_time] = info.closeTime.time_since_epoch().count();
78 json[jss::close_time_resolution] = info.closeTimeResolution.count();
82 json[jss::close_time_human] =
to_string(info.closeTime);
84 json[jss::close_time_estimated] =
true;
88 template <
class Object>
89 void fillJsonBinary(Object& json,
bool closed, LedgerInfo
const& info)
92 json[jss::closed] =
false;
95 json[jss::closed] =
true;
99 json[jss::ledger_data] =
strHex (s.peekData ());
105 LedgerFill
const& fill,
131 auto txMeta = std::make_shared<TxMeta>(
134 txJson[jss::metaData],
fill.ledger, txn, *txMeta);
147 if (account != amount.getIssuer())
155 txJson[jss::owner_funds] = ownerFunds.getText();
162 template <
class Object>
163 void fillJsonTx (Object& json, LedgerFill
const& fill)
165 auto&& txns =
setArray (json, jss::transactions);
166 auto bBinary = isBinary(fill);
167 auto bExpanded = isExpanded(fill);
171 for (
auto& i:
fill.ledger.txs)
173 txns.append(fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
182 template <
class Object>
183 void fillJsonState(Object& json, LedgerFill
const& fill)
185 auto& ledger =
fill.ledger;
187 auto expanded = isExpanded(fill);
188 auto binary = isBinary(fill);
190 for(
auto const& sle : ledger.sles)
208 template <
class Object>
209 void fillJsonQueue(Object& json, LedgerFill
const& fill)
212 auto bBinary = isBinary(fill);
213 auto bExpanded = isExpanded(fill);
215 for (
auto const& tx :
fill.txQueue)
218 txJson[jss::fee_level] =
to_string(tx.feeLevel);
220 txJson[jss::LastLedgerSequence] = *tx.lastValid;
224 tx.consequences->fee);
225 auto spend = tx.consequences->potentialSpend +
226 tx.consequences->fee;
227 txJson[jss::max_spend_drops] =
to_string(spend);
228 auto authChanged = tx.consequences->category ==
230 txJson[jss::auth_change] = authChanged;
233 txJson[jss::account] =
to_string(tx.account);
234 txJson[
"retries_remaining"] = tx.retriesRemaining;
235 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
237 txJson[
"last_result"] =
transToken(*tx.lastResult);
239 txJson[jss::tx] = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
243 template <
class Object>
244 void fillJson (Object& json, LedgerFill
const& fill)
248 auto bFull = isFull(fill);
250 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
252 fillJson(json, !
fill.ledger.open(),
fill.ledger.info(), bFull);
255 fillJsonTx(json, fill);
258 fillJsonState(json, fill);
266 fillJson (
object, fill);
269 fillJsonQueue(json, fill);
275 fillJson (json, fill);