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/StringUtilities.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/jss.h>
22#include <xrpl/resource/Fees.h>
38 offer->getFieldAmount(sfTakerPays).setJson(obj[jss::taker_pays]);
39 offer->getFieldAmount(sfTakerGets).setJson(obj[jss::taker_gets]);
40 obj[jss::seq] = offer->getFieldU32(sfSequence);
41 obj[jss::flags] = offer->getFieldU32(sfFlags);
42 obj[jss::quality] = dirRate.
getText();
43 if (offer->isFieldPresent(sfExpiration))
44 obj[jss::expiration] = offer->getFieldU32(sfExpiration);
57 auto const& params(context.
params);
58 if (!params.isMember(jss::account))
61 if (!params[jss::account].isString())
75 auto const accountID{
id.value()};
78 result[jss::account] =
toBase58(accountID);
83 unsigned int limit = 0;
92 if (params.isMember(jss::marker))
94 if (!params[jss::marker].isString())
111 if (!hint.has_value())
117 auto const sle = ledger->read({
ltANY, startAfter});
135 [&offers, &count, &marker, &limit, &nextHint, &accountID](
SLE::const_ref sle) {
139 UNREACHABLE(
"xrpl::doAccountOffers : null SLE");
144 if (++count == limit)
150 if (count <= limit && sle->getType() == ltOFFER)
152 offers.emplace_back(sle);
164 if (count == limit + 1 && marker)
166 result[jss::limit] = limit;
170 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).
Keylet account(AccountID const &id) noexcept
AccountID root.
Charge const kFeeMediumBurdenRpc
static constexpr LimitRange kAccountOffers
Limits for the account_offers 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::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)
std::optional< std::uint64_t > toUInt64(std::string const &s)
@ 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