rippled
Loading...
Searching...
No Matches
VaultInfo.cpp
1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
3
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/jss.h>
9#include <xrpl/protocol/serialize.h>
10
11namespace ripple {
12
14parseVault(Json::Value const& params, Json::Value& jvResult)
15{
16 auto const hasVaultId = params.isMember(jss::vault_id);
17 auto const hasOwner = params.isMember(jss::owner);
18 auto const hasSeq = params.isMember(jss::seq);
19
20 uint256 uNodeIndex = beast::zero;
21 if (hasVaultId && !hasOwner && !hasSeq)
22 {
23 if (!uNodeIndex.parseHex(params[jss::vault_id].asString()))
24 {
26 return std::nullopt;
27 }
28 // else uNodeIndex holds the value we need
29 }
30 else if (!hasVaultId && hasOwner && hasSeq)
31 {
32 auto const id = parseBase58<AccountID>(params[jss::owner].asString());
33 if (!id)
34 {
36 return std::nullopt;
37 }
38 else if (
39 !(params[jss::seq].isInt() || params[jss::seq].isUInt()) ||
40 params[jss::seq].asDouble() <= 0.0 ||
41 params[jss::seq].asDouble() > double(Json::Value::maxUInt))
42 {
44 return std::nullopt;
45 }
46
47 uNodeIndex = keylet::vault(*id, params[jss::seq].asUInt()).key;
48 }
49 else
50 {
51 // Invalid combination of fields vault_id/owner/seq
53 return std::nullopt;
54 }
55
56 return uNodeIndex;
57}
58
61{
63 auto jvResult = RPC::lookupLedger(lpLedger, context);
64
65 if (!lpLedger)
66 return jvResult;
67
68 auto const uNodeIndex =
69 parseVault(context.params, jvResult).value_or(beast::zero);
70 if (uNodeIndex == beast::zero)
71 {
72 jvResult[jss::error] = "malformedRequest";
73 return jvResult;
74 }
75
76 auto const sleVault = lpLedger->read(keylet::vault(uNodeIndex));
77 auto const sleIssuance = sleVault == nullptr //
78 ? nullptr
79 : lpLedger->read(keylet::mptIssuance(sleVault->at(sfShareMPTID)));
80 if (!sleVault || !sleIssuance)
81 {
82 jvResult[jss::error] = "entryNotFound";
83 return jvResult;
84 }
85
86 Json::Value& vault = jvResult[jss::vault];
87 vault = sleVault->getJson(JsonOptions::none);
88 auto& share = vault[jss::shares];
89 share = sleIssuance->getJson(JsonOptions::none);
90
91 jvResult[jss::vault] = vault;
92 return jvResult;
93}
94
95} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
static constexpr UInt maxUInt
Definition json_value.h:145
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
Definition base_uint.h:484
T is_same_v
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
Definition ErrorCodes.h:214
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Definition Indexes.cpp:507
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Definition Indexes.cpp:545
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ rpcACT_MALFORMED
Definition ErrorCodes.h:71
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
static Expected< uint256, Json::Value > parseVault(Json::Value const &params, Json::StaticString const fieldName)
Json::Value doVaultInfo(RPC::JsonContext &)
Definition VaultInfo.cpp:60
uint256 key
Definition Keylet.h:21