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/base_uint.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/RPCErr.h>
19#include <xrpl/protocol/SField.h>
20#include <xrpl/protocol/STAmount.h>
21#include <xrpl/protocol/UintTypes.h>
22#include <xrpl/protocol/jss.h>
23#include <xrpl/resource/Fees.h>
25#include <boost/lexical_cast.hpp>
26#include <boost/lexical_cast/bad_lexical_cast.hpp>
51 jPeer[jss::balance] = saBalance.
getText();
53 jPeer[jss::limit] = saLimit.
getText();
54 jPeer[jss::limit_peer] = saLimitPeer.
getText();
58 jPeer[jss::authorized] =
true;
60 jPeer[jss::peer_authorized] =
true;
62 jPeer[jss::no_ripple] =
true;
64 jPeer[jss::no_ripple_peer] =
true;
66 jPeer[jss::freeze] =
true;
68 jPeer[jss::freeze_peer] =
true;
70 jPeer[jss::deep_freeze] =
true;
72 jPeer[jss::deep_freeze_peer] =
true;
87 auto const& params(context.
params);
88 if (!params.isMember(jss::account))
91 if (!params[jss::account].isString())
105 auto const accountID{
id.value()};
111 if (params.isMember(jss::peer))
112 strPeer = params[jss::peer].asString();
117 if (!strPeer.
empty() && !raPeerAccount)
123 unsigned int limit = 0;
129 bool const ignoreDefault =
130 params.isMember(jss::ignore_default) && params[jss::ignore_default].asBool();
141 VisitData visitData = {
143 .accountID = accountID,
144 .raPeerAccount = raPeerAccount,
145 .ignoreDefault = ignoreDefault,
147 uint256 startAfter = beast::kZero;
150 if (params.isMember(jss::marker))
152 if (!params[jss::marker].isString())
170 startHint = boost::lexical_cast<std::uint64_t>(value);
172 catch (boost::bad_lexical_cast&)
179 auto const sle = ledger->read({
ltANY, startAfter});
198 [&visitData, &count, &marker, &limit, &nextHint](
SLE::const_ref sleCur) {
202 UNREACHABLE(
"xrpl::doAccountLines : null SLE");
207 if (++count == limit)
209 marker = sleCur->key();
213 if (sleCur->getType() != ltRIPPLE_STATE)
217 if (visitData.ignoreDefault)
219 if (sleCur->getFieldAmount(sfLowLimit).getIssuer() == visitData.accountID)
221 ignore = !sleCur->isFlag(lsfLowReserve);
225 ignore = !sleCur->isFlag(lsfHighReserve);
229 if (!ignore && count <= limit)
234 (!visitData.raPeerAccount ||
235 *visitData.raPeerAccount == line->getAccountIDPeer()))
237 visitData.items.emplace_back(*line);
251 if (count == limit + 1 && marker)
253 result[jss::limit] = limit;
257 result[jss::account] =
toBase58(accountID);
259 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).
static constexpr LimitRange kAccountLines
Limits for the account_lines 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.
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)
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.
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.
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
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.
json::Value doAccountLines(RPC::JsonContext &context)
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