1#include <xrpld/rpc/handlers/account/AccountLines.h>
3#include <xrpld/rpc/Context.h>
4#include <xrpld/rpc/detail/RPCHelpers.h>
5#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
6#include <xrpld/rpc/detail/TrustLine.h>
7#include <xrpld/rpc/detail/Tuning.h>
9#include <xrpl/basics/base_uint.h>
10#include <xrpl/beast/utility/Zero.h>
11#include <xrpl/beast/utility/instrumentation.h>
12#include <xrpl/json/json_value.h>
13#include <xrpl/ledger/ReadView.h>
14#include <xrpl/ledger/helpers/DirectoryHelpers.h>
15#include <xrpl/protocol/AccountID.h>
16#include <xrpl/protocol/ErrorCodes.h>
17#include <xrpl/protocol/Indexes.h>
18#include <xrpl/protocol/LedgerFormats.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/STAmount.h>
21#include <xrpl/protocol/STLedgerEntry.h>
22#include <xrpl/protocol/UintTypes.h>
23#include <xrpl/protocol/jss.h>
24#include <xrpl/resource/Fees.h>
26#include <rpcspec/AccountTypes.hpp>
27#include <rpcspec/Errors.hpp>
28#include <rpcspec/handlers/account_lines/Types.hpp>
46appendLineJson(RPCTrustLine
const& line, json::Value& lines)
48 STAmount
const& saBalance(line.getBalance());
49 STAmount
const& saLimit(line.getLimit());
50 STAmount
const& saLimitPeer(line.getLimitPeer());
53 jPeer[jss::account] =
to_string(line.getAccountIDPeer());
59 jPeer[jss::balance] = saBalance.getText();
60 jPeer[jss::currency] =
to_string(saBalance.get<Issue>().currency);
61 jPeer[jss::limit] = saLimit.getText();
62 jPeer[jss::limit_peer] = saLimitPeer.getText();
63 jPeer[jss::quality_in] = line.getQualityIn().value;
64 jPeer[jss::quality_out] = line.getQualityOut().value;
66 jPeer[jss::authorized] =
true;
67 if (line.getAuthPeer())
68 jPeer[jss::peer_authorized] =
true;
69 if (line.getNoRipple())
70 jPeer[jss::no_ripple] =
true;
71 if (line.getNoRipplePeer())
72 jPeer[jss::no_ripple_peer] =
true;
74 jPeer[jss::freeze] =
true;
75 if (line.getFreezePeer())
76 jPeer[jss::freeze_peer] =
true;
77 if (line.getDeepFreeze())
78 jPeer[jss::deep_freeze] =
true;
79 if (line.getDeepFreezePeer())
80 jPeer[jss::deep_freeze_peer] =
true;
89std::expected<AccountLinesHandler::Output, ::rpc::Status>
95 if (
auto const status =
getLedger(output.
ledger, input.ledger, context);
96 status != ::rpc::Status::kOK)
98 auto const& ledger = *output.
ledger;
100 if (!input.account.has_value())
105 auto const accountID = *input.account;
111 auto const& peer = input.peer;
112 if (!peer.has_value() && peer.error() == ::rpc::spec::AccountError::Malformed)
120 auto const parsed = input.marker.has_value()
123 if (!parsed.has_value())
126 UNREACHABLE(
"xrpl::rpc::AccountLinesHandler::process : marker validated by the spec");
130 auto const [startAfter, startHint] = *parsed;
132 if (input.marker.has_value())
136 auto const sle = ledger.read({
ltANY, startAfter});
145 bool const ignoreDefault = input.ignoreDefault;
155 [&output, &accountID, &peer, ignoreDefault, &count, &limit, &marker, &nextHint](
160 UNREACHABLE(
"xrpl::rpc::AccountLinesHandler::process : null SLE");
165 if (++count == limit)
171 if (sle->getType() != ltRIPPLE_STATE)
177 if (sle->getFieldAmount(sfLowLimit).getIssuer() == accountID)
179 ignore = !sle->isFlag(lsfLowReserve);
183 ignore = !sle->isFlag(lsfHighReserve);
187 if (!ignore && count <= limit)
191 if (line.has_value() &&
192 (!peer.has_value() || *peer == line->getAccountIDPeer()))
194 output.
lines.emplace_back(*line);
207 if (count == limit + 1 && marker.
has_value())
209 output.
limit = limit;
230 for (
auto const& line : output.
lines)
231 appendLineJson(line, lines);
233 if (output.
marker.has_value())
235 value[jss::limit] = output.
limit;
Value & append(Value const &value)
Append value to array at the end.
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, SLE::ConstRef sle)
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::expected< Output, ::rpc::Status > process(Input const &input) const
Process the request.
AccountLinesHandler(JsonContext &context)
Construct a handler for a single request.
void writeResult(json::Value &value, Output const &output) const
Write the output of process() into the response.
std::reference_wrapper< JsonContext > context_
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Keylet account(AccountID const &id) noexcept
AccountID root.
Charge const kFeeMediumBurdenRpc
static constexpr LimitRange kAccountLines
Limits for the account_lines command.
The api_version numbers this server serves.
unsigned int clampLimit(unsigned int limit, tuning::LimitRange const &range, Role const &role)
Clamps a requested limit to the range a role may use.
std::uint64_t getStartHint(SLE::ConstRef sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
::rpc::Status getLedger(T &ledger, UInt256 const &ledgerHash, Context const &context)
Retrieves a ledger by its hash.
void injectLedgerFields(ReadView const &ledger, Context const &context, json::Value &result)
Writes the fields that identify a ledger into a result.
bool isRelatedToAccount(ReadView const &ledger, SLE::ConstRef sle, AccountID const &accountID)
Tests if a ledger entry (SLE) is owned by the specified account.
std::optional< std::pair< uint256, std::uint64_t > > parseAccountMarker(std::string_view marker)
Splits an account marker into the entry to start after and its start hint.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(BaseUInt< Bits, Tag > const &a)
bool forEachItemAfter(ReadView const &view, Keylet const &root, UInt256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(SLE::ConstRef)> const &f)
Iterate all items after an item in the given directory.
@ ltANY
A special type, matching any ledger entry type.
The data an account_lines request produces, written out by writeResult().
std::optional< ErrorCodeI > error
An error written with the ledger fields.
std::optional< uint256 > marker
Where the next page starts, if there is one.
std::vector< RPCTrustLine > lines
The trust lines on this page.
AccountID account
The account whose trust lines are listed.
std::shared_ptr< ReadView const > ledger
The ledger the request selected.
std::uint32_t limit
The limit used; written only with a marker.
std::uint64_t nextHint
The directory page hint written with the marker.