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/TrustLine.h>
5#include <xrpld/rpc/detail/Tuning.h>
7#include <xrpl/basics/StringUtilities.h>
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/beast/utility/Zero.h>
10#include <xrpl/beast/utility/instrumentation.h>
11#include <xrpl/core/ServiceRegistry.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/RPCErr.h>
20#include <xrpl/protocol/SField.h>
21#include <xrpl/protocol/STAmount.h>
22#include <xrpl/protocol/UintTypes.h>
23#include <xrpl/protocol/jss.h>
24#include <xrpl/resource/Fees.h>
49 jPeer[jss::balance] = saBalance.
getText();
51 jPeer[jss::limit] = saLimit.
getText();
52 jPeer[jss::limit_peer] = saLimitPeer.
getText();
56 jPeer[jss::authorized] =
true;
58 jPeer[jss::peer_authorized] =
true;
60 jPeer[jss::no_ripple] =
true;
62 jPeer[jss::no_ripple_peer] =
true;
64 jPeer[jss::freeze] =
true;
66 jPeer[jss::freeze_peer] =
true;
68 jPeer[jss::deep_freeze] =
true;
70 jPeer[jss::deep_freeze_peer] =
true;
85 auto const& params(context.
params);
86 if (!params.isMember(jss::account))
89 if (!params[jss::account].isString())
103 auto const accountID{
id.value()};
109 if (params.isMember(jss::peer))
111 if (!params[jss::peer].isString())
114 strPeer = params[jss::peer].asString();
120 if (!strPeer.
empty() && !raPeerAccount)
126 unsigned int limit = 0;
132 bool const ignoreDefault =
133 params.isMember(jss::ignore_default) && params[jss::ignore_default].asBool();
144 VisitData visitData = {
146 .accountID = accountID,
147 .raPeerAccount = raPeerAccount,
148 .ignoreDefault = ignoreDefault,
153 if (params.isMember(jss::marker))
155 if (!params[jss::marker].isString())
172 if (!hint.has_value())
178 auto const sle = ledger->read({
ltANY, startAfter});
197 [&visitData, &count, &marker, &limit, &nextHint](
SLE::const_ref sleCur) {
201 UNREACHABLE(
"xrpl::doAccountLines : null SLE");
206 if (++count == limit)
208 marker = sleCur->key();
212 if (sleCur->getType() != ltRIPPLE_STATE)
216 if (visitData.ignoreDefault)
218 if (sleCur->getFieldAmount(sfLowLimit).getIssuer() == visitData.accountID)
220 ignore = !sleCur->isFlag(lsfLowReserve);
224 ignore = !sleCur->isFlag(lsfHighReserve);
228 if (!ignore && count <= limit)
233 (!visitData.raPeerAccount ||
234 *visitData.raPeerAccount == line->getAccountIDPeer()))
236 visitData.items.emplace_back(*line);
250 if (count == limit + 1 && marker)
252 result[jss::limit] = limit;
256 result[jss::account] =
toBase58(accountID);
258 for (
auto const& item : visitData.items)
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.
A currency issued by an account.
Rate const & getQualityIn() const
static std::optional< RPCTrustLine > makeItem(AccountID const &accountID, SLE::const_ref sle)
Rate const & getQualityOut() const
constexpr TIss const & get() const
std::string getText() const override
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const & getAccountIDPeer() const
bool getNoRipplePeer() const
STAmount const & getLimit() const
bool getDeepFreeze() const
Have we set the deep freeze flag on our peer.
bool getFreezePeer() const
Has the peer set the freeze flag on us.
bool getDeepFreezePeer() const
Has the peer set the deep freeze flag on us.
STAmount const & getLimitPeer() const
bool getFreeze() const
Have we set the freeze flag on our peer.
STAmount const & getBalance() const
@ 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.
json::Value expectedFieldError(std::string const &name, std::string const &type)
std::uint64_t getStartHint(SLE::const_ref sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
bool isRelatedToAccount(ReadView const &ledger, SLE::const_ref sle, AccountID const &accountID)
Tests if a ledger entry (SLE) is owned by the specified account.
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value invalidFieldError(std::string const &name)
json::Value missingFieldError(std::string const &name)
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
json::Value doAccountLines(rpc::JsonContext &context)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
std::optional< std::uint64_t > toUInt64(std::string const &s)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
void addLine(json::Value &jsonLines, RPCTrustLine const &line)
@ 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