1#include <xrpld/app/misc/Transaction.h>
2#include <xrpld/app/paths/TrustLine.h>
3#include <xrpld/app/rdb/RelationalDatabase.h>
4#include <xrpld/app/tx/detail/NFTokenUtils.h>
5#include <xrpld/rpc/Context.h>
6#include <xrpld/rpc/DeliveredAmount.h>
7#include <xrpld/rpc/detail/RPCHelpers.h>
9#include <xrpl/ledger/View.h>
10#include <xrpl/protocol/AccountID.h>
11#include <xrpl/protocol/RPCErr.h>
12#include <xrpl/protocol/nftPageMask.h>
13#include <xrpl/resource/Fees.h>
15#include <boost/algorithm/string/case_conv.hpp>
16#include <boost/algorithm/string/predicate.hpp>
24 if (sle->getType() == ltRIPPLE_STATE)
26 if (sle->getFieldAmount(sfLowLimit).getIssuer() == accountID)
27 return sle->getFieldU64(sfLowNode);
28 else if (sle->getFieldAmount(sfHighLimit).getIssuer() == accountID)
29 return sle->getFieldU64(sfHighNode);
32 if (!sle->isFieldPresent(sfOwnerNode))
35 return sle->getFieldU64(sfOwnerNode);
44 if (sle->getType() == ltRIPPLE_STATE)
46 return (sle->getFieldAmount(sfLowLimit).getIssuer() == accountID) ||
47 (sle->getFieldAmount(sfHighLimit).getIssuer() == accountID);
49 else if (sle->isFieldPresent(sfAccount))
57 return sle->getAccountID(sfAccount) == accountID ||
58 (sle->isFieldPresent(sfDestination) &&
59 sle->getAccountID(sfDestination) == accountID);
61 else if (sle->getType() == ltSIGNER_LIST)
64 return sle->key() == accountSignerList.
key;
66 else if (sle->getType() == ltNFTOKEN_OFFER)
70 return sle->getAccountID(sfOwner) == accountID;
80 for (
auto const& jv : jvArray)
84 auto const id = parseBase58<AccountID>(jv.asString());
98 limit =
range.rDefault;
103 auto const& jvLimit = context.
params[jss::limit];
104 if (!(jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0)))
107 limit = jvLimit.asUInt();
128 if (result.size() == 18 &&
139 using string_to_seed_t =
143 static seed_match_t
const seedTypes[]{
144 {jss::passphrase.c_str(),
147 [](
std::string const& s) {
return parseBase58<Seed>(s); }},
156 seed_match_t
const* seedType =
nullptr;
158 for (
auto const& t : seedTypes)
170 "Exactly one of the following must be specified: " +
177 auto const& param = params[seedType->first];
178 if (!param.isString())
184 auto const fieldContents = param.asString();
201 bool const has_key_type = params.
isMember(jss::key_type);
204 static char const*
const secretTypes[]{
205 jss::passphrase.c_str(),
208 jss::seed_hex.c_str()};
211 char const* secretType =
nullptr;
213 for (
auto t : secretTypes)
222 if (count == 0 || secretType ==
nullptr)
231 "Exactly one of the following must be specified: " +
243 if (!params[jss::key_type].isString())
262 if (strcmp(secretType, jss::secret.c_str()) == 0)
265 "The secret field is not allowed if " +
276 if (strcmp(secretType, jss::seed_hex.c_str()) != 0)
287 rpcBAD_SEED,
"Specified seed is for an Ed25519 wallet.");
304 if (!params[jss::secret].isString())
326 LogicError(
"keypairForSignature: invalid key type");
337 static constexpr auto types = std::to_array<
339#pragma push_macro("LEDGER_ENTRY")
342#define LEDGER_ENTRY(tag, value, name, rpcName, ...) \
343 {jss::name, jss::rpcName, tag},
345#include <xrpl/protocol/detail/ledger_entries.macro>
348#pragma pop_macro("LEDGER_ENTRY")
351 auto const& p = params[jss::type];
358 "xrpl::RPC::chooseLedgerEntryType : first valid result type");
365 auto const filter = p.asString();
368 return boost::iequals(std::get<0>(t), filter) ||
369 std::get<1>(t) == filter;
371 if (iter == types.end())
377 "xrpl::RPC::chooseLedgerEntryType : second valid result "
391 case LedgerEntryType::ltAMENDMENTS:
392 case LedgerEntryType::ltDIR_NODE:
393 case LedgerEntryType::ltFEE_SETTINGS:
394 case LedgerEntryType::ltLEDGER_HASHES:
395 case LedgerEntryType::ltNEGATIVE_UNL:
std::string asString() const
Returns the unquoted string value.
bool isNull() const
isNull() tests to see if this field is null.
bool isMember(char const *key) const
Return true if the object has a member named key.
Seeds are used to generate deterministic secret keys.
An immutable linear range of bytes.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
static constexpr std::size_t size()
Json::Value invalid_field_error(std::string const &name)
bool isRelatedToAccount(ReadView const &ledger, std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Tests if a ledger entry (SLE) is owned by the specified account.
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
Chooses the ledger entry type based on RPC parameters.
bool isAccountObjectsValidType(LedgerEntryType const &type)
Checks if the type is a valid filtering type for the account_objects method.
std::uint64_t getStartHint(std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
Json::Value expected_field_error(std::string const &name, std::string const &type)
Json::Value missing_field_error(std::string const &name)
std::optional< Seed > parseRippleLibSeed(Json::Value const &value)
Parses a RippleLib seed from RPC parameters.
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
Parses an array of account IDs from a JSON value.
static constexpr std::integral_constant< unsigned, Version > apiVersion
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
std::string invalid_field_message(std::string const &name)
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(Json::Value const ¶ms, Json::Value &error, unsigned int apiVersion)
Generates a keypair for signature from RPC parameters.
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
std::optional< Seed > getSeedFromRPC(Json::Value const ¶ms, Json::Value &error)
Extracts a Seed from RPC parameters.
std::optional< Json::Value > readLimitField(unsigned int &limit, Tuning::LimitRange const &range, JsonContext const &context)
Retrieves the limit value from a JsonContext or sets a default.
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
std::optional< KeyType > keyTypeFromString(std::string const &s)
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
Json::Value rpcError(error_code_i iError)
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
std::string decodeBase58Token(std::string const &s, TokenType type)
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
A pair of SHAMap key and LedgerEntryType.
Status represents the results of an operation that might fail.
Represents RPC limit parameter values that have a min, default and max.