20 #include <ripple/app/ledger/LedgerToJson.h> 
   21 #include <ripple/app/main/Application.h> 
   22 #include <ripple/app/misc/TxQ.h> 
   23 #include <ripple/basics/base_uint.h> 
   24 #include <ripple/core/Pg.h> 
   25 #include <ripple/rpc/Context.h> 
   26 #include <ripple/rpc/DeliveredAmount.h> 
   33 isFull(LedgerFill 
const& fill)
 
   39 isExpanded(LedgerFill 
const& fill)
 
   45 isBinary(LedgerFill 
const& fill)
 
   50 template <
class Object>
 
   52 fillJson(Object& json, 
bool closed, LedgerInfo 
const& info, 
bool bFull)
 
   54     json[jss::parent_hash] = 
to_string(info.parentHash);
 
   55     json[jss::ledger_index] = 
to_string(info.seq);
 
   60         json[jss::closed] = 
true;
 
   64         json[jss::closed] = 
false;
 
   68     json[jss::ledger_hash] = 
to_string(info.hash);
 
   69     json[jss::transaction_hash] = 
to_string(info.txHash);
 
   70     json[jss::account_hash] = 
to_string(info.accountHash);
 
   71     json[jss::total_coins] = 
to_string(info.drops);
 
   75     json[jss::totalCoins] = 
to_string(info.drops);
 
   76     json[jss::accepted] = closed;
 
   77     json[jss::close_flags] = info.closeFlags;
 
   80     json[jss::parent_close_time] =
 
   81         info.parentCloseTime.time_since_epoch().count();
 
   82     json[jss::close_time] = info.closeTime.time_since_epoch().count();
 
   83     json[jss::close_time_resolution] = info.closeTimeResolution.count();
 
   87         json[jss::close_time_human] = 
to_string(info.closeTime);
 
   89             json[jss::close_time_estimated] = 
true;
 
   93 template <
class Object>
 
   95 fillJsonBinary(Object& json, 
bool closed, LedgerInfo 
const& info)
 
   98         json[jss::closed] = 
false;
 
  101         json[jss::closed] = 
true;
 
  105         json[jss::ledger_data] = 
strHex(s.peekData());
 
  111     LedgerFill 
const& fill,
 
  138                     txJson[jss::metaData],
 
  141                     {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
 
  153         if (account != amount.getIssuer())
 
  161             txJson[jss::owner_funds] = ownerFunds.getText();
 
  168 template <
class Object>
 
  170 fillJsonTx(Object& json, LedgerFill 
const& fill)
 
  172     auto&& txns = 
setArray(json, jss::transactions);
 
  173     auto bBinary = isBinary(fill);
 
  174     auto bExpanded = isExpanded(fill);
 
  178         auto appendAll = [&](
auto const& txs) {
 
  182                     fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
 
  186         if (
fill.context && 
fill.context->app.config().reporting())
 
  192             appendAll(
fill.ledger.txs);
 
  200             JLOG(
fill.context->j.error())
 
  201                 << 
"Exception in " << __func__ << 
": " << ex.
what();
 
  206 template <
class Object>
 
  208 fillJsonState(Object& json, LedgerFill 
const& fill)
 
  210     auto& ledger = 
fill.ledger;
 
  212     auto expanded = isExpanded(fill);
 
  213     auto binary = isBinary(fill);
 
  215     for (
auto const& sle : ledger.sles)
 
  233 template <
class Object>
 
  235 fillJsonQueue(Object& json, LedgerFill 
const& fill)
 
  238     auto bBinary = isBinary(fill);
 
  239     auto bExpanded = isExpanded(fill);
 
  241     for (
auto const& tx : 
fill.txQueue)
 
  244         txJson[jss::fee_level] = 
to_string(tx.feeLevel);
 
  246             txJson[jss::LastLedgerSequence] = *tx.lastValid;
 
  248         txJson[jss::fee] = 
to_string(tx.consequences.fee());
 
  250             tx.consequences.potentialSpend() + tx.consequences.fee();
 
  251         txJson[jss::max_spend_drops] = 
to_string(spend);
 
  252         txJson[jss::auth_change] = tx.consequences.isBlocker();
 
  254         txJson[jss::account] = 
to_string(tx.account);
 
  255         txJson[
"retries_remaining"] = tx.retriesRemaining;
 
  256         txJson[
"preflight_result"] = 
transToken(tx.preflightResult);
 
  258             txJson[
"last_result"] = 
transToken(*tx.lastResult);
 
  260         txJson[jss::tx] = fillJsonTx(fill, bBinary, bExpanded, tx.txn, 
nullptr);
 
  264 template <
class Object>
 
  266 fillJson(Object& json, LedgerFill 
const& fill)
 
  270     auto bFull = isFull(fill);
 
  272         fillJsonBinary(json, !
fill.ledger.open(), 
fill.ledger.info());
 
  274         fillJson(json, !
fill.ledger.open(), 
fill.ledger.info(), bFull);
 
  277         fillJsonTx(json, fill);
 
  280         fillJsonState(json, fill);
 
  289     fillJson(
object, fill);
 
  292         fillJsonQueue(json, fill);
 
  299     fillJson(json, fill);