mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -86,7 +86,7 @@ public:
|
||||
spec() const
|
||||
{
|
||||
// clang-format off
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(destination_account), validation::Type<std::string>{},validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator}};
|
||||
|
||||
144
src/rpc/ngHandlers/AccountInfo.cpp
Normal file
144
src/rpc/ngHandlers/AccountInfo.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2023, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/ngHandlers/AccountInfo.h>
|
||||
|
||||
namespace RPCng {
|
||||
AccountInfoHandler::Result
|
||||
AccountInfoHandler::process(
|
||||
AccountInfoHandler::Input input,
|
||||
boost::asio::yield_context& yield) const
|
||||
{
|
||||
if (!input.account && !input.ident)
|
||||
return Error{RPC::Status{RPC::RippledError::rpcACT_MALFORMED}};
|
||||
|
||||
auto const range = sharedPtrBackend_->fetchLedgerRange();
|
||||
auto const lgrInfoOrStatus = RPC::getLedgerInfoFromHashOrSeq(
|
||||
*sharedPtrBackend_,
|
||||
yield,
|
||||
input.ledgerHash,
|
||||
input.ledgerIndex,
|
||||
range->maxSequence);
|
||||
|
||||
if (auto const status = std::get_if<RPC::Status>(&lgrInfoOrStatus))
|
||||
return Error{*status};
|
||||
|
||||
auto const lgrInfo = std::get<ripple::LedgerInfo>(lgrInfoOrStatus);
|
||||
|
||||
auto const accountStr = input.account.value_or(input.ident.value_or(""));
|
||||
auto const accountID = RPC::accountFromStringStrict(accountStr);
|
||||
auto const accountKeylet = ripple::keylet::account(*accountID);
|
||||
auto const accountLedgerObject = sharedPtrBackend_->fetchLedgerObject(
|
||||
accountKeylet.key, lgrInfo.seq, yield);
|
||||
if (!accountLedgerObject)
|
||||
return Error{RPC::Status{
|
||||
RPC::RippledError::rpcACT_NOT_FOUND, "accountNotFound"}};
|
||||
|
||||
ripple::STLedgerEntry const sle{
|
||||
ripple::SerialIter{
|
||||
accountLedgerObject->data(), accountLedgerObject->size()},
|
||||
accountKeylet.key};
|
||||
if (!accountKeylet.check(sle))
|
||||
return Error{RPC::Status{RPC::RippledError::rpcDB_DESERIALIZATION}};
|
||||
// Return SignerList(s) if that is requested.
|
||||
if (input.signerLists)
|
||||
{
|
||||
// We put the SignerList in an array because of an anticipated
|
||||
// future when we support multiple signer lists on one account.
|
||||
auto const signersKey = ripple::keylet::signers(*accountID);
|
||||
// This code will need to be revisited if in the future we
|
||||
// support multiple SignerLists on one account.
|
||||
auto const signers = sharedPtrBackend_->fetchLedgerObject(
|
||||
signersKey.key, lgrInfo.seq, yield);
|
||||
std::vector<ripple::STLedgerEntry> signerList;
|
||||
if (signers)
|
||||
{
|
||||
ripple::STLedgerEntry const sleSigners{
|
||||
ripple::SerialIter{signers->data(), signers->size()},
|
||||
signersKey.key};
|
||||
if (!signersKey.check(sleSigners))
|
||||
return Error{
|
||||
RPC::Status{RPC::RippledError::rpcDB_DESERIALIZATION}};
|
||||
|
||||
signerList.push_back(sleSigners);
|
||||
}
|
||||
return Output(
|
||||
lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle, signerList);
|
||||
}
|
||||
return Output(lgrInfo.seq, ripple::strHex(lgrInfo.hash), sle);
|
||||
}
|
||||
|
||||
void
|
||||
tag_invoke(
|
||||
boost::json::value_from_tag,
|
||||
boost::json::value& jv,
|
||||
AccountInfoHandler::Output const& output)
|
||||
{
|
||||
jv = boost::json::object{
|
||||
{JS(account_data), RPC::toJson(output.accountData)},
|
||||
{JS(ledger_hash), output.ledgerHash},
|
||||
{JS(ledger_index), output.ledgerIndex}};
|
||||
if (output.signerLists)
|
||||
{
|
||||
jv.as_object()[JS(signer_lists)] = boost::json::array();
|
||||
for (auto const& signerList : output.signerLists.value())
|
||||
jv.as_object()[JS(signer_lists)].as_array().push_back(
|
||||
RPC::toJson(signerList));
|
||||
}
|
||||
}
|
||||
|
||||
AccountInfoHandler::Input
|
||||
tag_invoke(
|
||||
boost::json::value_to_tag<AccountInfoHandler::Input>,
|
||||
boost::json::value const& jv)
|
||||
{
|
||||
auto const& jsonObject = jv.as_object();
|
||||
AccountInfoHandler::Input input;
|
||||
if (jsonObject.contains(JS(ident)))
|
||||
{
|
||||
input.ident = jsonObject.at(JS(ident)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains(JS(account)))
|
||||
{
|
||||
input.account = jsonObject.at(JS(account)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jsonObject.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jsonObject.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jsonObject.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains(JS(signer_lists)))
|
||||
{
|
||||
input.signerLists = jsonObject.at(JS(signer_lists)).as_bool();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
} // namespace RPCng
|
||||
112
src/rpc/ngHandlers/AccountInfo.h
Normal file
112
src/rpc/ngHandlers/AccountInfo.h
Normal file
@@ -0,0 +1,112 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of clio: https://github.com/XRPLF/clio
|
||||
Copyright (c) 2023, the clio developers.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
#include <boost/asio/spawn.hpp>
|
||||
|
||||
namespace RPCng {
|
||||
class AccountInfoHandler
|
||||
{
|
||||
std::shared_ptr<BackendInterface> sharedPtrBackend_;
|
||||
|
||||
public:
|
||||
struct Output
|
||||
{
|
||||
uint32_t ledgerIndex;
|
||||
std::string ledgerHash;
|
||||
ripple::STLedgerEntry accountData;
|
||||
std::optional<std::vector<ripple::STLedgerEntry>> signerLists;
|
||||
// validated should be sent via framework
|
||||
bool validated = true;
|
||||
|
||||
Output(
|
||||
uint32_t ledgerId,
|
||||
std::string ledgerHash,
|
||||
ripple::STLedgerEntry sle,
|
||||
std::vector<ripple::STLedgerEntry> signerLists)
|
||||
: ledgerIndex(ledgerId)
|
||||
, ledgerHash(std::move(ledgerHash))
|
||||
, accountData(std::move(sle))
|
||||
, signerLists(std::move(signerLists))
|
||||
{
|
||||
}
|
||||
|
||||
Output(
|
||||
uint32_t ledgerId,
|
||||
std::string ledgerHash,
|
||||
ripple::STLedgerEntry sle)
|
||||
: ledgerIndex(ledgerId)
|
||||
, ledgerHash(std::move(ledgerHash))
|
||||
, accountData(std::move(sle))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// "queue" is not available in Reporting mode
|
||||
// "ident" is deprecated, keep it for now, in line with rippled
|
||||
struct Input
|
||||
{
|
||||
std::optional<std::string> account;
|
||||
std::optional<std::string> ident;
|
||||
std::optional<std::string> ledgerHash;
|
||||
std::optional<uint32_t> ledgerIndex;
|
||||
bool signerLists = false;
|
||||
};
|
||||
|
||||
using Result = RPCng::HandlerReturnType<Output>;
|
||||
|
||||
AccountInfoHandler(
|
||||
std::shared_ptr<BackendInterface> const& sharedPtrBackend)
|
||||
: sharedPtrBackend_(sharedPtrBackend)
|
||||
{
|
||||
}
|
||||
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::AccountValidator},
|
||||
{JS(ident), validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
{JS(signer_lists), validation::Type<bool>{}}};
|
||||
return rpcSpec;
|
||||
}
|
||||
|
||||
Result
|
||||
process(Input input, boost::asio::yield_context& yield) const;
|
||||
};
|
||||
|
||||
void
|
||||
tag_invoke(
|
||||
boost::json::value_from_tag,
|
||||
boost::json::value& jv,
|
||||
AccountInfoHandler::Output const& output);
|
||||
|
||||
AccountInfoHandler::Input
|
||||
tag_invoke(
|
||||
boost::json::value_to_tag<AccountInfoHandler::Input>,
|
||||
boost::json::value const& jv);
|
||||
} // namespace RPCng
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(taker_gets),
|
||||
validation::Required{},
|
||||
validation::Type<boost::json::object>{},
|
||||
|
||||
@@ -104,7 +104,7 @@ public:
|
||||
return MaybeError{};
|
||||
}};
|
||||
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
return MaybeError{};
|
||||
}};
|
||||
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(binary), validation::Type<bool>{}},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
RpcSpecConstRef
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
static auto const rpcSpec = RpcSpec{
|
||||
{JS(tx_hash),
|
||||
validation::Required{},
|
||||
validation::Uint256HexStringValidator},
|
||||
|
||||
Reference in New Issue
Block a user