Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
VaultInfo.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/Errors.hpp"
5#include "rpc/JS.hpp"
6#include "rpc/common/MetaProcessors.hpp"
7#include "rpc/common/Specs.hpp"
8#include "rpc/common/Types.hpp"
9#include "rpc/common/Validators.hpp"
10
11#include <boost/json/conversion.hpp>
12#include <boost/json/object.hpp>
13#include <boost/json/value.hpp>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/jss.h>
16
17#include <cstdint>
18#include <memory>
19#include <optional>
20#include <string>
21
22namespace rpc {
23
28 std::shared_ptr<BackendInterface> sharedPtrBackend_;
29
30public:
36 VaultInfoHandler(std::shared_ptr<BackendInterface> sharedPtrBackend);
37
41 struct Input {
42 std::optional<std::string> vaultID;
43 std::optional<std::string> owner;
44 std::optional<uint32_t> tnxSequence;
45 std::optional<uint32_t> ledgerIndex;
46 };
47
51 struct Output {
52 boost::json::value vault;
53 uint32_t ledgerIndex{};
54 bool validated = true;
55 };
56
57 using Result = HandlerReturnType<Output>;
58
65 static RpcSpecConstRef
66 spec([[maybe_unused]] uint32_t apiVersion)
67 {
68 static auto const kRPC_SPEC = RpcSpec{
69 {JS(vault_id),
72 Status(ClioError::RpcMalformedRequest)
73 }},
74 {JS(owner),
77 Status(ClioError::RpcMalformedRequest, "OwnerNotHexString")
78 }},
79 {JS(seq),
81 validation::Type<uint32_t>{}, Status(ClioError::RpcMalformedRequest)
82 }},
84 };
85
86 return kRPC_SPEC;
87 }
88
96 Result
97 process(Input const& input, Context const& ctx) const;
98
99private:
106 friend void
107 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
108
115 friend Input
116 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
117};
118
119} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the VaultInfo command.
Definition VaultInfo.cpp:61
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition VaultInfo.hpp:66
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition VaultInfo.cpp:143
VaultInfoHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new VaultInfo object.
Definition VaultInfo.cpp:55
A meta-processor that wraps a validator and produces a custom error in case the wrapped validator fai...
Definition MetaProcessors.hpp:152
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:18
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:130
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
Context of an RPC call.
Definition Types.hpp:99
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:110
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
A status returned from any RPC handler.
Definition Errors.hpp:65
A struct to hold the input data for the command.
Definition VaultInfo.hpp:41
A struct to hold the output data for the command.
Definition VaultInfo.hpp:51
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:489
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:551
static CustomValidator accountBase58Validator
Provides a commonly used validator for accounts.
Definition Validators.hpp:511
Validates that the type of the value is one of the given types.
Definition Validators.hpp:128