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)
36fillJson(
Json::Value& json,
bool closed, LedgerHeader
const& info,
bool bFull,
unsigned apiVersion)
38 json[jss::parent_hash] =
to_string(info.parentHash);
43 json[jss::closed] =
true;
47 json[jss::closed] =
false;
51 json[jss::ledger_hash] =
to_string(info.hash);
52 json[jss::transaction_hash] =
to_string(info.txHash);
53 json[jss::account_hash] =
to_string(info.accountHash);
54 json[jss::total_coins] =
to_string(info.drops);
56 json[jss::close_flags] = info.closeFlags;
59 json[jss::parent_close_time] = info.parentCloseTime.time_since_epoch().count();
60 json[jss::close_time] = info.closeTime.time_since_epoch().count();
61 json[jss::close_time_resolution] = info.closeTimeResolution.count();
65 json[jss::close_time_human] =
to_string(info.closeTime);
67 json[jss::close_time_estimated] =
true;
73fillJsonBinary(
Json::Value& json,
bool closed, LedgerHeader
const& info)
76 json[jss::closed] =
false;
79 json[jss::closed] =
true;
83 json[jss::ledger_data] =
strHex(s.peekData());
89 LedgerFill
const& fill,
96 return to_string(txn->getTransactionID());
99 auto const txnType = txn->getTxnType();
103 if (
fill.context->apiVersion > 1)
104 txJson[jss::hash] =
to_string(txn->getTransactionID());
106 auto const json_meta = (
fill.context->apiVersion > 1 ? jss::meta_blob : jss::meta);
110 else if (
fill.context->apiVersion > 1)
113 txJson[jss::hash] =
to_string(txn->getTransactionID());
121 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
123 txJson[jss::meta],
fill.ledger, txn, {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
129 if (!
fill.ledger.open())
130 txJson[jss::ledger_hash] =
to_string(
fill.ledger.header().hash);
132 bool const validated =
fill.context->ledgerMaster.isValidated(
fill.ledger);
133 txJson[jss::validated] = validated;
136 auto const seq =
fill.ledger.seq();
137 txJson[jss::ledger_index] = seq;
151 if (txnType == ttPAYMENT || txnType == ttCHECK_CASH)
153 txJson[jss::metaData],
fill.ledger, txn, {txn->getTransactionID(), fill.ledger.seq(), *stMeta});
157 txJson[jss::metaData], txn, {txn->getTransactionID(),
fill.ledger.seq(), *stMeta});
163 auto const account = txn->getAccountID(sfAccount);
164 auto const amount = txn->getFieldAmount(sfTakerGets);
168 if (account !=
amount.getIssuer())
172 txJson[jss::owner_funds] = ownerFunds.getText();
180fillJsonTx(
Json::Value& json, LedgerFill
const& fill)
183 auto bBinary = isBinary(fill);
184 auto bExpanded = isExpanded(fill);
188 auto appendAll = [&](
auto const& txs) {
191 txns.append(fillJsonTx(fill, bBinary, bExpanded, i.first, i.second));
195 appendAll(
fill.ledger.txs);
202 JLOG(
fill.context->j.error()) <<
"Exception in " << __func__ <<
": " << ex.
what();
208fillJsonState(
Json::Value& 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)
231fillJsonQueue(
Json::Value& json, LedgerFill
const& fill)
234 auto bBinary = isBinary(fill);
235 auto bExpanded = isExpanded(fill);
237 for (
auto const& tx :
fill.txQueue)
240 txJson[jss::fee_level] =
to_string(tx.feeLevel);
242 txJson[jss::LastLedgerSequence] = *tx.lastValid;
244 txJson[jss::fee] =
to_string(tx.consequences.fee());
245 auto const spend = tx.consequences.potentialSpend() + tx.consequences.fee();
246 txJson[jss::max_spend_drops] =
to_string(spend);
247 txJson[jss::auth_change] = tx.consequences.isBlocker();
249 txJson[jss::account] =
to_string(tx.account);
250 txJson[
"retries_remaining"] = tx.retriesRemaining;
251 txJson[
"preflight_result"] =
transToken(tx.preflightResult);
253 txJson[
"last_result"] =
transToken(*tx.lastResult);
255 auto&& temp = fillJsonTx(fill, bBinary, bExpanded, tx.txn,
nullptr);
256 if (
fill.context->apiVersion > 1)
268 auto bFull = isFull(fill);
270 fillJsonBinary(json, !
fill.ledger.open(),
fill.ledger.header());
275 fill.ledger.header(),
277 (
fill.context ?
fill.context->apiVersion : RPC::apiMaximumSupportedVersion));
280 fillJsonTx(json, fill);
283 fillJsonState(json, fill);
292 fillJson(
object, fill);
295 fillJsonQueue(json, fill);
302 fillJson(json, fill);
315 XRPL_ASSERT(from.
isObjectOrNull(),
"copyFrom : invalid input type");
317 for (
auto const& m : members)
bool isObjectOrNull() const
Members getMemberNames() const
Return a list of the member names.
A generic endpoint for log messages.
std::chrono::time_point< NetClock > time_point
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
void insertDeliverMax(Json::Value &tx_json, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
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.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Json::Value getJson(LedgerFill const &fill)
Return a new Json::Value representing the ledger with given options.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string strHex(FwdIt begin, FwdIt end)
std::string transToken(TER code)
bool getCloseAgree(LedgerHeader const &info)
STAmount accountFunds(ReadView const &view, AccountID const &id, STAmount const &saDefault, FreezeHandling freezeHandling, beast::Journal j)
void copyFrom(Json::Value &to, Json::Value const &from)
Copy all the keys and values from one object into another.
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
std::string serializeHex(STObject const &o)
Serialize an object to a hex string.
std::string to_string_iso(date::sys_time< Duration > tp)
void addJson(Json::Value &json, LedgerFill const &fill)
Given a Ledger and options, fill a Json::Value with a description of the ledger.