1#include <xrpld/app/ledger/LedgerMaster.h>
2#include <xrpld/app/ledger/LedgerToJson.h>
3#include <xrpld/app/ledger/OpenLedger.h>
4#include <xrpld/app/misc/Transaction.h>
5#include <xrpld/app/paths/TrustLine.h>
6#include <xrpld/app/rdb/RelationalDatabase.h>
7#include <xrpld/app/tx/detail/NFTokenUtils.h>
8#include <xrpld/rpc/Context.h>
9#include <xrpld/rpc/DeliveredAmount.h>
10#include <xrpld/rpc/detail/RPCHelpers.h>
12#include <xrpl/ledger/View.h>
13#include <xrpl/protocol/AccountID.h>
14#include <xrpl/protocol/RPCErr.h>
15#include <xrpl/protocol/nftPageMask.h>
16#include <xrpl/resource/Fees.h>
18#include <boost/algorithm/string/case_conv.hpp>
19#include <boost/algorithm/string/predicate.hpp>
29 auto const publicKey =
35 result = parseBase58<AccountID>(account);
81 if (sle->getType() == ltRIPPLE_STATE)
83 if (sle->getFieldAmount(sfLowLimit).getIssuer() == accountID)
84 return sle->getFieldU64(sfLowNode);
85 else if (sle->getFieldAmount(sfHighLimit).getIssuer() == accountID)
86 return sle->getFieldU64(sfHighNode);
89 if (!sle->isFieldPresent(sfOwnerNode))
92 return sle->getFieldU64(sfOwnerNode);
101 if (sle->getType() == ltRIPPLE_STATE)
103 return (sle->getFieldAmount(sfLowLimit).getIssuer() == accountID) ||
104 (sle->getFieldAmount(sfHighLimit).getIssuer() == accountID);
106 else if (sle->isFieldPresent(sfAccount))
114 return sle->getAccountID(sfAccount) == accountID ||
115 (sle->isFieldPresent(sfDestination) &&
116 sle->getAccountID(sfDestination) == accountID);
118 else if (sle->getType() == ltSIGNER_LIST)
121 return sle->key() == accountSignerList.
key;
123 else if (sle->getType() == ltNFTOKEN_OFFER)
127 return sle->getAccountID(sfOwner) == accountID;
137 for (
auto const& jv : jvArray)
141 auto const id = parseBase58<AccountID>(jv.asString());
153 if (sle.
getType() == ltACCOUNT_ROOT)
158 Blob const b(hash.begin(), hash.end());
160 boost::to_lower(md5);
164 jv[jss::urlgravatar] =
165 str(boost::format(
"http://www.gravatar.com/avatar/%s") % md5);
170 jv[jss::Invalid] =
true;
180 limit =
range.rdefault;
185 auto const& jvLimit = context.
params[jss::limit];
186 if (!(jvLimit.isUInt() || (jvLimit.isInt() && jvLimit.asInt() >= 0)))
189 limit = jvLimit.asUInt();
210 if (result.size() == 18 &&
221 using string_to_seed_t =
225 static seed_match_t
const seedTypes[]{
226 {jss::passphrase.c_str(),
229 [](
std::string const& s) {
return parseBase58<Seed>(s); }},
238 seed_match_t
const* seedType =
nullptr;
240 for (
auto const& t : seedTypes)
252 "Exactly one of the following must be specified: " +
259 auto const& param = params[seedType->first];
260 if (!param.isString())
266 auto const fieldContents = param.asString();
283 bool const has_key_type = params.
isMember(jss::key_type);
286 static char const*
const secretTypes[]{
287 jss::passphrase.c_str(),
290 jss::seed_hex.c_str()};
293 char const* secretType =
nullptr;
295 for (
auto t : secretTypes)
304 if (count == 0 || secretType ==
nullptr)
313 "Exactly one of the following must be specified: " +
325 if (!params[jss::key_type].isString())
344 if (strcmp(secretType, jss::secret.c_str()) == 0)
347 "The secret field is not allowed if " +
358 if (strcmp(secretType, jss::seed_hex.c_str()) != 0)
369 rpcBAD_SEED,
"Specified seed is for an Ed25519 wallet.");
386 if (!params[jss::secret].isString())
408 LogicError(
"keypairForSignature: invalid key type");
419 static constexpr auto types = std::to_array<
421#pragma push_macro("LEDGER_ENTRY")
424#define LEDGER_ENTRY(tag, value, name, rpcName, ...) \
425 {jss::name, jss::rpcName, tag},
427#include <xrpl/protocol/detail/ledger_entries.macro>
430#pragma pop_macro("LEDGER_ENTRY")
433 auto const& p = params[jss::type];
440 "ripple::RPC::chooseLedgerEntryType : first valid result type");
447 auto const filter = p.asString();
450 return boost::iequals(std::get<0>(t), filter) ||
451 std::get<1>(t) == filter;
453 if (iter == types.end())
459 "ripple::RPC::chooseLedgerEntryType : second valid result "
473 case LedgerEntryType::ltAMENDMENTS:
474 case LedgerEntryType::ltDIR_NODE:
475 case LedgerEntryType::ltFEE_SETTINGS:
476 case LedgerEntryType::ltLEDGER_HASHES:
477 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.
LedgerEntryType getType() const
Json::Value getJson(JsonOptions options=JsonOptions::none) const override
bool isFieldPresent(SField const &field) const
uint128 getFieldH128(SField const &field) const
Seeds are used to generate deterministic secret keys.
An immutable linear range of bytes.
static constexpr std::size_t size()
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
@ objectValue
object value (collection of name/value pairs).
error_code_i accountFromStringWithCode(AccountID &result, std::string const &strIdent, bool bStrict)
Decode account ID from string.
bool contains_error(Json::Value const &json)
Returns true if the json contains an rpc error specification.
std::optional< Seed > getSeedFromRPC(Json::Value const ¶ms, Json::Value &error)
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
Json::Value invalid_field_error(std::string const &name)
bool isAccountObjectsValidType(LedgerEntryType const &type)
Check if the type is a valid filtering type for account_objects method.
static constexpr std::integral_constant< unsigned, Version > apiVersion
bool isRelatedToAccount(ReadView const &ledger, std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Tests if a SLE is owned by accountID.
void injectSLE(Json::Value &jv, SLE const &sle)
Inject JSON describing ledger entry.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
std::string invalid_field_message(std::string const &name)
std::optional< Json::Value > readLimitField(unsigned int &limit, Tuning::LimitRange const &range, JsonContext const &context)
Retrieve the limit value from a JsonContext, or set a default - then restrict the limit by max and mi...
Json::Value accountFromString(AccountID &result, std::string const &strIdent, bool bStrict)
Json::Value expected_field_error(std::string const &name, std::string const &type)
std::optional< AccountID > accountFromStringStrict(std::string const &account)
Get an AccountID from an account ID or public key.
hash_set< AccountID > parseAccountIds(Json::Value const &jvArray)
std::uint64_t getStartHint(std::shared_ptr< SLE const > const &sle, AccountID const &accountID)
Gets the start hint for traversing account objects.
Json::Value missing_field_error(std::string const &name)
std::optional< Seed > parseRippleLibSeed(Json::Value const &value)
std::optional< std::pair< PublicKey, SecretKey > > keypairForSignature(Json::Value const ¶ms, Json::Value &error, unsigned int apiVersion)
Keylet signers(AccountID const &account) noexcept
A SignerList.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< KeyType > keyTypeFromString(std::string const &s)
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
AccountID calcAccountID(PublicKey const &pk)
Json::Value rpcError(int iError)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
std::string decodeBase58Token(std::string const &s, TokenType type)
std::string strHex(FwdIt begin, FwdIt end)
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)
ClosedInterval< T > range(T low, T high)
Create a closed range interval.
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
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.