mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-26 21:45:50 +00:00
Add 'type' param to ledger_data and ledger rpc commands (RIPD-1446):
The 'type' field allows the rpc client to specify what type of ledger
entries to retrieve. The available types are:
"account"
"amendments"
"directory"
"fee"
"hashes"
"offer"
"signer_list"
"state"
"ticket"
This commit is contained in:
committed by
Nik Bougalis
parent
fab3ec0b56
commit
1a7a6f22e2
@@ -18,7 +18,12 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/protocol/LedgerFormats.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -165,4 +170,49 @@ LedgerFormats::getInstance ()
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::pair<RPC::Status, LedgerEntryType>
|
||||
chooseLedgerEntryType(Json::Value const& params)
|
||||
{
|
||||
std::pair<RPC::Status, LedgerEntryType> result{RPC::Status::OK, ltINVALID};
|
||||
if (params.isMember(jss::type))
|
||||
{
|
||||
static
|
||||
std::array<std::pair<char const *, LedgerEntryType>, 9> const types
|
||||
{{
|
||||
{ jss::account, ltACCOUNT_ROOT },
|
||||
{ jss::amendments, ltAMENDMENTS },
|
||||
{ jss::directory, ltDIR_NODE },
|
||||
{ jss::fee, ltFEE_SETTINGS },
|
||||
{ jss::hashes, ltLEDGER_HASHES },
|
||||
{ jss::offer, ltOFFER },
|
||||
{ jss::signer_list, ltSIGNER_LIST },
|
||||
{ jss::state, ltRIPPLE_STATE },
|
||||
{ jss::ticket, ltTICKET }
|
||||
}};
|
||||
|
||||
auto const& p = params[jss::type];
|
||||
if (!p.isString())
|
||||
{
|
||||
result.first = RPC::Status{rpcINVALID_PARAMS,
|
||||
"Invalid field 'type', not string."};
|
||||
assert(result.first.type() == RPC::Status::Type::error_code_i);
|
||||
return result;
|
||||
}
|
||||
|
||||
auto const filter = p.asString ();
|
||||
auto iter = std::find_if (types.begin (), types.end (),
|
||||
[&filter](decltype (types.front ())& t)
|
||||
{ return t.first == filter; });
|
||||
if (iter == types.end ())
|
||||
{
|
||||
result.first = RPC::Status{rpcINVALID_PARAMS,
|
||||
"Invalid field 'type'."};
|
||||
assert(result.first.type() == RPC::Status::Type::error_code_i);
|
||||
return result;
|
||||
}
|
||||
result.second = iter->second;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
Reference in New Issue
Block a user