Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AccountInfo.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/AmendmentCenterInterface.hpp"
23#include "data/BackendInterface.hpp"
24#include "rpc/JS.hpp"
25#include "rpc/common/Checkers.hpp"
26#include "rpc/common/JsonBool.hpp"
27#include "rpc/common/Specs.hpp"
28#include "rpc/common/Types.hpp"
29#include "rpc/common/Validators.hpp"
30
31#include <boost/json/conversion.hpp>
32#include <boost/json/value.hpp>
33#include <xrpl/protocol/STLedgerEntry.h>
34#include <xrpl/protocol/jss.h>
35
36#include <cstdint>
37#include <memory>
38#include <optional>
39#include <string>
40#include <utility>
41#include <vector>
42
43namespace rpc {
44
51 std::shared_ptr<BackendInterface> sharedPtrBackend_;
52 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
53
54public:
58 struct Output {
59 uint32_t ledgerIndex;
60 std::string ledgerHash;
61 ripple::STLedgerEntry accountData;
62 bool isDisallowIncomingEnabled = false;
63 bool isClawbackEnabled = false;
64 uint32_t apiVersion;
65 std::optional<std::vector<ripple::STLedgerEntry>> signerLists;
66 // validated should be sent via framework
67 bool validated = true;
68
81 uint32_t ledgerId,
82 std::string ledgerHash,
83 ripple::STLedgerEntry sle,
84 bool isDisallowIncomingEnabled,
85 bool isClawbackEnabled,
86 uint32_t version,
87 std::optional<std::vector<ripple::STLedgerEntry>> signerLists = std::nullopt
88 )
89 : ledgerIndex(ledgerId)
90 , ledgerHash(std::move(ledgerHash))
91 , accountData(std::move(sle))
92 , isDisallowIncomingEnabled(isDisallowIncomingEnabled)
93 , isClawbackEnabled(isClawbackEnabled)
94 , apiVersion(version)
95 , signerLists(std::move(signerLists))
96 {
97 }
98 };
99
106 struct Input {
107 std::optional<std::string> account;
108 std::optional<std::string> ident;
109 std::optional<std::string> ledgerHash;
110 std::optional<uint32_t> ledgerIndex;
111 JsonBool signerLists{false};
112 };
113
114 using Result = HandlerReturnType<Output>;
115
123 std::shared_ptr<BackendInterface> const& sharedPtrBackend,
124 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
125 )
126 : sharedPtrBackend_(sharedPtrBackend), amendmentCenter_{amendmentCenter}
127 {
128 }
129
136 static RpcSpecConstRef
137 spec([[maybe_unused]] uint32_t apiVersion)
138 {
139 static auto const kRPC_SPEC_V1 = RpcSpec{
142 {JS(ident), check::Deprecated{}},
145 {JS(ledger), check::Deprecated{}},
146 {JS(strict), check::Deprecated{}}
147 };
148
149 static auto const kRPC_SPEC = RpcSpec{kRPC_SPEC_V1, {{JS(signer_lists), validation::Type<bool>{}}}};
150
151 return apiVersion == 1 ? kRPC_SPEC_V1 : kRPC_SPEC;
152 }
153
161 Result
162 process(Input input, Context const& ctx) const;
163
164private:
171 friend void
172 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
173
180 friend Input
181 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
182};
183
184} // namespace rpc
The account_info command retrieves information about an account, its activity, and its XRP balance.
Definition AccountInfo.hpp:50
AccountInfoHandler(std::shared_ptr< BackendInterface > const &sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new AccountInfoHandler object.
Definition AccountInfo.hpp:122
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AccountInfo.cpp:132
Result process(Input input, Context const &ctx) const
Process the AccountInfo command.
Definition AccountInfo.cpp:54
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition AccountInfo.hpp:137
Check for a deprecated fields.
Definition Checkers.hpp:62
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:36
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:145
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81
A struct to hold the input data for the command.
Definition AccountInfo.hpp:106
A struct to hold the output data of the command.
Definition AccountInfo.hpp:58
Output(uint32_t ledgerId, std::string ledgerHash, ripple::STLedgerEntry sle, bool isDisallowIncomingEnabled, bool isClawbackEnabled, uint32_t version, std::optional< std::vector< ripple::STLedgerEntry > > signerLists=std::nullopt)
Construct a new Output object.
Definition AccountInfo.hpp:80
Context of an RPC call.
Definition Types.hpp:118
A wrapper around bool that allows to convert from any JSON value.
Definition JsonBool.hpp:34
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129
Represents a Specification of an entire RPC command.
Definition Specs.hpp:98
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:491
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:484
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:530
Validates that the type of the value is one of the given types.
Definition Validators.hpp:142