1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/detail/RPCHelpers.h>
3#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
4#include <xrpld/rpc/detail/Tuning.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/basics/strHex.h>
8#include <xrpl/beast/utility/Zero.h>
9#include <xrpl/beast/utility/instrumentation.h>
10#include <xrpl/core/ServiceRegistry.h>
11#include <xrpl/json/json_value.h>
12#include <xrpl/ledger/ReadView.h>
13#include <xrpl/ledger/helpers/DirectoryHelpers.h>
14#include <xrpl/protocol/AccountID.h>
15#include <xrpl/protocol/ErrorCodes.h>
16#include <xrpl/protocol/Indexes.h>
17#include <xrpl/protocol/LedgerFormats.h>
18#include <xrpl/protocol/PublicKey.h>
19#include <xrpl/protocol/RPCErr.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/jss.h>
22#include <xrpl/protocol/tokens.h>
23#include <xrpl/resource/Fees.h>
25#include <boost/lexical_cast.hpp>
26#include <boost/lexical_cast/bad_lexical_cast.hpp>
43 jDst[jss::account] =
to_string(line[sfAccount]);
44 jDst[jss::destination_account] =
to_string(line[sfDestination]);
45 jDst[jss::amount] = line[sfAmount].
getText();
46 jDst[jss::balance] = line[sfBalance].
getText();
51 jDst[jss::public_key_hex] =
strHex(pk);
53 jDst[jss::settle_delay] = line[sfSettleDelay];
54 if (
auto const& v = line[~sfExpiration])
55 jDst[jss::expiration] = *v;
56 if (
auto const& v = line[~sfCancelAfter])
57 jDst[jss::cancel_after] = *v;
58 if (
auto const& v = line[~sfSourceTag])
59 jDst[jss::source_tag] = *v;
60 if (
auto const& v = line[~sfDestinationTag])
61 jDst[jss::destination_tag] = *v;
74 auto const& params(context.
params);
75 if (!params.isMember(jss::account))
78 if (!params[jss::account].isString())
97 if (params.isMember(jss::destination_account))
99 if (!params[jss::destination_account].isString())
101 strDst = params[jss::destination_account].asString();
107 if (!strDst.
empty() && !raDstAccount)
110 unsigned int limit = 0;
121 VisitData visitData = {.items = {}, .accountID = accountID, .raDstAccount = raDstAccount};
122 visitData.items.reserve(limit);
123 uint256 startAfter = beast::kZero;
126 if (params.isMember(jss::marker))
128 if (!params[jss::marker].isString())
146 startHint = boost::lexical_cast<std::uint64_t>(value);
148 catch (boost::bad_lexical_cast&)
155 auto const sle = ledger->read({
ltANY, startAfter});
173 [&visitData, &accountID, &count, &limit, &marker, &nextHint](
SLE::const_ref sleCur) {
177 UNREACHABLE(
"xrpl::doAccountChannels : null SLE");
182 if (++count == limit)
184 marker = sleCur->key();
188 if (count <= limit && sleCur->getType() == ltPAYCHAN &&
189 (*sleCur)[sfAccount] == accountID &&
190 (!visitData.raDstAccount ||
191 *visitData.raDstAccount == (*sleCur)[sfDestination]))
193 visitData.items.emplace_back(sleCur);
205 if (count == limit + 1 && marker)
207 result[jss::limit] = limit;
211 result[jss::account] =
toBase58(accountID);
213 for (
auto const& item : visitData.items)
217 result[jss::channels] = std::move(jsonChannels);
Value & append(Value const &value)
Append value to array at the end.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
uint256 const & key() const
Returns the 'key' (or 'index') of this item.
std::shared_ptr< STLedgerEntry const > const & const_ref
std::string getText() const override
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
static constexpr LimitRange kAccountChannels
Limits for the account_channels command.
bool isRelatedToAccount(ReadView const &ledger, SLE::const_ref sle, AccountID const &accountID)
Tests if a ledger entry (SLE) is owned by the specified account.
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, json::Value &result)
Looks up a ledger from a request and fills a json::Value with ledger data.
std::uint64_t getStartHint(SLE::const_ref sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
json::Value invalidFieldError(std::string const &name)
json::Value missingFieldError(std::string const &name)
json::Value expectedFieldError(std::string const &name, std::string const &type)
Charge const kFeeMediumBurdenRpc
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
json::Value doAccountChannels(RPC::JsonContext &context)
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string strHex(FwdIt begin, FwdIt end)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(BaseUInt< Bits, Tag > const &a)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
void addChannel(json::Value &jsonLines, SLE const &line)
json::Value rpcError(ErrorCodeI iError)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
@ ltANY
A special type, matching any ledger entry type.
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(SLE::const_ref)> const &f)
Iterate all items after an item in the given directory.
Resource::Charge & loadType