Use JSS string (#563)

#565
This commit is contained in:
cyan317
2023-03-28 09:07:10 +01:00
committed by GitHub
parent b69e4350a1
commit f604856eab
13 changed files with 224 additions and 213 deletions

View File

@@ -18,7 +18,6 @@
//============================================================================== //==============================================================================
#include <rpc/RPC.h> #include <rpc/RPC.h>
#include <rpc/RPCHelpers.h>
#include <rpc/ngHandlers/AccountChannels.h> #include <rpc/ngHandlers/AccountChannels.h>
namespace RPCng { namespace RPCng {
@@ -126,34 +125,34 @@ tag_invoke(
{ {
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
AccountChannelsHandler::Input input; AccountChannelsHandler::Input input;
input.account = jv.at("account").as_string().c_str(); input.account = jv.at(JS(account)).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();
} }
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 = 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 = 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; boost::json::object obj;
obj = { obj = {
{"account", output.account}, {JS(account), output.account},
{"ledger_hash", output.ledgerHash}, {JS(ledger_hash), output.ledgerHash},
{"ledger_index", output.ledgerIndex}, {JS(ledger_index), output.ledgerIndex},
{"validated", output.validated}, {JS(validated), output.validated},
{"limit", output.limit}, {JS(limit), output.limit},
{"channels", output.channels}}; {JS(channels), output.channels}};
if (output.marker) if (output.marker)
obj["marker"] = output.marker.value(); obj[JS(marker)] = output.marker.value();
jv = obj; jv = obj;
} }
@@ -187,24 +186,24 @@ tag_invoke(
{ {
boost::json::object obj; boost::json::object obj;
obj = { obj = {
{"channel_id", channel.channelID}, {JS(channel_id), channel.channelID},
{"account", channel.account}, {JS(account), channel.account},
{"account_destination", channel.accountDestination}, {JS(destination_account), channel.accountDestination},
{"amount", channel.amount}, {JS(amount), channel.amount},
{"balance", channel.balance}, {JS(balance), channel.balance},
{"settle_delay", channel.settleDelay}}; {JS(settle_delay), channel.settleDelay}};
if (channel.publicKey) if (channel.publicKey)
obj["public_key"] = *(channel.publicKey); obj[JS(public_key)] = *(channel.publicKey);
if (channel.publicKeyHex) if (channel.publicKeyHex)
obj["public_key_hex"] = *(channel.publicKeyHex); obj[JS(public_key_hex)] = *(channel.publicKeyHex);
if (channel.expiration) if (channel.expiration)
obj["expiration"] = *(channel.expiration); obj[JS(expiration)] = *(channel.expiration);
if (channel.cancelAfter) if (channel.cancelAfter)
obj["cancel_after"] = *(channel.cancelAfter); obj[JS(cancel_after)] = *(channel.cancelAfter);
if (channel.sourceTag) if (channel.sourceTag)
obj["source_tag"] = *(channel.sourceTag); obj[JS(source_tag)] = *(channel.sourceTag);
if (channel.destinationTag) if (channel.destinationTag)
obj["destination_tag"] = *(channel.destinationTag); obj[JS(destination_tag)] = *(channel.destinationTag);
jv = obj; jv = obj;
} }
} // namespace RPCng } // namespace RPCng

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -86,12 +87,12 @@ public:
{ {
// clang-format off // clang-format off
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"account", validation::Required{}, validation::AccountValidator}, {JS(account), validation::Required{}, validation::AccountValidator},
{"destination_account", validation::Type<std::string>{},validation::AccountValidator}, {JS(destination_account), validation::Type<std::string>{},validation::AccountValidator},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"limit", validation::Type<uint32_t>{},validation::Between{10,400}}, {JS(limit), validation::Type<uint32_t>{},validation::Between{10,400}},
{"ledger_index", validation::LedgerIndexValidator}, {JS(ledger_index), validation::LedgerIndexValidator},
{"marker", validation::MarkerValidator} {JS(marker), validation::MarkerValidator}
}; };
// clang-format on // clang-format on

View File

