1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/main/Application.h>
3#include <xrpld/app/misc/DeliverMax.h>
4#include <xrpld/app/misc/Transaction.h>
5#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
6#include <xrpld/rpc/Context.h>
7#include <xrpld/rpc/Role.h>
8#include <xrpld/rpc/Status.h>
9#include <xrpld/rpc/detail/RPCHelpers.h>
10#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
11#include <xrpld/rpc/detail/SyntheticFields.h>
12#include <xrpld/rpc/detail/Tuning.h>
14#include <xrpl/basics/Log.h>
15#include <xrpl/basics/base_uint.h>
16#include <xrpl/basics/chrono.h>
17#include <xrpl/basics/strHex.h>
18#include <xrpl/beast/utility/instrumentation.h>
19#include <xrpl/json/json_value.h>
20#include <xrpl/ledger/ReadView.h>
21#include <xrpl/protocol/AccountID.h>
22#include <xrpl/protocol/ErrorCodes.h>
23#include <xrpl/protocol/RPCErr.h>
24#include <xrpl/protocol/RippleLedgerHash.h>
25#include <xrpl/protocol/jss.h>
26#include <xrpl/rdb/RelationalDatabase.h>
27#include <xrpl/resource/Fees.h>
29#include <rpcspec/Ledger.hpp>
41static std::expected<DelegateFilter, json::Value>
47 if (!delegateNode.
isMember(jss::delegate_filter) ||
48 !delegateNode[jss::delegate_filter].
isString())
51 auto const& delegateFilterStr = delegateNode[jss::delegate_filter].
asString();
53 auto typeResult = [&] -> std::expected<DelegateType, json::Value> {
54 if (delegateFilterStr ==
"actor")
57 if (delegateFilterStr ==
"authorizer")
69 if (delegateNode.
isMember(jss::counter_party))
71 if (!delegateNode[jss::counter_party].isString())
114 if ((params.
isMember(jss::ledger_index_min) || params.
isMember(jss::ledger_index_max)) &&
118 status.inject(response);
122 if (params.
isMember(jss::ledger_index_min) || params.
isMember(jss::ledger_index_max))
125 params.
isMember(jss::ledger_index_min) && params[jss::ledger_index_min].
asInt() >= 0
126 ? params[jss::ledger_index_min].
asUInt()
129 params.
isMember(jss::ledger_index_max) && params[jss::ledger_index_max].
asInt() >= 0
130 ? params[jss::ledger_index_max].
asUInt()
135 if (params.
isMember(jss::ledger_hash))
137 auto& hashValue = params[jss::ledger_hash];
138 if (!hashValue.isString())
141 status.inject(response);
146 if (!hash.
parseHex(hashValue.asString()))
149 status.inject(response);
154 if (params.
isMember(jss::ledger_index))
157 if (params[jss::ledger_index].isNumeric())
159 ledger = params[jss::ledger_index].
asUInt();
165 if (ledgerStr ==
"current" || ledgerStr.
empty())
167 ledger = ::rpc::spec::LedgerShortcut::Current;
169 else if (ledgerStr ==
"closed")
171 ledger = ::rpc::spec::LedgerShortcut::Closed;
173 else if (ledgerStr ==
"validated")
175 ledger = ::rpc::spec::LedgerShortcut::Validated;
180 status.inject(response);
219 if ((ls.max > uValidatedMax && ls.max != -1) ||
220 (ls.min < uValidatedMin && ls.min != 0))
225 if (ls.min > uValidatedMin)
229 if (ls.max < uValidatedMax)
233 if (uLedgerMax < uLedgerMin)
243 auto status = getLedger(ledgerView, ls, context);
251 if (!validated || ledgerView->header().seq > uValidatedMax ||
252 ledgerView->header().seq < uValidatedMin)
256 uLedgerMin = uLedgerMax = ledgerView->header().seq;
265 return LedgerRange{.min = uLedgerMin, .max = uLedgerMax};
279 return {result, *stat};
282 result.
ledgerRange = std::get<LedgerRange>(lgrRange);
300 auto [tx, marker] = db.oldestAccountTxPageB(options);
306 auto [tx, marker] = db.newestAccountTxPageB(options);
315 auto [tx, marker] = db.oldestAccountTxPage(options);
321 auto [tx, marker] = db.newestAccountTxPage(options);
328 JLOG(context.
j.
debug()) << __func__ <<
" : finished";
348 response[jss::validated] =
true;
349 response[jss::limit] = result.
limit;
358 XRPL_ASSERT(!args.
binary,
"xrpl::populateJsonResponse : binary is not set");
360 for (
auto const& [txn, txnMeta] : *txnsData)
365 jvObj[jss::validated] =
true;
367 auto const jsonTx = (context.
apiVersion > 1 ? jss::tx_json : jss::tx);
370 jvObj[jsonTx] = txn->getJson(
376 jvObj[jss::hash] =
to_string(txn->getID());
377 jvObj[jss::ledger_index] = txn->getLedger();
378 jvObj[jss::ledger_hash] =
383 jvObj[jss::close_time_iso] =
toStringIso(*closeTime);
390 auto const& sttx = txn->getSTransaction();
401 "xrpl::populateJsonResponse : missing "
402 "transaction metadata");
410 XRPL_ASSERT(args.
binary,
"xrpl::populateJsonResponse : binary is set");
412 for (
auto const& binaryData : std::get<TxnsDataBinary>(result.
transactions))
416 jvObj[jss::tx_blob] =
strHex(std::get<0>(binaryData));
417 auto const jsonMeta = (context.
apiVersion > 1 ? jss::meta_blob : jss::meta);
418 jvObj[jsonMeta] =
strHex(std::get<1>(binaryData));
419 jvObj[jss::ledger_index] = std::get<2>(binaryData);
420 jvObj[jss::validated] =
true;
427 response[jss::marker][jss::ledger] = result.
marker->ledgerSeq;
428 response[jss::marker][jss::seq] = result.
marker->txnSeq;
431 response[jss::marker][jss::delegate] =
true;
435 JLOG(context.
j.
debug()) << __func__ <<
" : finished";
465 auto& params = context.
params;
473 if (context.
apiVersion > 1u && params.isMember(jss::binary) && !params[jss::binary].isBool())
477 if (context.
apiVersion > 1u && params.isMember(jss::forward) && !params[jss::forward].isBool())
485 args.
binary = params.isMember(jss::binary) && params[jss::binary].asBool();
486 args.
forward = params.isMember(jss::forward) && params[jss::forward].asBool();
488 if (!params.isMember(jss::account))
491 if (!params[jss::account].isString())
506 args.
ledger = std::get<std::optional<LedgerSpecifier>>(parseRes);
508 if (params.isMember(jss::marker))
510 auto& token = params[jss::marker];
511 if (!token.isMember(jss::ledger) || !token.isMember(jss::seq) ||
517 "invalid marker. Provide ledger index via ledger field, and "
518 "transaction sequence number via seq field"};
519 status.inject(response);
523 .ledgerSeq = token[jss::ledger].asUInt(), .txnSeq = token[jss::seq].asUInt()};
526 if (params.isMember(jss::delegate))
534 return filter.error();
544 bool const markerFromDelegate = params[jss::marker].isMember(jss::delegate) &&
545 params[jss::marker][jss::delegate].isBool() &&
546 params[jss::marker][jss::delegate].asBool();
547 if (markerFromDelegate != args.
delegate.has_value())
551 "Do not mix delegate and non-delegate pagination markers in account_tx; "
552 "repeat the same `delegate` object when using a delegate marker."};
553 status.inject(response);
559 JLOG(context.
j.
debug()) << __func__ <<
" populating response";
Value & append(Value const &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual Config & config()=0
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
bool getValidatedRange(std::uint32_t &minVal, std::uint32_t &maxVal)
Returns Ledgers we have all the nodes for and are indexed: a contiguous part of getFullValidatedRange...
UInt256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
std::optional< NetClock::time_point > getCloseTimeBySeq(LedgerIndex ledgerIndex)
bool isValidated(ReadView const &ledger)
Tests whether a ledger is on the validated chain, using the skip list when the ledger does not alread...
std::vector< TxnMetaLedgerType > MetaTxsList
std::vector< AccountTx > AccountTxs
std::tuple< Blob, Blob, std::uint32_t > TxnMetaLedgerType
virtual RelationalDatabase & getRelationalDatabase()=0
@ UInt
unsigned integer value
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Charge const kFeeMediumBurdenRpc
static constexpr LimitRange kAccountTx
Limits for the account_tx command.
void insertDeliverMax(json::Value &txJson, TxType txnType, unsigned int apiVersion)
Copy Amount field to DeliverMax field in transaction output JSON.
void insertAllSyntheticInJson(json::Value &metadata, ReadView const &ledger, std::shared_ptr< STTx const > const &transaction, TxMeta const &transactionMeta)
Adds all synthetic fields to transaction metadata JSON.
json::Value invalidFieldError(std::string const &name)
std::optional< json::Value > readLimitField(unsigned int &limit, tuning::LimitRange const &range, JsonContext const &context)
Retrieves the limit value from a JsonContext or sets a default.
json::Value missingFieldError(std::string const &name)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
RelationalDatabase::AccountTxs TxnsData
json::Value doAccountTx(rpc::JsonContext &context)
RelationalDatabase::AccountTxResult AccountTxResult
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string strHex(FwdIt begin, FwdIt end)
std::pair< AccountTxResult, rpc::Status > doAccountTxHelp(rpc::Context &context, AccountTxArgs const &args)
static std::expected< DelegateFilter, json::Value > parseDelegateFilter(json::Value const &delegateNode)
RelationalDatabase::MetaTxsList TxnsDataBinary
std::variant< LedgerRange, ::rpc::spec::LedgerShortcut, std::uint32_t, uint256 > LedgerSpecifier
std::string to_string(BaseUInt< Bits, Tag > const &a)
std::string toStringIso(date::sys_time< Duration > tp)
DelegateType
Enumeration of possible delegate types that can occur during filtering in account_tx.
@ Authorizer
This account signed and submitted transactions on behalf of another account (this account is the sign...
@ Actor
Another account signed and submitted transactions on behalf of this account (this account is the owne...
json::Value rpcError(ErrorCodeI iError)
json::Value populateJsonResponse(std::pair< AccountTxResult, rpc::Status > const &res, AccountTxArgs const &args, rpc::JsonContext const &context)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
RelationalDatabase::TxnMetaLedgerType TxnDataBinary
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
std::variant< LedgerRange, rpc::Status > getLedgerRange(rpc::Context &context, std::optional< LedgerSpecifier > const &ledgerSpecifier)
std::variant< std::optional< LedgerSpecifier >, json::Value > parseLedgerArgs(rpc::Context &context, json::Value const ¶ms)
std::optional< RelationalDatabase::AccountTxMarker > marker
std::optional< DelegateFilter > delegate
std::optional< LedgerSpecifier > ledger
std::variant< AccountTxs, MetaTxsList > transactions
std::optional< AccountTxMarker > marker
The context of information needed to call an RPC.
resource::Charge & loadType
LedgerMaster & ledgerMaster
Status represents the results of an operation that might fail.
void inject(json::Value &object) const
Apply the Status to a JsonObject.
ErrorCodeI toErrorCode() const
Returns the Status as an error_code_i.
static constexpr Code kOK