-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New validator_info and manifest RPC methods #3197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,21 @@ class RPCParser | |
} | ||
} | ||
|
||
static bool validPublicKey (std::string const& strPk) | ||
{ | ||
if (parseBase58<PublicKey> (TokenType::AccountPublic, strPk)) | ||
return true; | ||
|
||
auto pkHex = strUnHex (strPk); | ||
if (!pkHex) | ||
return false; | ||
|
||
if (!publicKeyType(makeSlice(*pkHex))) | ||
return false; | ||
|
||
return true; | ||
Comment on lines
+153
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative here is this:
Note that this rewrite returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nbougalis do you mind if we leave this as is for this patch? The reason I suggest this is that this method is simply extracted verbatim from the parseFetchInfo method below. This way we can just focus on extracting the common logic here, and refactoring / cleaning this up in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at all. Whether review comments should be "resolved" is typically up to the PR author. Obviously, exceptions for bugs/problems exist, but this wasn't that. I'm fine with leaving this as is. |
||
} | ||
|
||
private: | ||
using parseFuncPtr = Json::Value (RPCParser::*) (Json::Value const& jvParams); | ||
|
||
|
@@ -203,6 +218,24 @@ class RPCParser | |
return v; | ||
} | ||
|
||
Json::Value parseManifest (Json::Value const& jvParams) | ||
{ | ||
if (jvParams.size () == 1) | ||
{ | ||
Json::Value jvRequest (Json::objectValue); | ||
|
||
std::string const strPk = jvParams[0u].asString (); | ||
if (!validPublicKey (strPk)) | ||
return rpcError (rpcPUBLIC_MALFORMED); | ||
|
||
jvRequest[jss::public_key] = strPk; | ||
|
||
return jvRequest; | ||
} | ||
|
||
return rpcError (rpcINVALID_PARAMS); | ||
} | ||
|
||
// fetch_info [clear] | ||
Json::Value parseFetchInfo (Json::Value const& jvParams) | ||
{ | ||
|
@@ -764,21 +797,7 @@ class RPCParser | |
{ | ||
std::string const strPk = jvParams[0u].asString (); | ||
|
||
bool const validPublicKey = [&strPk]{ | ||
if (parseBase58<PublicKey> (TokenType::AccountPublic, strPk)) | ||
return true; | ||
|
||
auto pkHex = strUnHex (strPk); | ||
if (!pkHex) | ||
return false; | ||
|
||
if (!publicKeyType(makeSlice(*pkHex))) | ||
return false; | ||
|
||
return true; | ||
}(); | ||
|
||
if (!validPublicKey) | ||
if (!validPublicKey(strPk)) | ||
return rpcError (rpcPUBLIC_MALFORMED); | ||
|
||
Json::Value jvRequest (Json::objectValue); | ||
|
@@ -1171,6 +1190,7 @@ class RPCParser | |
{ "ledger_request", &RPCParser::parseLedgerId, 1, 1 }, | ||
{ "log_level", &RPCParser::parseLogLevel, 0, 2 }, | ||
{ "logrotate", &RPCParser::parseAsIs, 0, 0 }, | ||
{ "manifest", &RPCParser::parseManifest, 1, 1 }, | ||
{ "owner_info", &RPCParser::parseAccountItems, 1, 2 }, | ||
{ "peers", &RPCParser::parseAsIs, 0, 0 }, | ||
{ "ping", &RPCParser::parseAsIs, 0, 0 }, | ||
|
@@ -1195,6 +1215,7 @@ class RPCParser | |
{ "tx_history", &RPCParser::parseTxHistory, 1, 1 }, | ||
{ "unl_list", &RPCParser::parseAsIs, 0, 0 }, | ||
{ "validation_create", &RPCParser::parseValidationCreate, 0, 1 }, | ||
{ "validator_info", &RPCParser::parseAsIs, 0, 0 }, | ||
{ "version", &RPCParser::parseAsIs, 0, 0 }, | ||
{ "wallet_propose", &RPCParser::parseWalletPropose, 0, 1 }, | ||
{ "internal", &RPCParser::parseInternal, 1, -1 }, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of rippled: https://github.com/ripple/rippled | ||
Copyright (c) 2019 Dev Null Productions | ||
|
||
Permission to use, copy, modify, and/or 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 <ripple/app/main/Application.h> | ||
#include <ripple/basics/base64.h> | ||
#include <ripple/json/json_value.h> | ||
#include <ripple/protocol/ErrorCodes.h> | ||
#include <ripple/protocol/jss.h> | ||
#include <ripple/rpc/Context.h> | ||
|
||
namespace ripple { | ||
Json::Value doManifest (RPC::JsonContext& context) | ||
{ | ||
auto& params = context.params; | ||
|
||
if (!params.isMember(jss::public_key)) | ||
return RPC::missing_field_error (jss::public_key); | ||
|
||
auto const requested = params[jss::public_key].asString(); | ||
|
||
Json::Value ret; | ||
ret[jss::requested] = requested; | ||
|
||
auto const pk = parseBase58<PublicKey>(TokenType::NodePublic, requested); | ||
if (!pk) | ||
{ | ||
RPC::inject_error(rpcINVALID_PARAMS, ret); | ||
return ret; | ||
} | ||
|
||
// first attempt to use params as ephemeral key, | ||
// if this lookup succeeds master key will be returned, | ||
// else pk will just be returned and we will assume that | ||
// is master key anyways | ||
auto const mk = context.app.validatorManifests().getMasterKey(*pk); | ||
|
||
auto const ek = context.app.validatorManifests().getSigningKey(mk); | ||
|
||
// if ephemeral key not found, we don't have specified manifest | ||
if (ek == mk) | ||
return ret; | ||
|
||
if (auto const manifest = context.app.validatorManifests().getManifest(mk)) | ||
ret[jss::manifest] = base64_encode(*manifest); | ||
Json::Value details; | ||
|
||
details[jss::master_key] = toBase58(TokenType::NodePublic, mk); | ||
details[jss::ephemeral_key] = toBase58(TokenType::NodePublic, ek); | ||
|
||
if (auto const seq = context.app.validatorManifests().getSequence(mk)) | ||
details[jss::seq] = *seq; | ||
|
||
if (auto const domain = context.app.validatorManifests().getDomain(mk)) | ||
details[jss::domain] = *domain; | ||
|
||
ret[jss::details] = details; | ||
return ret; | ||
} | ||
} // ripple |
Uh oh!
There was an error while loading. Please reload this page.