Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/avalanche.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche.h> | #include <avalanche.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
static UniValue getavalanchekey(const Config &config, | static UniValue getavalanchekey(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getavalanchekey", | "getavalanchekey", | ||||
"\nReturns the key used to sign avalanche messages.\n", | "\nReturns the key used to sign avalanche messages.\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + HelpExampleRpc("getavalanchekey", "")); | RPCExamples{HelpExampleRpc("getavalanchekey", "")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
if (!g_avalanche) { | 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() != 2) { | 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, /* opt */ false, | {"nodeid", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_value */ "", "Node to be added to avalanche."}, | /* default_value */ "", "Node to be added to avalanche."}, | ||||
{"publickey", RPCArg::Type::STR_HEX, /* opt */ false, | {"publickey", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_value */ "", "The public key of the node."}, | /* default_value */ "", "The public key of the node."}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nExamples:\n" + HelpExampleRpc("addavalanchepeer", "5")); | RPCExamples{HelpExampleRpc("addavalanchepeer", "5")}, | ||||
} | |||||
.ToStringWithResultsAndExamples()); | |||||
} | } | ||||
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 | // Parse nodeid | ||||
if (!request.params[0].isNum()) { | if (!request.params[0].isNum()) { | ||||
Show All 36 Lines |