@@ -17,7 +17,6 @@
*/ */
//============================================================================== //==============================================================================
#include <rpc/RPCHelpers.h>
#include <rpc/ngHandlers/AccountCurrencies.h> #include <rpc/ngHandlers/AccountCurrencies.h>
namespace RPCng { namespace RPCng {
@@ -91,11 +90,11 @@ tag_invoke(
AccountCurrenciesHandler::Output const& output) AccountCurrenciesHandler::Output const& output)
{ {
jv = { jv = {
{"ledger_hash", output.ledgerHash}, {JS(ledger_hash), output.ledgerHash},
{"ledger_index", output.ledgerIndex}, {JS(ledger_index), output.ledgerIndex},
{"validated", output.validated}, {JS(validated), output.validated},
{"receive_currencies", output.receiveCurrencies}, {JS(receive_currencies), output.receiveCurrencies},
{"send_currencies", output.sendCurrencies}}; {JS(send_currencies), output.sendCurrencies}};
} }
AccountCurrenciesHandler::Input AccountCurrenciesHandler::Input
@@ -105,21 +104,21 @@ tag_invoke(
{ {
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
AccountCurrenciesHandler::Input input; AccountCurrenciesHandler::Input input;
input.account = jv.at("account").as_string().c_str(); input.account = jv.at(JS(account)).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 = 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; return input;

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -64,9 +65,9 @@ public:
spec() const spec() const
{ {
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"account", validation::Required{}, validation::AccountValidator}, {JS(account), validation::Required{}, validation::AccountValidator},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"ledger_index", validation::LedgerIndexValidator}}; {JS(ledger_index), validation::LedgerIndexValidator}};
return rpcSpec; return rpcSpec;
} }

View File

