Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/avalanche.cpp
Show All 25 Lines | if (!g_avalanche) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); | ||||
} | } | ||||
return HexStr(g_avalanche->getSessionPubKey()); | return HexStr(g_avalanche->getSessionPubKey()); | ||||
} | } | ||||
static UniValue addavalanchepeer(const Config &config, | static UniValue addavalanchepeer(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"addavalanchepeer", | "addavalanchepeer", | ||||
"\nAdd a peer to the set of peer to poll for avalanche.\n", | "\nAdd a peer to the set of peer to poll for avalanche.\n", | ||||
{ | { | ||||
{"nodeid", RPCArg::Type::NUM, false}, | {"nodeid", RPCArg::Type::NUM, false}, | ||||
{"publickey", RPCArg::Type::STR_HEX, false}, | |||||
}} | }} | ||||
.ToString() + | .ToString() + | ||||
"\nArguments\n" + | "\nArguments\n" + | ||||
"1. nodeid (number, required) Node to be added to avalanche.\n" + | "1. nodeid (number, required) Node to be added to avalanche.\n" + | ||||
"2. publickey (sring, required) The public key of the node.\n" + | |||||
"\nExamples:\n" + HelpExampleRpc("addavalanchepeer", "5")); | "\nExamples:\n" + HelpExampleRpc("addavalanchepeer", "5")); | ||||
} | } | ||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); | ||||
} | } | ||||
// Parse nodeid | |||||
if (!request.params[0].isNum()) { | if (!request.params[0].isNum()) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
std::string("Invalid parameter, nodeid must be an integer")); | std::string("Invalid parameter, nodeid must be an integer")); | ||||
} | } | ||||
NodeId nodeid = request.params[0].get_int64(); | NodeId nodeid = request.params[0].get_int64(); | ||||
g_avalanche->addPeer(nodeid, 0); | |||||
// Parse the pubkey | |||||
const std::string keyHex = request.params[1].get_str(); | |||||
if ((keyHex.length() != 2 * CPubKey::COMPRESSED_PUBLIC_KEY_SIZE && | |||||
keyHex.length() != 2 * CPubKey::PUBLIC_KEY_SIZE) || | |||||
!IsHex(keyHex)) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
strprintf("Invalid public key: %s\n", keyHex)); | |||||
} | |||||
CPubKey pubkey{HexToPubKey(keyHex)}; | |||||
g_avalanche->addPeer(nodeid, 0, pubkey); | |||||
return {}; | return {}; | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
// ------------------- ------------------------ ---------------------- ---------- | // ------------------- ------------------------ ---------------------- ---------- | ||||
{ "avalanche", "getavalanchekey", getavalanchekey, {}}, | { "avalanche", "getavalanchekey", getavalanchekey, {}}, | ||||
Show All 9 Lines |