diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp index 3b06e7cb0..b23afdfd1 100644 --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -1,99 +1,95 @@ // Copyright (c) 2017-2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include static UniValue getexcessiveblock(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error(RPCHelpMan{ - "getexcessiveblock", - "\nReturn the excessive block size.", - {}, - RPCResult{" excessiveBlockSize (integer) block size in bytes\n"}, - RPCExamples{HelpExampleCli("getexcessiveblock", "") + - HelpExampleRpc("getexcessiveblock", "")}, - } - .ToString()); + RPCHelpMan{ + "getexcessiveblock", + "\nReturn the excessive block size.", + {}, + RPCResult{" excessiveBlockSize (integer) block size in bytes\n"}, + RPCExamples{HelpExampleCli("getexcessiveblock", "") + + HelpExampleRpc("getexcessiveblock", "")}, } + .Check(request); UniValue ret(UniValue::VOBJ); ret.pushKV("excessiveBlockSize", config.GetMaxBlockSize()); return ret; } static UniValue setexcessiveblock(Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 1) { - throw std::runtime_error(RPCHelpMan{ - "setexcessiveblock", - "\nSet the excessive block size. Excessive blocks will not be used " - "in the active chain or relayed. This discourages the propagation " - "of blocks that you consider excessively large.", - { - {"blockSize", RPCArg::Type::NUM, RPCArg::Optional::NO, - "Excessive block size in bytes. Must be greater than " + - std::to_string(LEGACY_MAX_BLOCK_SIZE) + "."}, - }, - RPCResult{" blockSize (integer) excessive block size in bytes\n"}, - RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") + - HelpExampleRpc("setexcessiveblock", "25000000")}, - } - .ToString()); + RPCHelpMan{ + "setexcessiveblock", + "\nSet the excessive block size. Excessive blocks will not be used in " + "the active chain or relayed. This discourages the propagation of " + "blocks that you consider excessively large.", + { + {"blockSize", RPCArg::Type::NUM, RPCArg::Optional::NO, + "Excessive block size in bytes. Must be greater than " + + std::to_string(LEGACY_MAX_BLOCK_SIZE) + "."}, + }, + RPCResult{" blockSize (integer) excessive block size in bytes\n"}, + RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") + + HelpExampleRpc("setexcessiveblock", "25000000")}, } + .Check(request); if (!request.params[0].isNum()) { throw JSONRPCError( RPC_INVALID_PARAMETER, std::string( "Invalid parameter, excessiveblock must be an integer")); } int64_t ebs = request.params[0].get_int64(); // Do not allow maxBlockSize to be set below historic 1MB limit if (ebs <= int64_t(LEGACY_MAX_BLOCK_SIZE)) { throw JSONRPCError( RPC_INVALID_PARAMETER, std::string( "Invalid parameter, excessiveblock must be larger than ") + std::to_string(LEGACY_MAX_BLOCK_SIZE)); } // Set the new max block size. { LOCK(cs_main); if (!config.SetMaxBlockSize(ebs)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected error"); } } // settingsToUserAgentString(); std::ostringstream ret; ret << "Excessive Block set to " << ebs << " bytes."; return UniValue(ret.str()); } // clang-format off static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "network", "getexcessiveblock", getexcessiveblock, {}}, { "network", "setexcessiveblock", setexcessiveblock, {"maxBlockSize"}}, }; // clang-format on void RegisterABCRPCCommands(CRPCTable &t) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); } } diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp index b574583d5..640753685 100644 --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -1,93 +1,89 @@ // Copyright (c) 2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include static UniValue getavalanchekey(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 0) { - throw std::runtime_error(RPCHelpMan{ - "getavalanchekey", - "\nReturns the key used to sign avalanche messages.\n", - {}, - RPCResults{}, - RPCExamples{HelpExampleRpc("getavalanchekey", "")}, - } - .ToString()); + RPCHelpMan{ + "getavalanchekey", + "\nReturns the key used to sign avalanche messages.\n", + {}, + RPCResults{}, + RPCExamples{HelpExampleRpc("getavalanchekey", "")}, } + .Check(request); if (!g_avalanche) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); } return HexStr(g_avalanche->getSessionPubKey()); } static UniValue addavalanchepeer(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 2) { - throw std::runtime_error(RPCHelpMan{ - "addavalanchepeer", - "\nAdd a peer to the set of peer to poll for avalanche.\n", - { - {"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, - "Node to be added to avalanche."}, - {"publickey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, - "The public key of the node."}, - }, - RPCResults{}, - RPCExamples{HelpExampleRpc("addavalanchepeer", "5")}, - } - .ToString()); + RPCHelpMan{ + "addavalanchepeer", + "\nAdd a peer to the set of peer to poll for avalanche.\n", + { + {"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, + "Node to be added to avalanche."}, + {"publickey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, + "The public key of the node."}, + }, + RPCResults{}, + RPCExamples{HelpExampleRpc("addavalanchepeer", "5")}, } + .Check(request); if (!g_avalanche) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Avalanche is not initialized"); } // Parse nodeid if (!request.params[0].isNum()) { throw JSONRPCError( RPC_INVALID_PARAMETER, std::string("Invalid parameter, nodeid must be an integer")); } NodeId nodeid = request.params[0].get_int64(); // 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 {}; } // clang-format off static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "avalanche", "getavalanchekey", getavalanchekey, {}}, { "avalanche", "addavalanchepeer", addavalanchepeer, {"nodeid"}}, }; // clang-format on void RegisterAvalancheRPCCommands(CRPCTable &t) { for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); } }