@@ -71,9 +71,9 @@ tag_invoke(
BookOffersHandler::Output const& output) BookOffersHandler::Output const& output)
{ {
jv = boost::json::object{ jv = boost::json::object{
{"ledger_hash", output.ledgerHash}, {JS(ledger_hash), output.ledgerHash},
{"ledger_index", output.ledgerIndex}, {JS(ledger_index), output.ledgerIndex},
{"offers", output.offers}, {JS(offers), output.offers},
}; };
} }
@@ -86,46 +86,54 @@ tag_invoke(
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
ripple::to_currency( ripple::to_currency(
input.getsCurrency, 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( ripple::to_currency(
input.paysCurrency, input.paysCurrency,
jv.at("taker_pays").as_object().at("currency").as_string().c_str()); jv.at(JS(taker_pays)).as_object().at(JS(currency)).as_string().c_str());
if (jv.at("taker_gets").as_object().contains("issuer")) if (jv.at(JS(taker_gets)).as_object().contains(JS(issuer)))
{ {
ripple::to_issuer( ripple::to_issuer(
input.getsID, 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( ripple::to_issuer(
input.paysID, 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 = 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 = 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; return input;

View File

@@ -66,38 +66,38 @@ public:
spec() const spec() const
{ {
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"taker_gets", {JS(taker_gets),
validation::Required{}, validation::Required{},
validation::Type<boost::json::object>{}, validation::Type<boost::json::object>{},
validation::Section{ validation::Section{
{"currency", {JS(currency),
validation::Required{}, validation::Required{},
validation::WithCustomError{ validation::WithCustomError{
validation::CurrencyValidator, validation::CurrencyValidator,
RPC::Status(RPC::RippledError::rpcDST_AMT_MALFORMED)}}, RPC::Status(RPC::RippledError::rpcDST_AMT_MALFORMED)}},
{"issuer", {JS(issuer),
validation::WithCustomError{ validation::WithCustomError{
validation::IssuerValidator, validation::IssuerValidator,
RPC::Status(RPC::RippledError::rpcDST_ISR_MALFORMED)}}}}, RPC::Status(RPC::RippledError::rpcDST_ISR_MALFORMED)}}}},
{"taker_pays", {JS(taker_pays),
validation::Required{}, validation::Required{},
validation::Type<boost::json::object>{}, validation::Type<boost::json::object>{},
validation::Section{ validation::Section{
{"currency", {JS(currency),
validation::Required{}, validation::Required{},
validation::WithCustomError{ validation::WithCustomError{
validation::CurrencyValidator, validation::CurrencyValidator,
RPC::Status(RPC::RippledError::rpcSRC_CUR_MALFORMED)}}, RPC::Status(RPC::RippledError::rpcSRC_CUR_MALFORMED)}},
{"issuer", {JS(issuer),
validation::WithCustomError{ validation::WithCustomError{
validation::IssuerValidator, validation::IssuerValidator,
RPC::Status(RPC::RippledError::rpcSRC_ISR_MALFORMED)}}}}, RPC::Status(RPC::RippledError::rpcSRC_ISR_MALFORMED)}}}},
{"taker", validation::AccountValidator}, {JS(taker), validation::AccountValidator},
{"limit", {JS(limit),
validation::Type<uint32_t>{}, validation::Type<uint32_t>{},
validation::Between{1, 100}}, validation::Between{1, 100}},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"ledger_index", validation::LedgerIndexValidator}}; {JS(ledger_index), validation::LedgerIndexValidator}};
return rpcSpec; return rpcSpec;
} }

View File

@@ -17,7 +17,6 @@
*/ */
//============================================================================== //==============================================================================
#include <rpc/RPCHelpers.h>
#include <rpc/ngHandlers/GatewayBalances.h> #include <rpc/ngHandlers/GatewayBalances.h>
namespace RPCng { namespace RPCng {
@@ -154,7 +153,7 @@ tag_invoke(
{ {
obligations[ripple::to_string(k)] = v.getText(); obligations[ripple::to_string(k)] = v.getText();
} }
obj["obligations"] = std::move(obligations); obj[JS(obligations)] = std::move(obligations);
} }
auto const toJson = auto const toJson =
@@ -181,17 +180,17 @@ tag_invoke(
}; };
if (auto balances = toJson(output.hotBalances); balances.size()) if (auto balances = toJson(output.hotBalances); balances.size())
obj["balances"] = balances; obj[JS(balances)] = balances;
// we don't have frozen_balances field in the // we don't have frozen_balances field in the
// document:https://xrpl.org/gateway_balances.html#gateway_balances // document:https://xrpl.org/gateway_balances.html#gateway_balances
if (auto balances = toJson(output.frozenBalances); balances.size()) 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()) if (auto balances = toJson(output.assets); balances.size())
obj["assets"] = balances; obj[JS(assets)] = balances;
obj["account"] = output.accountID; obj[JS(account)] = output.accountID;
obj["ledger_index"] = output.ledgerIndex; obj[JS(ledger_index)] = output.ledgerIndex;
obj["ledger_hash"] = output.ledgerHash; obj[JS(ledger_hash)] = output.ledgerHash;
if (output.overflow) if (output.overflow)
obj["overflow"] = true; obj["overflow"] = true;
jv = std::move(obj); jv = std::move(obj);
@@ -204,33 +203,33 @@ tag_invoke(
{ {
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
GatewayBalancesHandler::Input input; GatewayBalancesHandler::Input input;
input.account = jv.at("account").as_string().c_str(); input.account = jv.at(JS(account)).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 = 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( input.hotWallets.insert(*RPC::accountFromStringStrict(
jv.at("hotwallet").as_string().c_str())); jv.at(JS(hotwallet)).as_string().c_str()));
} }
else else
{ {
auto const& hotWallets = jv.at("hotwallet").as_array(); auto const& hotWallets = jv.at(JS(hotwallet)).as_array();
std::transform( std::transform(
hotWallets.begin(), hotWallets.begin(),
hotWallets.end(), hotWallets.end(),

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -104,10 +105,10 @@ public:
}}; }};
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"account", validation::Required{}, validation::AccountValidator}, {JS(account), validation::Required{}, validation::AccountValidator},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"ledger_index", validation::LedgerIndexValidator}, {JS(ledger_index), validation::LedgerIndexValidator},
{"hotwallet", hotWalletValidator}}; {JS(hotwallet), hotWalletValidator}};
return rpcSpec; return rpcSpec;
} }

View File

