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)
35template <
class Object>
44 json[jss::parent_hash] =
to_string(info.parentHash);
45 json[jss::ledger_index] = (apiVersion > 1)
51 json[jss::closed] =
true;
55 json[jss::closed] =
false;
59 json[jss::ledger_hash] =
to_string(info.hash);
60 json[jss::transaction_hash] =
to_string(info.txHash);
61 json[jss::account_hash] =
to_string(info.accountHash);
62 json[jss::total_coins] =
to_string(info.drops);
64 json[jss::close_flags] = info.closeFlags;
67 json[jss::parent_close_time] =
68 info.parentCloseTime.time_since_epoch().count();
69 json[jss::close_time] = info.closeTime.time_since_epoch().count();
70 json[jss::close_time_resolution] = info.closeTimeResolution.count();
74 json[jss::close_time_human] =
to_string(info.closeTime);
76 json[jss::close_time_estimated] =
true;
81template <
class Object>
83fillJsonBinary(Object& json,
bool closed,
LedgerInfo const& info)
86 json[jss::closed] =
false;
89 json[jss::closed] =
true;
93 json[jss::ledger_data] =
strHex(s.peekData());
99 LedgerFill
const& fill,
106 return to_string(txn->getTransactionID());
109 auto const txnType = txn->getTxnType();
113 if (
fill.context->apiVersion > 1)
114 txJson[jss::hash] =
to_string(txn->getTransactionID());
116 auto const json_meta =
117 (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
121 else if (
fill.context->apiVersion > 1)
124 txJson[jss::tx_json],
126 txJson[jss::hash] =
to_string(txn->getTransactionID());
128 txJson[jss::tx_json], txnType,
fill.context->apiVersion);
135 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
140 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
146 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
149 if (!
fill.ledger.open())
150 txJson[jss::ledger_hash] =
to_string(
fill.ledger.info().hash);
152 bool const validated =
153 fill.context->ledgerMaster.isValidated(
fill.ledger);
154 txJson[jss::validated] = validated;
157 auto const seq =
fill.ledger.seq();
158 txJson[jss::ledger_index] = seq;
172 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
174 txJson[jss::metaData],
177 {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
181 txJson[jss::metaData],
183 {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
188 txn->getTxnType() == ttOFFER_CREATE)
190 auto const account = txn->getAccountID(sfAccount);
191 auto const amount = txn->getFieldAmount(sfTakerGets);
195 if (account != amount.getIssuer())
203 txJson[jss::owner_funds] = ownerFunds.getText();
210template <
class Object>
212fillJsonTx(Object& json, LedgerFill
const& fill)
214 auto&& txns =
setArray(json, jss::transactions);
215 auto bBinary = isBinary(fill);
216 auto bExpanded = isExpanded(fill);
220 auto appendAll = [&](
auto const& txs) {
224 fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
228 appendAll(
fill.ledger.txs);
235 JLOG(
fill.context->j.error())
236 <<
"Exception in " << __func__ <<
": " << ex.
what();
241template <
class Object>
243fillJsonState(Object& json, LedgerFill
const& fill)
245 auto& ledger =
fill.ledger;
247 auto expanded = isExpanded(fill);
248 auto binary = isBinary(fill);
250 for (
auto const& sle : ledger.sles)
265template <
class Object>
267fillJsonQueue(Object& json, LedgerFill
const& fill)
270 auto bBinary = isBinary(fill);
271 auto bExpanded = isExpanded(fill);
273 for (
auto const& tx :
fill.txQueue)
276 txJson[jss::fee_level] =
to_string(tx.feeLevel);
278 txJson[jss::LastLedgerSequence] = *tx.lastValid;
280 txJson[jss::fee] =
to_string(tx.consequences.fee());
282 tx.consequences.potentialSpend() + tx.consequences.fee();
283 txJson[jss::max_spend_drops] =
to_string(spend);
284 txJson[jss::auth_change] = tx.consequences.isBlocker();
286 txJson[jss::account] =
to_string(tx.account);
287 txJson[
"retries_remaining"] = tx.retriesRemaining;
288 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
290 txJson[
"last_result"] =
transToken(*tx.lastResult);
292 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
293 if (
fill.context->apiVersion > 1)
300template <
class Object>
302fillJson(Object& json, LedgerFill
const& fill)
306 auto bFull = isFull(fill);
308 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.info());
315 (
fill.context ?
fill.context->apiVersion
316 : RPC::apiMaximumSupportedVersion));
319 fillJsonTx(json, fill);
322 fillJsonState(json, fill);
331 fillJson(
object, fill);
334 fillJsonQueue(json, fill);
341 fillJson(json, fill);
A generic endpoint for log messages.
std::chrono::time_point< NetClock > time_point
@ objectValue
object value (collection of name/value pairs).
Json::Value & setArray(Json::Value &, Json::StaticString const &key)
Add a new subarray at a named key in a Json object.
Json::Value & addObject(Json::Value &, Json::StaticString const &key)
Add a new subobject at a named key in a Json object.
Json::Value & appendObject(Json::Value &)
Append a new subobject to a Json object.
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
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.
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool getCloseAgree(LedgerHeader const &info)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Object or Json::Value with a description of the ledger.
std::string strHex(FwdIt begin, FwdIt end)
std::string transToken(TER code)
std::string to_string_iso(date::sys_time< Duration > tp)
std::string to_string(base_uint< Bits, Tag > const &a)
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)