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/ledger/ReadView.h>
7#include <xrpl/ledger/View.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/PublicKey.h>
10#include <xrpl/protocol/RPCErr.h>
11#include <xrpl/protocol/jss.h>
12#include <xrpl/resource/Fees.h>
21 jDst[jss::account] =
to_string(line[sfAccount]);
22 jDst[jss::destination_account] =
to_string(line[sfDestination]);
23 jDst[jss::amount] = line[sfAmount].getText();
24 jDst[jss::balance] = line[sfBalance].getText();
29 jDst[jss::public_key_hex] =
strHex(pk);
31 jDst[jss::settle_delay] = line[sfSettleDelay];
32 if (
auto const& v = line[~sfExpiration])
33 jDst[jss::expiration] = *v;
34 if (
auto const& v = line[~sfCancelAfter])
35 jDst[jss::cancel_after] = *v;
36 if (
auto const& v = line[~sfSourceTag])
37 jDst[jss::source_tag] = *v;
38 if (
auto const& v = line[~sfDestinationTag])
39 jDst[jss::destination_tag] = *v;
52 auto const& params(context.
params);
53 if (!params.isMember(jss::account))
56 if (!params[jss::account].isString())
64 auto id = parseBase58<AccountID>(params[jss::account].asString());
69 AccountID const accountID{std::move(
id.value())};
75 if (params.isMember(jss::destination_account))
76 strDst = params[jss::destination_account].asString();
81 if (!strDst.
empty() && !raDstAccount)
95 VisitData visitData = {{}, accountID, raDstAccount};
96 visitData.items.reserve(limit);
97 uint256 startAfter = beast::zero;
100 if (params.isMember(jss::marker))
102 if (!params[jss::marker].isString())
120 startHint = boost::lexical_cast<std::uint64_t>(value);
122 catch (boost::bad_lexical_cast&)
129 auto const sle = ledger->read({
ltANY, startAfter});
147 [&visitData, &accountID, &count, &limit, &marker, &nextHint](
152 UNREACHABLE(
"ripple::doAccountChannels : null SLE");
157 if (++count == limit)
159 marker = sleCur->key();
163 if (count <= limit && sleCur->getType() == ltPAYCHAN &&
164 (*sleCur)[sfAccount] == accountID &&
165 (!visitData.raDstAccount ||
166 *visitData.raDstAccount == (*sleCur)[sfDestination]))
168 visitData.items.emplace_back(sleCur);
180 if (count == limit + 1 && marker)
182 result[jss::limit] = limit;
183 result[jss::marker] =
187 result[jss::account] =
toBase58(accountID);
189 for (
auto const& item : visitData.items)
193 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.
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
static LimitRange constexpr accountChannels
Limits for the account_channels command.
Json::Value invalid_field_error(std::string const &name)
bool isRelatedToAccount(ReadView const &ledger, std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Tests if a SLE is owned by accountID.
Json::Value expected_field_error(std::string const &name, std::string const &type)
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
std::uint64_t getStartHint(std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
Json::Value missing_field_error(std::string const &name)
Charge const feeMediumBurdenRPC
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
void addChannel(Json::Value &jsonLines, SLE const &line)
Json::Value rpcError(int iError)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
std::string strHex(FwdIt begin, FwdIt end)
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items after an item in the given directory.
std::string to_string(base_uint< Bits, Tag > const &a)
@ ltANY
A special type, matching any ledger entry type.
Json::Value doAccountChannels(RPC::JsonContext &context)
Resource::Charge & loadType