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/basics/base_uint.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/core/ServiceRegistry.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/ledger/ReadView.h>
12#include <xrpl/ledger/helpers/DirectoryHelpers.h>
13#include <xrpl/protocol/AccountID.h>
14#include <xrpl/protocol/ErrorCodes.h>
15#include <xrpl/protocol/Indexes.h>
16#include <xrpl/protocol/LedgerFormats.h>
17#include <xrpl/protocol/RPCErr.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/STAmount.h>
20#include <xrpl/protocol/jss.h>
21#include <xrpl/resource/Fees.h>
23#include <boost/lexical_cast.hpp>
24#include <boost/lexical_cast/bad_lexical_cast.hpp>
40 offer->getFieldAmount(sfTakerPays).setJson(obj[jss::taker_pays]);
41 offer->getFieldAmount(sfTakerGets).setJson(obj[jss::taker_gets]);
42 obj[jss::seq] = offer->getFieldU32(sfSequence);
43 obj[jss::flags] = offer->getFieldU32(sfFlags);
44 obj[jss::quality] = dirRate.
getText();
45 if (offer->isFieldPresent(sfExpiration))
46 obj[jss::expiration] = offer->getFieldU32(sfExpiration);
59 auto const& params(context.
params);
60 if (!params.isMember(jss::account))
63 if (!params[jss::account].isString())
77 auto const accountID{
id.value()};
80 result[jss::account] =
toBase58(accountID);
85 unsigned int limit = 0;
91 uint256 startAfter = beast::kZero;
94 if (params.isMember(jss::marker))
96 if (!params[jss::marker].isString())
114 startHint = boost::lexical_cast<std::uint64_t>(value);
116 catch (boost::bad_lexical_cast&)
123 auto const sle = ledger->read({
ltANY, startAfter});
141 [&offers, &count, &marker, &limit, &nextHint, &accountID](
SLE::const_ref sle) {
145 UNREACHABLE(
"xrpl::doAccountOffers : null SLE");
150 if (++count == limit)
156 if (count <= limit && sle->getType() == ltOFFER)
158 offers.emplace_back(sle);
170 if (count == limit + 1 && marker)
172 result[jss::limit] = limit;
176 for (
auto const& offer : offers)
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
std::string getText() const override
std::shared_ptr< STLedgerEntry const > const & const_ref
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
static constexpr LimitRange kAccountOffers
Limits for the account_offers 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::uint64_t getQuality(uint256 const &uBase)
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)
STAmount amountFromQuality(std::uint64_t rate)
json::Value doAccountOffers(RPC::JsonContext &context)
@ 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.
void appendOfferJson(SLE::const_ref offer, json::Value &offers)
Resource::Charge & loadType