mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-19 03:05:51 +00:00
@@ -18,7 +18,6 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/RPC.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/ngHandlers/AccountChannels.h>
|
||||
|
||||
namespace RPCng {
|
||||
@@ -126,34 +125,34 @@ tag_invoke(
|
||||
{
|
||||
auto const& jsonObject = jv.as_object();
|
||||
AccountChannelsHandler::Input input;
|
||||
input.account = jv.at("account").as_string().c_str();
|
||||
if (jsonObject.contains("limit"))
|
||||
input.account = jv.at(JS(account)).as_string().c_str();
|
||||
if (jsonObject.contains(JS(limit)))
|
||||
{
|
||||
input.limit = jv.at("limit").as_int64();
|
||||
input.limit = jv.at(JS(limit)).as_int64();
|
||||
}
|
||||
if (jsonObject.contains("marker"))
|
||||
if (jsonObject.contains(JS(marker)))
|
||||
{
|
||||
input.marker = jv.at("marker").as_string().c_str();
|
||||
input.marker = jv.at(JS(marker)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("destination_account"))
|
||||
if (jsonObject.contains(JS(destination_account)))
|
||||
{
|
||||
input.destinationAccount =
|
||||
jv.at("destination_account").as_string().c_str();
|
||||
jv.at(JS(destination_account)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,14 +167,14 @@ tag_invoke(
|
||||
{
|
||||
boost::json::object obj;
|
||||
obj = {
|
||||
{"account", output.account},
|
||||
{"ledger_hash", output.ledgerHash},
|
||||
{"ledger_index", output.ledgerIndex},
|
||||
{"validated", output.validated},
|
||||
{"limit", output.limit},
|
||||
{"channels", output.channels}};
|
||||
{JS(account), output.account},
|
||||
{JS(ledger_hash), output.ledgerHash},
|
||||
{JS(ledger_index), output.ledgerIndex},
|
||||
{JS(validated), output.validated},
|
||||
{JS(limit), output.limit},
|
||||
{JS(channels), output.channels}};
|
||||
if (output.marker)
|
||||
obj["marker"] = output.marker.value();
|
||||
obj[JS(marker)] = output.marker.value();
|
||||
jv = obj;
|
||||
}
|
||||
|
||||
@@ -187,24 +186,24 @@ tag_invoke(
|
||||
{
|
||||
boost::json::object obj;
|
||||
obj = {
|
||||
{"channel_id", channel.channelID},
|
||||
{"account", channel.account},
|
||||
{"account_destination", channel.accountDestination},
|
||||
{"amount", channel.amount},
|
||||
{"balance", channel.balance},
|
||||
{"settle_delay", channel.settleDelay}};
|
||||
{JS(channel_id), channel.channelID},
|
||||
{JS(account), channel.account},
|
||||
{JS(destination_account), channel.accountDestination},
|
||||
{JS(amount), channel.amount},
|
||||
{JS(balance), channel.balance},
|
||||
{JS(settle_delay), channel.settleDelay}};
|
||||
if (channel.publicKey)
|
||||
obj["public_key"] = *(channel.publicKey);
|
||||
obj[JS(public_key)] = *(channel.publicKey);
|
||||
if (channel.publicKeyHex)
|
||||
obj["public_key_hex"] = *(channel.publicKeyHex);
|
||||
obj[JS(public_key_hex)] = *(channel.publicKeyHex);
|
||||
if (channel.expiration)
|
||||
obj["expiration"] = *(channel.expiration);
|
||||
obj[JS(expiration)] = *(channel.expiration);
|
||||
if (channel.cancelAfter)
|
||||
obj["cancel_after"] = *(channel.cancelAfter);
|
||||
obj[JS(cancel_after)] = *(channel.cancelAfter);
|
||||
if (channel.sourceTag)
|
||||
obj["source_tag"] = *(channel.sourceTag);
|
||||
obj[JS(source_tag)] = *(channel.sourceTag);
|
||||
if (channel.destinationTag)
|
||||
obj["destination_tag"] = *(channel.destinationTag);
|
||||
obj[JS(destination_tag)] = *(channel.destinationTag);
|
||||
jv = obj;
|
||||
}
|
||||
} // namespace RPCng
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
@@ -86,12 +87,12 @@ public:
|
||||
{
|
||||
// clang-format off
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"account", validation::Required{}, validation::AccountValidator},
|
||||
{"destination_account", validation::Type<std::string>{},validation::AccountValidator},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"limit", validation::Type<uint32_t>{},validation::Between{10,400}},
|
||||
{"ledger_index", validation::LedgerIndexValidator},
|
||||
{"marker", validation::MarkerValidator}
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(destination_account), validation::Type<std::string>{},validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(limit), validation::Type<uint32_t>{},validation::Between{10,400}},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
{JS(marker), validation::MarkerValidator}
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/ngHandlers/AccountCurrencies.h>
|
||||
|
||||
namespace RPCng {
|
||||
@@ -91,11 +90,11 @@ tag_invoke(
|
||||
AccountCurrenciesHandler::Output const& output)
|
||||
{
|
||||
jv = {
|
||||
{"ledger_hash", output.ledgerHash},
|
||||
{"ledger_index", output.ledgerIndex},
|
||||
{"validated", output.validated},
|
||||
{"receive_currencies", output.receiveCurrencies},
|
||||
{"send_currencies", output.sendCurrencies}};
|
||||
{JS(ledger_hash), output.ledgerHash},
|
||||
{JS(ledger_index), output.ledgerIndex},
|
||||
{JS(validated), output.validated},
|
||||
{JS(receive_currencies), output.receiveCurrencies},
|
||||
{JS(send_currencies), output.sendCurrencies}};
|
||||
}
|
||||
|
||||
AccountCurrenciesHandler::Input
|
||||
@@ -105,21 +104,21 @@ tag_invoke(
|
||||
{
|
||||
auto const& jsonObject = jv.as_object();
|
||||
AccountCurrenciesHandler::Input input;
|
||||
input.account = jv.at("account").as_string().c_str();
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
input.account = jv.at(JS(account)).as_string().c_str();
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
return input;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
@@ -64,9 +65,9 @@ public:
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"account", validation::Required{}, validation::AccountValidator},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"ledger_index", validation::LedgerIndexValidator}};
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator}};
|
||||
return rpcSpec;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,9 +71,9 @@ tag_invoke(
|
||||
BookOffersHandler::Output const& output)
|
||||
{
|
||||
jv = boost::json::object{
|
||||
{"ledger_hash", output.ledgerHash},
|
||||
{"ledger_index", output.ledgerIndex},
|
||||
{"offers", output.offers},
|
||||
{JS(ledger_hash), output.ledgerHash},
|
||||
{JS(ledger_index), output.ledgerIndex},
|
||||
{JS(offers), output.offers},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -86,46 +86,54 @@ tag_invoke(
|
||||
auto const& jsonObject = jv.as_object();
|
||||
ripple::to_currency(
|
||||
input.getsCurrency,
|
||||
jv.at("taker_gets").as_object().at("currency").as_string().c_str());
|
||||
jv.at(JS(taker_gets)).as_object().at(JS(currency)).as_string().c_str());
|
||||
ripple::to_currency(
|
||||
input.paysCurrency,
|
||||
jv.at("taker_pays").as_object().at("currency").as_string().c_str());
|
||||
if (jv.at("taker_gets").as_object().contains("issuer"))
|
||||
jv.at(JS(taker_pays)).as_object().at(JS(currency)).as_string().c_str());
|
||||
if (jv.at(JS(taker_gets)).as_object().contains(JS(issuer)))
|
||||
{
|
||||
ripple::to_issuer(
|
||||
input.getsID,
|
||||
jv.at("taker_gets").as_object().at("issuer").as_string().c_str());
|
||||
jv.at(JS(taker_gets))
|
||||
.as_object()
|
||||
.at(JS(issuer))
|
||||
.as_string()
|
||||
.c_str());
|
||||
}
|
||||
if (jv.at("taker_pays").as_object().contains("issuer"))
|
||||
if (jv.at(JS(taker_pays)).as_object().contains(JS(issuer)))
|
||||
{
|
||||
ripple::to_issuer(
|
||||
input.paysID,
|
||||
jv.at("taker_pays").as_object().at("issuer").as_string().c_str());
|
||||
jv.at(JS(taker_pays))
|
||||
.as_object()
|
||||
.at(JS(issuer))
|
||||
.as_string()
|
||||
.c_str());
|
||||
}
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("taker"))
|
||||
if (jsonObject.contains(JS(taker)))
|
||||
{
|
||||
input.taker =
|
||||
RPC::accountFromStringStrict(jv.at("taker").as_string().c_str());
|
||||
RPC::accountFromStringStrict(jv.at(JS(taker)).as_string().c_str());
|
||||
}
|
||||
if (jsonObject.contains("limit"))
|
||||
if (jsonObject.contains(JS(limit)))
|
||||
{
|
||||
input.limit = jv.at("limit").as_int64();
|
||||
input.limit = jv.at(JS(limit)).as_int64();
|
||||
}
|
||||
|
||||
return input;
|
||||
|
||||
@@ -66,38 +66,38 @@ public:
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"taker_gets",
|
||||
{JS(taker_gets),
|
||||
validation::Required{},
|
||||
validation::Type<boost::json::object>{},
|
||||
validation::Section{
|
||||
{"currency",
|
||||
{JS(currency),
|
||||
validation::Required{},
|
||||
validation::WithCustomError{
|
||||
validation::CurrencyValidator,
|
||||
RPC::Status(RPC::RippledError::rpcDST_AMT_MALFORMED)}},
|
||||
{"issuer",
|
||||
{JS(issuer),
|
||||
validation::WithCustomError{
|
||||
validation::IssuerValidator,
|
||||
RPC::Status(RPC::RippledError::rpcDST_ISR_MALFORMED)}}}},
|
||||
{"taker_pays",
|
||||
{JS(taker_pays),
|
||||
validation::Required{},
|
||||
validation::Type<boost::json::object>{},
|
||||
validation::Section{
|
||||
{"currency",
|
||||
{JS(currency),
|
||||
validation::Required{},
|
||||
validation::WithCustomError{
|
||||
validation::CurrencyValidator,
|
||||
RPC::Status(RPC::RippledError::rpcSRC_CUR_MALFORMED)}},
|
||||
{"issuer",
|
||||
{JS(issuer),
|
||||
validation::WithCustomError{
|
||||
validation::IssuerValidator,
|
||||
RPC::Status(RPC::RippledError::rpcSRC_ISR_MALFORMED)}}}},
|
||||
{"taker", validation::AccountValidator},
|
||||
{"limit",
|
||||
{JS(taker), validation::AccountValidator},
|
||||
{JS(limit),
|
||||
validation::Type<uint32_t>{},
|
||||
validation::Between{1, 100}},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"ledger_index", validation::LedgerIndexValidator}};
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator}};
|
||||
return rpcSpec;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/ngHandlers/GatewayBalances.h>
|
||||
|
||||
namespace RPCng {
|
||||
@@ -154,7 +153,7 @@ tag_invoke(
|
||||
{
|
||||
obligations[ripple::to_string(k)] = v.getText();
|
||||
}
|
||||
obj["obligations"] = std::move(obligations);
|
||||
obj[JS(obligations)] = std::move(obligations);
|
||||
}
|
||||
|
||||
auto const toJson =
|
||||
@@ -181,17 +180,17 @@ tag_invoke(
|
||||
};
|
||||
|
||||
if (auto balances = toJson(output.hotBalances); balances.size())
|
||||
obj["balances"] = balances;
|
||||
obj[JS(balances)] = balances;
|
||||
|
||||
// we don't have frozen_balances field in the
|
||||
// document:https://xrpl.org/gateway_balances.html#gateway_balances
|
||||
if (auto balances = toJson(output.frozenBalances); balances.size())
|
||||
obj["frozen_balances"] = balances;
|
||||
obj[JS(frozen_balances)] = balances;
|
||||
if (auto balances = toJson(output.assets); balances.size())
|
||||
obj["assets"] = balances;
|
||||
obj["account"] = output.accountID;
|
||||
obj["ledger_index"] = output.ledgerIndex;
|
||||
obj["ledger_hash"] = output.ledgerHash;
|
||||
obj[JS(assets)] = balances;
|
||||
obj[JS(account)] = output.accountID;
|
||||
obj[JS(ledger_index)] = output.ledgerIndex;
|
||||
obj[JS(ledger_hash)] = output.ledgerHash;
|
||||
if (output.overflow)
|
||||
obj["overflow"] = true;
|
||||
jv = std::move(obj);
|
||||
@@ -204,33 +203,33 @@ tag_invoke(
|
||||
{
|
||||
auto const& jsonObject = jv.as_object();
|
||||
GatewayBalancesHandler::Input input;
|
||||
input.account = jv.at("account").as_string().c_str();
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
input.account = jv.at(JS(account)).as_string().c_str();
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("hotwallet"))
|
||||
if (jsonObject.contains(JS(hotwallet)))
|
||||
{
|
||||
if (jsonObject.at("hotwallet").is_string())
|
||||
if (jsonObject.at(JS(hotwallet)).is_string())
|
||||
{
|
||||
input.hotWallets.insert(*RPC::accountFromStringStrict(
|
||||
jv.at("hotwallet").as_string().c_str()));
|
||||
jv.at(JS(hotwallet)).as_string().c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto const& hotWallets = jv.at("hotwallet").as_array();
|
||||
auto const& hotWallets = jv.at(JS(hotwallet)).as_array();
|
||||
std::transform(
|
||||
hotWallets.begin(),
|
||||
hotWallets.end(),
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
@@ -104,10 +105,10 @@ public:
|
||||
}};
|
||||
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"account", validation::Required{}, validation::AccountValidator},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"ledger_index", validation::LedgerIndexValidator},
|
||||
{"hotwallet", hotWalletValidator}};
|
||||
{JS(account), validation::Required{}, validation::AccountValidator},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
{JS(hotwallet), hotWalletValidator}};
|
||||
return rpcSpec;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/ngHandlers/LedgerEntry.h>
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -49,51 +48,52 @@ LedgerEntryHandler::process(
|
||||
else if (input.offer)
|
||||
{
|
||||
auto const id = ripple::parseBase58<ripple::AccountID>(
|
||||
input.offer->at("account").as_string().c_str());
|
||||
key = ripple::keylet::offer(
|
||||
*id,
|
||||
boost::json::value_to<std::uint32_t>(input.offer->at("seq")))
|
||||
.key;
|
||||
input.offer->at(JS(account)).as_string().c_str());
|
||||
key =
|
||||
ripple::keylet::offer(
|
||||
*id,
|
||||
boost::json::value_to<std::uint32_t>(input.offer->at(JS(seq))))
|
||||
.key;
|
||||
}
|
||||
else if (input.rippleStateAccount)
|
||||
{
|
||||
auto const id1 = ripple::parseBase58<ripple::AccountID>(
|
||||
input.rippleStateAccount->at("accounts")
|
||||
input.rippleStateAccount->at(JS(accounts))
|
||||
.as_array()
|
||||
.at(0)
|
||||
.as_string()
|
||||
.c_str());
|
||||
auto const id2 = ripple::parseBase58<ripple::AccountID>(
|
||||
input.rippleStateAccount->at("accounts")
|
||||
input.rippleStateAccount->at(JS(accounts))
|
||||
.as_array()
|
||||
.at(1)
|
||||
.as_string()
|
||||
.c_str());
|
||||
auto const currency = ripple::to_currency(
|
||||
input.rippleStateAccount->at("currency").as_string().c_str());
|
||||
input.rippleStateAccount->at(JS(currency)).as_string().c_str());
|
||||
key = ripple::keylet::line(*id1, *id2, currency).key;
|
||||
}
|
||||
else if (input.escrow)
|
||||
{
|
||||
auto const id = ripple::parseBase58<ripple::AccountID>(
|
||||
input.escrow->at("owner").as_string().c_str());
|
||||
key =
|
||||
ripple::keylet::escrow(*id, input.escrow->at("seq").as_int64()).key;
|
||||
input.escrow->at(JS(owner)).as_string().c_str());
|
||||
key = ripple::keylet::escrow(*id, input.escrow->at(JS(seq)).as_int64())
|
||||
.key;
|
||||
}
|
||||
else if (input.depositPreauth)
|
||||
{
|
||||
auto const owner = ripple::parseBase58<ripple::AccountID>(
|
||||
input.depositPreauth->at("owner").as_string().c_str());
|
||||
input.depositPreauth->at(JS(owner)).as_string().c_str());
|
||||
auto const authorized = ripple::parseBase58<ripple::AccountID>(
|
||||
input.depositPreauth->at("authorized").as_string().c_str());
|
||||
input.depositPreauth->at(JS(authorized)).as_string().c_str());
|
||||
key = ripple::keylet::depositPreauth(*owner, *authorized).key;
|
||||
}
|
||||
else if (input.ticket)
|
||||
{
|
||||
auto const id = ripple::parseBase58<ripple::AccountID>(
|
||||
input.ticket->at("account").as_string().c_str());
|
||||
input.ticket->at(JS(account)).as_string().c_str());
|
||||
key = ripple::getTicketIndex(
|
||||
*id, input.ticket->at("ticket_seq").as_int64());
|
||||
*id, input.ticket->at(JS(ticket_seq)).as_int64());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -146,28 +146,28 @@ LedgerEntryHandler::composeKeyFromDirectory(
|
||||
boost::json::object const& directory) const noexcept
|
||||
{
|
||||
// can not specify both dir_root and owner.
|
||||
if (directory.contains("dir_root") && directory.contains("owner"))
|
||||
if (directory.contains(JS(dir_root)) && directory.contains(JS(owner)))
|
||||
return RPC::Status{
|
||||
RPC::RippledError::rpcINVALID_PARAMS,
|
||||
"mayNotSpecifyBothDirRootAndOwner"};
|
||||
// at least one should availiable
|
||||
if (!(directory.contains("dir_root") || directory.contains("owner")))
|
||||
if (!(directory.contains(JS(dir_root)) || directory.contains(JS(owner))))
|
||||
return RPC::Status{
|
||||
RPC::RippledError::rpcINVALID_PARAMS, "missingOwnerOrDirRoot"};
|
||||
|
||||
uint64_t const subIndex = directory.contains("sub_index")
|
||||
? boost::json::value_to<uint64_t>(directory.at("sub_index"))
|
||||
uint64_t const subIndex = directory.contains(JS(sub_index))
|
||||
? boost::json::value_to<uint64_t>(directory.at(JS(sub_index)))
|
||||
: 0;
|
||||
|
||||
if (directory.contains("dir_root"))
|
||||
if (directory.contains(JS(dir_root)))
|
||||
{
|
||||
ripple::uint256 const uDirRoot{
|
||||
directory.at("dir_root").as_string().c_str()};
|
||||
directory.at(JS(dir_root)).as_string().c_str()};
|
||||
return ripple::keylet::page(uDirRoot, subIndex).key;
|
||||
}
|
||||
|
||||
auto const ownerID = ripple::parseBase58<ripple::AccountID>(
|
||||
directory.at("owner").as_string().c_str());
|
||||
directory.at(JS(owner)).as_string().c_str());
|
||||
return ripple::keylet::page(ripple::keylet::ownerDir(*ownerID), subIndex)
|
||||
.key;
|
||||
}
|
||||
@@ -179,17 +179,17 @@ tag_invoke(
|
||||
LedgerEntryHandler::Output const& output)
|
||||
{
|
||||
auto object = boost::json::object{
|
||||
{"ledger_hash", output.ledgerHash},
|
||||
{"ledger_index", output.ledgerIndex},
|
||||
{"validated", output.validated},
|
||||
{"index", output.index}};
|
||||
{JS(ledger_hash), output.ledgerHash},
|
||||
{JS(ledger_index), output.ledgerIndex},
|
||||
{JS(validated), output.validated},
|
||||
{JS(index), output.index}};
|
||||
if (output.nodeBinary)
|
||||
{
|
||||
object["node_binary"] = *(output.nodeBinary);
|
||||
object[JS(node_binary)] = *(output.nodeBinary);
|
||||
}
|
||||
else
|
||||
{
|
||||
object["node"] = *(output.node);
|
||||
object[JS(node)] = *(output.node);
|
||||
}
|
||||
jv = std::move(object);
|
||||
}
|
||||
@@ -201,37 +201,37 @@ tag_invoke(
|
||||
{
|
||||
auto const& jsonObject = jv.as_object();
|
||||
LedgerEntryHandler::Input input;
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
if (jsonObject.contains("binary"))
|
||||
if (jsonObject.contains(JS(binary)))
|
||||
{
|
||||
input.binary = jv.at("binary").as_bool();
|
||||
input.binary = jv.at(JS(binary)).as_bool();
|
||||
}
|
||||
// check all the protential index
|
||||
static auto const indexFieldTypeMap =
|
||||
std::unordered_map<std::string, ripple::LedgerEntryType>{
|
||||
{"index", ripple::ltANY},
|
||||
{"directory", ripple::ltDIR_NODE},
|
||||
{"offer", ripple::ltOFFER},
|
||||
{"check", ripple::ltCHECK},
|
||||
{"escrow", ripple::ltESCROW},
|
||||
{"payment_channel", ripple::ltPAYCHAN},
|
||||
{"deposit_preauth", ripple::ltDEPOSIT_PREAUTH},
|
||||
{"ticket", ripple::ltTICKET}};
|
||||
{JS(index), ripple::ltANY},
|
||||
{JS(directory), ripple::ltDIR_NODE},
|
||||
{JS(offer), ripple::ltOFFER},
|
||||
{JS(check), ripple::ltCHECK},
|
||||
{JS(escrow), ripple::ltESCROW},
|
||||
{JS(payment_channel), ripple::ltPAYCHAN},
|
||||
{JS(deposit_preauth), ripple::ltDEPOSIT_PREAUTH},
|
||||
{JS(ticket), ripple::ltTICKET}};
|
||||
|
||||
auto const indexFieldType = std::find_if(
|
||||
indexFieldTypeMap.begin(),
|
||||
@@ -247,34 +247,34 @@ tag_invoke(
|
||||
input.expectedType = indexFieldType->second;
|
||||
}
|
||||
// check if request for account root
|
||||
else if (jsonObject.contains("account_root"))
|
||||
else if (jsonObject.contains(JS(account_root)))
|
||||
{
|
||||
input.accountRoot = jv.at("account_root").as_string().c_str();
|
||||
input.accountRoot = jv.at(JS(account_root)).as_string().c_str();
|
||||
}
|
||||
// no need to check if_object again, validator only allows string or object
|
||||
else if (jsonObject.contains("directory"))
|
||||
else if (jsonObject.contains(JS(directory)))
|
||||
{
|
||||
input.directory = jv.at("directory").as_object();
|
||||
input.directory = jv.at(JS(directory)).as_object();
|
||||
}
|
||||
else if (jsonObject.contains("offer"))
|
||||
else if (jsonObject.contains(JS(offer)))
|
||||
{
|
||||
input.offer = jv.at("offer").as_object();
|
||||
input.offer = jv.at(JS(offer)).as_object();
|
||||
}
|
||||
else if (jsonObject.contains("ripple_state"))
|
||||
else if (jsonObject.contains(JS(ripple_state)))
|
||||
{
|
||||
input.rippleStateAccount = jv.at("ripple_state").as_object();
|
||||
input.rippleStateAccount = jv.at(JS(ripple_state)).as_object();
|
||||
}
|
||||
else if (jsonObject.contains("escrow"))
|
||||
else if (jsonObject.contains(JS(escrow)))
|
||||
{
|
||||
input.escrow = jv.at("escrow").as_object();
|
||||
input.escrow = jv.at(JS(escrow)).as_object();
|
||||
}
|
||||
else if (jsonObject.contains("deposit_preauth"))
|
||||
else if (jsonObject.contains(JS(deposit_preauth)))
|
||||
{
|
||||
input.depositPreauth = jv.at("deposit_preauth").as_object();
|
||||
input.depositPreauth = jv.at(JS(deposit_preauth)).as_object();
|
||||
}
|
||||
else if (jsonObject.contains("ticket"))
|
||||
else if (jsonObject.contains(JS(ticket)))
|
||||
{
|
||||
input.ticket = jv.at("ticket").as_object();
|
||||
input.ticket = jv.at(JS(ticket)).as_object();
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
@@ -102,81 +103,83 @@ public:
|
||||
}};
|
||||
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"binary", validation::Type<bool>{}},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"ledger_index", validation::LedgerIndexValidator},
|
||||
{"index", validation::Uint256HexStringValidator},
|
||||
{"account_root", validation::AccountBase58Validator},
|
||||
{"check", validation::Uint256HexStringValidator},
|
||||
{"deposit_preauth",
|
||||
{JS(binary), validation::Type<bool>{}},
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator},
|
||||
{JS(index), validation::Uint256HexStringValidator},
|
||||
{JS(account_root), validation::AccountBase58Validator},
|
||||
{JS(check), validation::Uint256HexStringValidator},
|
||||
{JS(deposit_preauth),
|
||||
validation::Type<std::string, boost::json::object>{},
|
||||
validation::IfType<std::string>{
|
||||
validation::Uint256HexStringValidator},
|
||||
validation::IfType<boost::json::object>{
|
||||
validation::Section{
|
||||
{"owner",
|
||||
{JS(owner),
|
||||
validation::Required{},
|
||||
validation::AccountBase58Validator},
|
||||
{"authorized",
|
||||
{JS(authorized),
|
||||
validation::Required{},
|
||||
validation::AccountBase58Validator},
|
||||
},
|
||||
}},
|
||||
{"directory",
|
||||
{JS(directory),
|
||||
validation::Type<std::string, boost::json::object>{},
|
||||
validation::IfType<std::string>{
|
||||
validation::Uint256HexStringValidator},
|
||||
validation::IfType<boost::json::object>{validation::Section{
|
||||
{"owner", validation::AccountBase58Validator},
|
||||
{"dir_root", validation::Uint256HexStringValidator},
|
||||
{"sub_index", validation::Type<uint32_t>{}}}}},
|
||||
{"escrow",
|
||||
{JS(owner), validation::AccountBase58Validator},
|
||||
{JS(dir_root), validation::Uint256HexStringValidator},
|
||||
{JS(sub_index), validation::Type<uint32_t>{}}}}},
|
||||
{JS(escrow),
|
||||
validation::Type<std::string, boost::json::object>{},
|
||||
validation::IfType<std::string>{
|
||||
validation::Uint256HexStringValidator},
|
||||
validation::IfType<boost::json::object>{
|
||||
validation::Section{
|
||||
{"owner",
|
||||
{JS(owner),
|
||||
validation::Required{},
|
||||
validation::AccountBase58Validator},
|
||||
{"seq",
|
||||
{JS(seq),
|
||||
validation::Required{},
|
||||
validation::Type<uint32_t>{}},
|
||||
},
|
||||
}},
|
||||
{"offer",
|
||||
{JS(offer),
|
||||
validation::Type<std::string, boost::json::object>{},
|
||||
validation::IfType<std::string>{
|
||||
validation::Uint256HexStringValidator},
|
||||
validation::IfType<boost::json::object>{
|
||||
validation::Section{
|
||||
{"account",
|
||||
{JS(account),
|
||||
validation::Required{},
|
||||
validation::AccountBase58Validator},
|
||||
{"seq",
|
||||
{JS(seq),
|
||||
validation::Required{},
|
||||
validation::Type<uint32_t>{}},
|
||||
},
|
||||
}},
|
||||
{"payment_channel", validation::Uint256HexStringValidator},
|
||||
{"ripple_state",
|
||||
{JS(payment_channel), validation::Uint256HexStringValidator},
|
||||
{JS(ripple_state),
|
||||
validation::Type<boost::json::object>{},
|
||||
validation::Section{
|
||||
{"accounts", validation::Required{}, rippleStateAccountsCheck},
|
||||
{"currency",
|
||||
{JS(accounts),
|
||||
validation::Required{},
|
||||
rippleStateAccountsCheck},
|
||||
{JS(currency),
|
||||
validation::Required{},
|
||||
validation::CurrencyValidator},
|
||||
}},
|
||||
{"ticket",
|
||||
{JS(ticket),
|
||||
validation::Type<std::string, boost::json::object>{},
|
||||
validation::IfType<std::string>{
|
||||
validation::Uint256HexStringValidator},
|
||||
validation::IfType<boost::json::object>{
|
||||
validation::Section{
|
||||
{"account",
|
||||
{JS(account),
|
||||
validation::Required{},
|
||||
validation::AccountBase58Validator},
|
||||
{"ticket_seq",
|
||||
{JS(ticket_seq),
|
||||
validation::Required{},
|
||||
validation::Type<uint32_t>{}},
|
||||
},
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/ngHandlers/TransactionEntry.h>
|
||||
|
||||
namespace RPCng {
|
||||
@@ -87,21 +86,21 @@ tag_invoke(
|
||||
auto const& jsonObject = jv.as_object();
|
||||
|
||||
TransactionEntryHandler::Input input;
|
||||
input.txHash = jv.at("tx_hash").as_string().c_str();
|
||||
if (jsonObject.contains("ledger_hash"))
|
||||
input.txHash = jv.at(JS(tx_hash)).as_string().c_str();
|
||||
if (jsonObject.contains(JS(ledger_hash)))
|
||||
{
|
||||
input.ledgerHash = jv.at("ledger_hash").as_string().c_str();
|
||||
input.ledgerHash = jv.at(JS(ledger_hash)).as_string().c_str();
|
||||
}
|
||||
if (jsonObject.contains("ledger_index"))
|
||||
if (jsonObject.contains(JS(ledger_index)))
|
||||
{
|
||||
if (!jsonObject.at("ledger_index").is_string())
|
||||
if (!jsonObject.at(JS(ledger_index)).is_string())
|
||||
{
|
||||
input.ledgerIndex = jv.at("ledger_index").as_int64();
|
||||
input.ledgerIndex = jv.at(JS(ledger_index)).as_int64();
|
||||
}
|
||||
else if (jsonObject.at("ledger_index").as_string() != "validated")
|
||||
else if (jsonObject.at(JS(ledger_index)).as_string() != "validated")
|
||||
{
|
||||
input.ledgerIndex =
|
||||
std::stoi(jv.at("ledger_index").as_string().c_str());
|
||||
std::stoi(jv.at(JS(ledger_index)).as_string().c_str());
|
||||
}
|
||||
}
|
||||
return input;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <backend/BackendInterface.h>
|
||||
#include <rpc/RPCHelpers.h>
|
||||
#include <rpc/common/Types.h>
|
||||
#include <rpc/common/Validators.h>
|
||||
|
||||
@@ -61,11 +62,11 @@ public:
|
||||
spec() const
|
||||
{
|
||||
static const RpcSpec rpcSpec = {
|
||||
{"tx_hash",
|
||||
{JS(tx_hash),
|
||||
validation::Required{},
|
||||
validation::Uint256HexStringValidator},
|
||||
{"ledger_hash", validation::Uint256HexStringValidator},
|
||||
{"ledger_index", validation::LedgerIndexValidator}};
|
||||
{JS(ledger_hash), validation::Uint256HexStringValidator},
|
||||
{JS(ledger_index), validation::LedgerIndexValidator}};
|
||||
return rpcSpec;
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
|
||||
{
|
||||
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321",
|
||||
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"amount":"100",
|
||||
"balance":"10",
|
||||
"settle_delay":32,
|
||||
@@ -391,7 +391,7 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
|
||||
{
|
||||
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322",
|
||||
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"amount":"100",
|
||||
"balance":"10",
|
||||
"settle_delay":32,
|
||||
@@ -634,7 +634,7 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
|
||||
{
|
||||
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321",
|
||||
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"amount":"100",
|
||||
"balance":"10",
|
||||
"settle_delay":32,
|
||||
@@ -648,7 +648,7 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
|
||||
{
|
||||
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322",
|
||||
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
|
||||
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
|
||||
"amount":"100",
|
||||
"balance":"10",
|
||||
"settle_delay":32,
|
||||
|
||||
Reference in New Issue
Block a user