mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-25 21:15:49 +00:00
Fix levelization
* Move `chooseLedgerEntryType` from protocol to RPC
This commit is contained in:
committed by
Scott Schurr
parent
46004158a2
commit
96ece1b9f0
@@ -21,7 +21,6 @@
|
|||||||
#define RIPPLE_PROTOCOL_LEDGERFORMATS_H_INCLUDED
|
#define RIPPLE_PROTOCOL_LEDGERFORMATS_H_INCLUDED
|
||||||
|
|
||||||
#include <ripple/protocol/KnownFormats.h>
|
#include <ripple/protocol/KnownFormats.h>
|
||||||
#include <ripple/rpc/Status.h>
|
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -164,9 +163,6 @@ private:
|
|||||||
void addCommonFields (Item& item);
|
void addCommonFields (Item& item);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::pair<RPC::Status, LedgerEntryType>
|
|
||||||
chooseLedgerEntryType(Json::Value const& params);
|
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
|
#include <ripple/protocol/LedgerFormats.h>
|
||||||
#include <ripple/protocol/ErrorCodes.h>
|
#include <ripple/protocol/ErrorCodes.h>
|
||||||
#include <ripple/protocol/JsonFields.h>
|
#include <ripple/protocol/JsonFields.h>
|
||||||
#include <ripple/protocol/LedgerFormats.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -170,51 +170,4 @@ LedgerFormats::getInstance ()
|
|||||||
return instance;
|
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>, 11> 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 },
|
|
||||||
{ jss::escrow, ltESCROW },
|
|
||||||
{ jss::payment_channel, ltPAYCHAN }
|
|
||||||
}};
|
|
||||||
|
|
||||||
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
|
} // ripple
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ Json::Value doAccountObjects (RPC::Context& context)
|
|||||||
if (! ledger->exists(keylet::account (accountID)))
|
if (! ledger->exists(keylet::account (accountID)))
|
||||||
return rpcError (rpcACT_NOT_FOUND);
|
return rpcError (rpcACT_NOT_FOUND);
|
||||||
|
|
||||||
auto type = chooseLedgerEntryType(params);
|
auto type = RPC::chooseLedgerEntryType(params);
|
||||||
if (type.first)
|
if (type.first)
|
||||||
{
|
{
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ Json::Value doLedgerData (RPC::Context& context)
|
|||||||
LedgerFill::Options::binary : 0));
|
LedgerFill::Options::binary : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto type = chooseLedgerEntryType(params);
|
auto type = RPC::chooseLedgerEntryType(params);
|
||||||
if (type.first)
|
if (type.first)
|
||||||
{
|
{
|
||||||
jvResult.clear();
|
jvResult.clear();
|
||||||
|
|||||||
@@ -664,9 +664,58 @@ keypairForSignature(Json::Value const& params, Json::Value& error)
|
|||||||
return generateKeyPair (keyType, *seed);
|
return generateKeyPair (keyType, *seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
beast::SemanticVersion const firstVersion ("1.0.0");
|
std::pair<RPC::Status, LedgerEntryType>
|
||||||
beast::SemanticVersion const goodVersion ("1.0.0");
|
chooseLedgerEntryType(Json::Value const& params)
|
||||||
beast::SemanticVersion const lastVersion ("1.0.0");
|
{
|
||||||
|
std::pair<RPC::Status, LedgerEntryType> result{ RPC::Status::OK, ltINVALID };
|
||||||
|
if (params.isMember(jss::type))
|
||||||
|
{
|
||||||
|
static
|
||||||
|
std::array<std::pair<char const *, LedgerEntryType>, 11> 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 },
|
||||||
|
{ jss::escrow, ltESCROW },
|
||||||
|
{ jss::payment_channel, ltPAYCHAN }
|
||||||
|
} };
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
beast::SemanticVersion const firstVersion("1.0.0");
|
||||||
|
beast::SemanticVersion const goodVersion("1.0.0");
|
||||||
|
beast::SemanticVersion const lastVersion("1.0.0");
|
||||||
|
|
||||||
} // RPC
|
} // RPC
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ setVersion(Object& parent)
|
|||||||
object[jss::last] = lastVersion.print();
|
object[jss::last] = lastVersion.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<RPC::Status, LedgerEntryType>
|
||||||
|
chooseLedgerEntryType(Json::Value const& params);
|
||||||
|
|
||||||
} // RPC
|
} // RPC
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user