@@ -17,7 +17,6 @@
*/ */
//============================================================================== //==============================================================================
#include <rpc/RPCHelpers.h>
#include <rpc/ngHandlers/LedgerEntry.h> #include <rpc/ngHandlers/LedgerEntry.h>
#include <unordered_map> #include <unordered_map>
@@ -49,51 +48,52 @@ LedgerEntryHandler::process(
else if (input.offer) else if (input.offer)
{ {
auto const id = ripple::parseBase58<ripple::AccountID>( auto const id = ripple::parseBase58<ripple::AccountID>(
input.offer->at("account").as_string().c_str()); input.offer->at(JS(account)).as_string().c_str());
key = ripple::keylet::offer( key =
*id, ripple::keylet::offer(
boost::json::value_to<std::uint32_t>(input.offer->at("seq"))) *id,
.key; boost::json::value_to<std::uint32_t>(input.offer->at(JS(seq))))
.key;
} }
else if (input.rippleStateAccount) else if (input.rippleStateAccount)
{ {
auto const id1 = ripple::parseBase58<ripple::AccountID>( auto const id1 = ripple::parseBase58<ripple::AccountID>(
input.rippleStateAccount->at("accounts") input.rippleStateAccount->at(JS(accounts))
.as_array() .as_array()
.at(0) .at(0)
.as_string() .as_string()
.c_str()); .c_str());
auto const id2 = ripple::parseBase58<ripple::AccountID>( auto const id2 = ripple::parseBase58<ripple::AccountID>(
input.rippleStateAccount->at("accounts") input.rippleStateAccount->at(JS(accounts))
.as_array() .as_array()
.at(1) .at(1)
.as_string() .as_string()
.c_str()); .c_str());
auto const currency = ripple::to_currency( 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; key = ripple::keylet::line(*id1, *id2, currency).key;
} }
else if (input.escrow) else if (input.escrow)
{ {
auto const id = ripple::parseBase58<ripple::AccountID>( auto const id = ripple::parseBase58<ripple::AccountID>(
input.escrow->at("owner").as_string().c_str()); input.escrow->at(JS(owner)).as_string().c_str());
key = key = ripple::keylet::escrow(*id, input.escrow->at(JS(seq)).as_int64())
ripple::keylet::escrow(*id, input.escrow->at("seq").as_int64()).key; .key;
} }
else if (input.depositPreauth) else if (input.depositPreauth)
{ {
auto const owner = ripple::parseBase58<ripple::AccountID>( 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>( 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; key = ripple::keylet::depositPreauth(*owner, *authorized).key;
} }
else if (input.ticket) else if (input.ticket)
{ {
auto const id = ripple::parseBase58<ripple::AccountID>( 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( key = ripple::getTicketIndex(
*id, input.ticket->at("ticket_seq").as_int64()); *id, input.ticket->at(JS(ticket_seq)).as_int64());
} }
else else
{ {
@@ -146,28 +146,28 @@ LedgerEntryHandler::composeKeyFromDirectory(
boost::json::object const& directory) const noexcept boost::json::object const& directory) const noexcept
{ {
// can not specify both dir_root and owner. // 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{ return RPC::Status{
RPC::RippledError::rpcINVALID_PARAMS, RPC::RippledError::rpcINVALID_PARAMS,
"mayNotSpecifyBothDirRootAndOwner"}; "mayNotSpecifyBothDirRootAndOwner"};
// at least one should availiable // 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{ return RPC::Status{
RPC::RippledError::rpcINVALID_PARAMS, "missingOwnerOrDirRoot"}; RPC::RippledError::rpcINVALID_PARAMS, "missingOwnerOrDirRoot"};
uint64_t const subIndex = directory.contains("sub_index") uint64_t const subIndex = directory.contains(JS(sub_index))
? boost::json::value_to<uint64_t>(directory.at("sub_index")) ? boost::json::value_to<uint64_t>(directory.at(JS(sub_index)))
: 0; : 0;
if (directory.contains("dir_root")) if (directory.contains(JS(dir_root)))
{ {
ripple::uint256 const uDirRoot{ 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; return ripple::keylet::page(uDirRoot, subIndex).key;
} }
auto const ownerID = ripple::parseBase58<ripple::AccountID>( 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) return ripple::keylet::page(ripple::keylet::ownerDir(*ownerID), subIndex)
.key; .key;
} }
@@ -179,17 +179,17 @@ tag_invoke(
LedgerEntryHandler::Output const& output) LedgerEntryHandler::Output const& output)
{ {
auto object = boost::json::object{ auto object = boost::json::object{
{"ledger_hash", output.ledgerHash}, {JS(ledger_hash), output.ledgerHash},
{"ledger_index", output.ledgerIndex}, {JS(ledger_index), output.ledgerIndex},
{"validated", output.validated}, {JS(validated), output.validated},
{"index", output.index}}; {JS(index), output.index}};
if (output.nodeBinary) if (output.nodeBinary)
{ {
object["node_binary"] = *(output.nodeBinary); object[JS(node_binary)] = *(output.nodeBinary);
} }
else else
{ {
object["node"] = *(output.node); object[JS(node)] = *(output.node);
} }
jv = std::move(object); jv = std::move(object);
} }
@@ -201,37 +201,37 @@ tag_invoke(
{ {
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
LedgerEntryHandler::Input input; 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 = 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 // check all the protential index
static auto const indexFieldTypeMap = static auto const indexFieldTypeMap =
std::unordered_map<std::string, ripple::LedgerEntryType>{ std::unordered_map<std::string, ripple::LedgerEntryType>{
{"index", ripple::ltANY}, {JS(index), ripple::ltANY},
{"directory", ripple::ltDIR_NODE}, {JS(directory), ripple::ltDIR_NODE},
{"offer", ripple::ltOFFER}, {JS(offer), ripple::ltOFFER},
{"check", ripple::ltCHECK}, {JS(check), ripple::ltCHECK},
{"escrow", ripple::ltESCROW}, {JS(escrow), ripple::ltESCROW},
{"payment_channel", ripple::ltPAYCHAN}, {JS(payment_channel), ripple::ltPAYCHAN},
{"deposit_preauth", ripple::ltDEPOSIT_PREAUTH}, {JS(deposit_preauth), ripple::ltDEPOSIT_PREAUTH},
{"ticket", ripple::ltTICKET}}; {JS(ticket), ripple::ltTICKET}};
auto const indexFieldType = std::find_if( auto const indexFieldType = std::find_if(
indexFieldTypeMap.begin(), indexFieldTypeMap.begin(),
@@ -247,34 +247,34 @@ tag_invoke(
input.expectedType = indexFieldType->second; input.expectedType = indexFieldType->second;
} }
// check if request for account root // 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 // 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; return input;
} }

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -102,81 +103,83 @@ public:
}}; }};
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"binary", validation::Type<bool>{}}, {JS(binary), validation::Type<bool>{}},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"ledger_index", validation::LedgerIndexValidator}, {JS(ledger_index), validation::LedgerIndexValidator},
{"index", validation::Uint256HexStringValidator}, {JS(index), validation::Uint256HexStringValidator},
{"account_root", validation::AccountBase58Validator}, {JS(account_root), validation::AccountBase58Validator},
{"check", validation::Uint256HexStringValidator}, {JS(check), validation::Uint256HexStringValidator},
{"deposit_preauth", {JS(deposit_preauth),
validation::Type<std::string, boost::json::object>{}, validation::Type<std::string, boost::json::object>{},
validation::IfType<std::string>{ validation::IfType<std::string>{
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
validation::IfType<boost::json::object>{ validation::IfType<boost::json::object>{
validation::Section{ validation::Section{
{"owner", {JS(owner),
validation::Required{}, validation::Required{},
validation::AccountBase58Validator}, validation::AccountBase58Validator},
{"authorized", {JS(authorized),
validation::Required{}, validation::Required{},
validation::AccountBase58Validator}, validation::AccountBase58Validator},
}, },
}}, }},
{"directory", {JS(directory),
validation::Type<std::string, boost::json::object>{}, validation::Type<std::string, boost::json::object>{},
validation::IfType<std::string>{ validation::IfType<std::string>{
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
validation::IfType<boost::json::object>{validation::Section{ validation::IfType<boost::json::object>{validation::Section{
{"owner", validation::AccountBase58Validator}, {JS(owner), validation::AccountBase58Validator},
{"dir_root", validation::Uint256HexStringValidator}, {JS(dir_root), validation::Uint256HexStringValidator},
{"sub_index", validation::Type<uint32_t>{}}}}}, {JS(sub_index), validation::Type<uint32_t>{}}}}},
{"escrow", {JS(escrow),
validation::Type<std::string, boost::json::object>{}, validation::Type<std::string, boost::json::object>{},
validation::IfType<std::string>{ validation::IfType<std::string>{
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
validation::IfType<boost::json::object>{ validation::IfType<boost::json::object>{
validation::Section{ validation::Section{
{"owner", {JS(owner),
validation::Required{}, validation::Required{},
validation::AccountBase58Validator}, validation::AccountBase58Validator},
{"seq", {JS(seq),
validation::Required{}, validation::Required{},
validation::Type<uint32_t>{}}, validation::Type<uint32_t>{}},
}, },
}}, }},
{"offer", {JS(offer),
validation::Type<std::string, boost::json::object>{}, validation::Type<std::string, boost::json::object>{},
validation::IfType<std::string>{ validation::IfType<std::string>{
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
validation::IfType<boost::json::object>{ validation::IfType<boost::json::object>{
validation::Section{ validation::Section{
{"account", {JS(account),
validation::Required{}, validation::Required{},
validation::AccountBase58Validator}, validation::AccountBase58Validator},
{"seq", {JS(seq),
validation::Required{}, validation::Required{},
validation::Type<uint32_t>{}}, validation::Type<uint32_t>{}},
}, },
}}, }},
{"payment_channel", validation::Uint256HexStringValidator}, {JS(payment_channel), validation::Uint256HexStringValidator},
{"ripple_state", {JS(ripple_state),
validation::Type<boost::json::object>{}, validation::Type<boost::json::object>{},
validation::Section{ validation::Section{
{"accounts", validation::Required{}, rippleStateAccountsCheck}, {JS(accounts),
{"currency", validation::Required{},
rippleStateAccountsCheck},
{JS(currency),
validation::Required{}, validation::Required{},
validation::CurrencyValidator}, validation::CurrencyValidator},
}}, }},
{"ticket", {JS(ticket),
validation::Type<std::string, boost::json::object>{}, validation::Type<std::string, boost::json::object>{},
validation::IfType<std::string>{ validation::IfType<std::string>{
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
validation::IfType<boost::json::object>{ validation::IfType<boost::json::object>{
validation::Section{ validation::Section{
{"account", {JS(account),
validation::Required{}, validation::Required{},
validation::AccountBase58Validator}, validation::AccountBase58Validator},
{"ticket_seq", {JS(ticket_seq),
validation::Required{}, validation::Required{},
validation::Type<uint32_t>{}}, validation::Type<uint32_t>{}},
}, },

View File

@@ -17,7 +17,6 @@
*/ */
//============================================================================== //==============================================================================
#include <rpc/RPCHelpers.h>
#include <rpc/ngHandlers/TransactionEntry.h> #include <rpc/ngHandlers/TransactionEntry.h>
namespace RPCng { namespace RPCng {
@@ -87,21 +86,21 @@ tag_invoke(
auto const& jsonObject = jv.as_object(); auto const& jsonObject = jv.as_object();
TransactionEntryHandler::Input input; TransactionEntryHandler::Input input;
input.txHash = jv.at("tx_hash").as_string().c_str(); input.txHash = jv.at(JS(tx_hash)).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 = 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; return input;

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include <backend/BackendInterface.h> #include <backend/BackendInterface.h>
#include <rpc/RPCHelpers.h>
#include <rpc/common/Types.h> #include <rpc/common/Types.h>
#include <rpc/common/Validators.h> #include <rpc/common/Validators.h>
@@ -61,11 +62,11 @@ public:
spec() const spec() const
{ {
static const RpcSpec rpcSpec = { static const RpcSpec rpcSpec = {
{"tx_hash", {JS(tx_hash),
validation::Required{}, validation::Required{},
validation::Uint256HexStringValidator}, validation::Uint256HexStringValidator},
{"ledger_hash", validation::Uint256HexStringValidator}, {JS(ledger_hash), validation::Uint256HexStringValidator},
{"ledger_index", validation::LedgerIndexValidator}}; {JS(ledger_index), validation::LedgerIndexValidator}};
return rpcSpec; return rpcSpec;
} }

View File

@@ -381,7 +381,7 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
{ {
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321", "channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321",
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
"amount":"100", "amount":"100",
"balance":"10", "balance":"10",
"settle_delay":32, "settle_delay":32,
@@ -391,7 +391,7 @@ TEST_F(RPCAccountHandlerTest, DefaultParameterTest)
{ {
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322", "channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322",
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
"amount":"100", "amount":"100",
"balance":"10", "balance":"10",
"settle_delay":32, "settle_delay":32,
@@ -634,7 +634,7 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
{ {
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321", "channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC321",
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
"amount":"100", "amount":"100",
"balance":"10", "balance":"10",
"settle_delay":32, "settle_delay":32,
@@ -648,7 +648,7 @@ TEST_F(RPCAccountHandlerTest, OptionalResponseField)
{ {
"channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322", "channel_id":"E6DBAFC99223B42257915A63DFC6B0C032D4070F9A574B255AD97466726FC322",
"account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", "account":"rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
"account_destination":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", "destination_account":"rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun",
"amount":"100", "amount":"100",
"balance":"10", "balance":"10",
"settle_delay":32, "settle_delay":32,