1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/detail/RPCHelpers.h>
3#include <xrpld/rpc/detail/Tuning.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/protocol/PublicKey.h>
9#include <xrpl/protocol/RPCErr.h>
10#include <xrpl/protocol/jss.h>
11#include <xrpl/resource/Fees.h>
20 jDst[jss::account] =
to_string(line[sfAccount]);
21 jDst[jss::destination_account] =
to_string(line[sfDestination]);
22 jDst[jss::amount] = line[sfAmount].getText();
23 jDst[jss::balance] = line[sfBalance].getText();
28 jDst[jss::public_key_hex] =
strHex(pk);
30 jDst[jss::settle_delay] = line[sfSettleDelay];
31 if (
auto const& v = line[~sfExpiration])
32 jDst[jss::expiration] = *v;
33 if (
auto const& v = line[~sfCancelAfter])
34 jDst[jss::cancel_after] = *v;
35 if (
auto const& v = line[~sfSourceTag])
36 jDst[jss::source_tag] = *v;
37 if (
auto const& v = line[~sfDestinationTag])
38 jDst[jss::destination_tag] = *v;
51 auto const& params(context.
params);
52 if (!params.isMember(jss::account))
55 if (!params[jss::account].isString())
63 auto id = parseBase58<AccountID>(params[jss::account].asString());
68 AccountID const accountID{std::move(
id.value())};
74 if (params.isMember(jss::destination_account))
75 strDst = params[jss::destination_account].asString();
80 if (!strDst.
empty() && !raDstAccount)
94 VisitData visitData = {{}, accountID, raDstAccount};
95 visitData.items.reserve(limit);
96 uint256 startAfter = beast::zero;
99 if (params.isMember(jss::marker))
101 if (!params[jss::marker].isString())
119 startHint = boost::lexical_cast<std::uint64_t>(value);
121 catch (boost::bad_lexical_cast&)
128 auto const sle = ledger->read({
ltANY, startAfter});
146 [&visitData, &accountID, &count, &limit, &marker, &nextHint](
151 UNREACHABLE(
"ripple::doAccountChannels : null SLE");
156 if (++count == limit)
158 marker = sleCur->key();
162 if (count <= limit && sleCur->getType() == ltPAYCHAN &&
163 (*sleCur)[sfAccount] == accountID &&
164 (!visitData.raDstAccount ||
165 *visitData.raDstAccount == (*sleCur)[sfDestination]))
167 visitData.items.emplace_back(sleCur);
179 if (count == limit + 1 && marker)
181 result[jss::limit] = limit;
182 result[jss::marker] =
186 result[jss::account] =
toBase58(accountID);
188 for (
auto const& item : visitData.items)
192 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