scripted-diff: Use getInt<T> over get_int/get_int64

-BEGIN VERIFY SCRIPT-
 sed -i 's|\<get_int64\>|getInt<int64_t>|g' $(git grep -l get_int ':(exclude)src/univalue')
 sed -i 's|\<get_int\>|getInt<int>|g'       $(git grep -l get_int ':(exclude)src/univalue')
-END VERIFY SCRIPT-
This commit is contained in:
MacroFake 2022-05-13 12:32:59 +02:00
parent e016c00e98
commit fa9af21878
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
32 changed files with 114 additions and 114 deletions

View file

@ -467,7 +467,7 @@ public:
if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO]; if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO];
const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]}; const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]};
if (networkinfo["version"].get_int() < 209900) { if (networkinfo["version"].getInt<int>() < 209900) {
throw std::runtime_error("-netinfo requires bitcoind server to be running v0.21.0 and up"); throw std::runtime_error("-netinfo requires bitcoind server to be running v0.21.0 and up");
} }
const int64_t time_now{count_seconds(Now<CliSeconds>())}; const int64_t time_now{count_seconds(Now<CliSeconds>())};
@ -488,16 +488,16 @@ public:
if (conn_type == "manual") ++m_manual_peers_count; if (conn_type == "manual") ++m_manual_peers_count;
if (DetailsRequested()) { if (DetailsRequested()) {
// Push data for this peer to the peers vector. // Push data for this peer to the peers vector.
const int peer_id{peer["id"].get_int()}; const int peer_id{peer["id"].getInt<int>()};
const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()}; const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].getInt<int>()};
const int version{peer["version"].get_int()}; const int version{peer["version"].getInt<int>()};
const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].get_int64()}; const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].getInt<int64_t>()};
const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].get_int64()}; const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].getInt<int64_t>()};
const int64_t conn_time{peer["conntime"].get_int64()}; const int64_t conn_time{peer["conntime"].getInt<int64_t>()};
const int64_t last_blck{peer["last_block"].get_int64()}; const int64_t last_blck{peer["last_block"].getInt<int64_t>()};
const int64_t last_recv{peer["lastrecv"].get_int64()}; const int64_t last_recv{peer["lastrecv"].getInt<int64_t>()};
const int64_t last_send{peer["lastsend"].get_int64()}; const int64_t last_send{peer["lastsend"].getInt<int64_t>()};
const int64_t last_trxn{peer["last_transaction"].get_int64()}; const int64_t last_trxn{peer["last_transaction"].getInt<int64_t>()};
const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()}; const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()};
const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()}; const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()};
const std::string addr{peer["addr"].get_str()}; const std::string addr{peer["addr"].get_str()};
@ -517,7 +517,7 @@ public:
} }
// Generate report header. // Generate report header.
std::string result{strprintf("%s client %s%s - server %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].get_int(), networkinfo["subversion"].get_str())}; std::string result{strprintf("%s client %s%s - server %i%s\n\n", PACKAGE_NAME, FormatFullVersion(), ChainToString(), networkinfo["protocolversion"].getInt<int>(), networkinfo["subversion"].get_str())};
// Report detailed peer connections list sorted by direction and minimum ping time. // Report detailed peer connections list sorted by direction and minimum ping time.
if (DetailsRequested() && !m_peers.empty()) { if (DetailsRequested() && !m_peers.empty()) {
@ -598,7 +598,7 @@ public:
max_addr_size = std::max(addr["address"].get_str().length() + 1, max_addr_size); max_addr_size = std::max(addr["address"].get_str().length() + 1, max_addr_size);
} }
for (const UniValue& addr : local_addrs) { for (const UniValue& addr : local_addrs) {
result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].get_int(), addr["score"].get_int()); result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].getInt<int>(), addr["score"].getInt<int>());
} }
} }
@ -851,7 +851,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
response = CallRPC(rh, strMethod, args, rpcwallet); response = CallRPC(rh, strMethod, args, rpcwallet);
if (fWait) { if (fWait) {
const UniValue& error = find_value(response, "error"); const UniValue& error = find_value(response, "error");
if (!error.isNull() && error["code"].get_int() == RPC_IN_WARMUP) { if (!error.isNull() && error["code"].getInt<int>() == RPC_IN_WARMUP) {
throw CConnectionFailed("server in warmup"); throw CConnectionFailed("server in warmup");
} }
} }
@ -886,13 +886,13 @@ static void ParseError(const UniValue& error, std::string& strPrint, int& nRet)
if (err_msg.isStr()) { if (err_msg.isStr()) {
strPrint += ("error message:\n" + err_msg.get_str()); strPrint += ("error message:\n" + err_msg.get_str());
} }
if (err_code.isNum() && err_code.get_int() == RPC_WALLET_NOT_SPECIFIED) { if (err_code.isNum() && err_code.getInt<int>() == RPC_WALLET_NOT_SPECIFIED) {
strPrint += "\nTry adding \"-rpcwallet=<filename>\" option to bitcoin-cli command line."; strPrint += "\nTry adding \"-rpcwallet=<filename>\" option to bitcoin-cli command line.";
} }
} else { } else {
strPrint = "error: " + error.write(); strPrint = "error: " + error.write();
} }
nRet = abs(error["code"].get_int()); nRet = abs(error["code"].getInt<int>());
} }
/** /**

View file

@ -612,7 +612,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')"); throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')");
} }
const int nOut = prevOut["vout"].get_int(); const int nOut = prevOut["vout"].getInt<int>();
if (nOut < 0) if (nOut < 0)
throw std::runtime_error("vout cannot be negative"); throw std::runtime_error("vout cannot be negative");

View file

@ -75,7 +75,7 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
{ {
// Send error reply from json-rpc error object // Send error reply from json-rpc error object
int nStatus = HTTP_INTERNAL_SERVER_ERROR; int nStatus = HTTP_INTERNAL_SERVER_ERROR;
int code = find_value(objError, "code").get_int(); int code = find_value(objError, "code").getInt<int>();
if (code == RPC_INVALID_REQUEST) if (code == RPC_INVALID_REQUEST)
nStatus = HTTP_BAD_REQUEST; nStatus = HTTP_BAD_REQUEST;

View file

@ -12,9 +12,9 @@
static const char* BANMAN_JSON_VERSION_KEY{"version"}; static const char* BANMAN_JSON_VERSION_KEY{"version"};
CBanEntry::CBanEntry(const UniValue& json) CBanEntry::CBanEntry(const UniValue& json)
: nVersion(json[BANMAN_JSON_VERSION_KEY].get_int()), : nVersion(json[BANMAN_JSON_VERSION_KEY].getInt<int>()),
nCreateTime(json["ban_created"].get_int64()), nCreateTime(json["ban_created"].getInt<int64_t>()),
nBanUntil(json["banned_until"].get_int64()) nBanUntil(json["banned_until"].getInt<int64_t>())
{ {
} }
@ -58,7 +58,7 @@ UniValue BanMapToJson(const banmap_t& bans)
void BanMapFromJson(const UniValue& bans_json, banmap_t& bans) void BanMapFromJson(const UniValue& bans_json, banmap_t& bans)
{ {
for (const auto& ban_entry_json : bans_json.getValues()) { for (const auto& ban_entry_json : bans_json.getValues()) {
const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()}; const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].getInt<int>()};
if (version != CBanEntry::CURRENT_VERSION) { if (version != CBanEntry::CURRENT_VERSION) {
LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version); LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version);
continue; continue;

View file

@ -426,7 +426,7 @@ public:
// try to handle the request. Otherwise, reraise the exception. // try to handle the request. Otherwise, reraise the exception.
if (!last_handler) { if (!last_handler) {
const UniValue& code = e["code"]; const UniValue& code = e["code"];
if (code.isNum() && code.get_int() == RPC_WALLET_NOT_FOUND) { if (code.isNum() && code.getInt<int>() == RPC_WALLET_NOT_FOUND) {
return false; return false;
} }
} }

View file

@ -457,7 +457,7 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
{ {
try // Nice formatting for standard-format error try // Nice formatting for standard-format error
{ {
int code = find_value(objError, "code").get_int(); int code = find_value(objError, "code").getInt<int>();
std::string message = find_value(objError, "message").get_str(); std::string message = find_value(objError, "message").get_str();
Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")"); Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")");
} }

View file

@ -110,7 +110,7 @@ static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateMan
CChain& active_chain = chainman.ActiveChain(); CChain& active_chain = chainman.ActiveChain();
if (param.isNum()) { if (param.isNum()) {
const int height{param.get_int()}; const int height{param.getInt<int>()};
if (height < 0) { if (height < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d is negative", height)); throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d is negative", height));
} }
@ -271,7 +271,7 @@ static RPCHelpMan waitfornewblock()
{ {
int timeout = 0; int timeout = 0;
if (!request.params[0].isNull()) if (!request.params[0].isNull())
timeout = request.params[0].get_int(); timeout = request.params[0].getInt<int>();
CUpdatedBlock block; CUpdatedBlock block;
{ {
@ -317,7 +317,7 @@ static RPCHelpMan waitforblock()
uint256 hash(ParseHashV(request.params[0], "blockhash")); uint256 hash(ParseHashV(request.params[0], "blockhash"));
if (!request.params[1].isNull()) if (!request.params[1].isNull())
timeout = request.params[1].get_int(); timeout = request.params[1].getInt<int>();
CUpdatedBlock block; CUpdatedBlock block;
{ {
@ -361,10 +361,10 @@ static RPCHelpMan waitforblockheight()
{ {
int timeout = 0; int timeout = 0;
int height = request.params[0].get_int(); int height = request.params[0].getInt<int>();
if (!request.params[1].isNull()) if (!request.params[1].isNull())
timeout = request.params[1].get_int(); timeout = request.params[1].getInt<int>();
CUpdatedBlock block; CUpdatedBlock block;
{ {
@ -445,7 +445,7 @@ static RPCHelpMan getblockfrompeer()
PeerManager& peerman = EnsurePeerman(node); PeerManager& peerman = EnsurePeerman(node);
const uint256& block_hash{ParseHashV(request.params[0], "blockhash")}; const uint256& block_hash{ParseHashV(request.params[0], "blockhash")};
const NodeId peer_id{request.params[1].get_int64()}; const NodeId peer_id{request.params[1].getInt<int64_t>()};
const CBlockIndex* const index = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(block_hash);); const CBlockIndex* const index = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(block_hash););
@ -485,7 +485,7 @@ static RPCHelpMan getblockhash()
LOCK(cs_main); LOCK(cs_main);
const CChain& active_chain = chainman.ActiveChain(); const CChain& active_chain = chainman.ActiveChain();
int nHeight = request.params[0].get_int(); int nHeight = request.params[0].getInt<int>();
if (nHeight < 0 || nHeight > active_chain.Height()) if (nHeight < 0 || nHeight > active_chain.Height())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
@ -694,7 +694,7 @@ static RPCHelpMan getblock()
if (request.params[1].isBool()) { if (request.params[1].isBool()) {
verbosity = request.params[1].get_bool() ? 1 : 0; verbosity = request.params[1].get_bool() ? 1 : 0;
} else { } else {
verbosity = request.params[1].get_int(); verbosity = request.params[1].getInt<int>();
} }
} }
@ -759,7 +759,7 @@ static RPCHelpMan pruneblockchain()
CChainState& active_chainstate = chainman.ActiveChainstate(); CChainState& active_chainstate = chainman.ActiveChainstate();
CChain& active_chain = active_chainstate.m_chain; CChain& active_chain = active_chainstate.m_chain;
int heightParam = request.params[0].get_int(); int heightParam = request.params[0].getInt<int>();
if (heightParam < 0) { if (heightParam < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height."); throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
} }
@ -1050,8 +1050,8 @@ static RPCHelpMan verifychain()
}, },
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].get_int()}; const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].getInt<int>()};
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()}; const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].getInt<int>()};
ChainstateManager& chainman = EnsureAnyChainman(request.context); ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(cs_main); LOCK(cs_main);
@ -1585,7 +1585,7 @@ static RPCHelpMan getchaintxstats()
if (request.params[0].isNull()) { if (request.params[0].isNull()) {
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1));
} else { } else {
blockcount = request.params[0].get_int(); blockcount = request.params[0].getInt<int>();
if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) { if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1");

View file

@ -109,7 +109,7 @@ static RPCHelpMan getnetworkhashps()
{ {
ChainstateManager& chainman = EnsureAnyChainman(request.context); ChainstateManager& chainman = EnsureAnyChainman(request.context);
LOCK(cs_main); LOCK(cs_main);
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, chainman.ActiveChain()); return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].getInt<int>() : 120, !request.params[1].isNull() ? request.params[1].getInt<int>() : -1, chainman.ActiveChain());
}, },
}; };
} }
@ -217,8 +217,8 @@ static RPCHelpMan generatetodescriptor()
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")}, "\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
const int num_blocks{request.params[0].get_int()}; const int num_blocks{request.params[0].getInt<int>()};
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()}; const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
CScript coinbase_script; CScript coinbase_script;
std::string error; std::string error;
@ -264,8 +264,8 @@ static RPCHelpMan generatetoaddress()
}, },
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
const int num_blocks{request.params[0].get_int()}; const int num_blocks{request.params[0].getInt<int>()};
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()}; const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
CTxDestination destination = DecodeDestination(request.params[1].get_str()); CTxDestination destination = DecodeDestination(request.params[1].get_str());
if (!IsValidDestination(destination)) { if (!IsValidDestination(destination)) {
@ -462,7 +462,7 @@ static RPCHelpMan prioritisetransaction()
LOCK(cs_main); LOCK(cs_main);
uint256 hash(ParseHashV(request.params[0], "txid")); uint256 hash(ParseHashV(request.params[0], "txid"));
CAmount nAmount = request.params[2].get_int64(); CAmount nAmount = request.params[2].getInt<int64_t>();
if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) { if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0."); throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.");
@ -657,7 +657,7 @@ static RPCHelpMan getblocktemplate()
// NOTE: It is important that this NOT be read if versionbits is supported // NOTE: It is important that this NOT be read if versionbits is supported
const UniValue& uvMaxVersion = find_value(oparam, "maxversion"); const UniValue& uvMaxVersion = find_value(oparam, "maxversion");
if (uvMaxVersion.isNum()) { if (uvMaxVersion.isNum()) {
nMaxVersionPreVB = uvMaxVersion.get_int64(); nMaxVersionPreVB = uvMaxVersion.getInt<int64_t>();
} }
} }
} }

View file

@ -412,7 +412,7 @@ static RPCHelpMan disconnectnode()
success = connman.DisconnectNode(address_arg.get_str()); success = connman.DisconnectNode(address_arg.get_str());
} else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) { } else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
/* handle disconnect-by-id */ /* handle disconnect-by-id */
NodeId nodeid = (NodeId) id_arg.get_int64(); NodeId nodeid = (NodeId) id_arg.getInt<int64_t>();
success = connman.DisconnectNode(nodeid); success = connman.DisconnectNode(nodeid);
} else { } else {
throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided."); throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
@ -720,7 +720,7 @@ static RPCHelpMan setban()
int64_t banTime = 0; //use standard bantime if not specified int64_t banTime = 0; //use standard bantime if not specified
if (!request.params[2].isNull()) if (!request.params[2].isNull())
banTime = request.params[2].get_int64(); banTime = request.params[2].getInt<int64_t>();
bool absolute = false; bool absolute = false;
if (request.params[3].isTrue()) if (request.params[3].isTrue())
@ -879,7 +879,7 @@ static RPCHelpMan getnodeaddresses()
NodeContext& node = EnsureAnyNodeContext(request.context); NodeContext& node = EnsureAnyNodeContext(request.context);
const CConnman& connman = EnsureConnman(node); const CConnman& connman = EnsureConnman(node);
const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()}; const int count{request.params[0].isNull() ? 1 : request.params[0].getInt<int>()};
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range"); if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}}; const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};

View file

@ -53,7 +53,7 @@ static RPCHelpMan setmocktime()
LOCK(cs_main); LOCK(cs_main);
RPCTypeCheck(request.params, {UniValue::VNUM}); RPCTypeCheck(request.params, {UniValue::VNUM});
const int64_t time{request.params[0].get_int64()}; const int64_t time{request.params[0].getInt<int64_t>()};
if (time < 0) { if (time < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time)); throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
} }
@ -108,7 +108,7 @@ static RPCHelpMan mockscheduler()
// check params are valid values // check params are valid values
RPCTypeCheck(request.params, {UniValue::VNUM}); RPCTypeCheck(request.params, {UniValue::VNUM});
int64_t delta_seconds = request.params[0].get_int64(); int64_t delta_seconds = request.params[0].getInt<int64_t>();
if (delta_seconds <= 0 || delta_seconds > 3600) { if (delta_seconds <= 0 || delta_seconds > 3600) {
throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)"); throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
} }

View file

@ -124,7 +124,7 @@ static RPCHelpMan createmultisig()
}, },
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{ {
int required = request.params[0].get_int(); int required = request.params[0].getInt<int>();
// Get the public keys // Get the public keys
const UniValue& keys = request.params[1].get_array(); const UniValue& keys = request.params[1].get_array();

View file

@ -225,7 +225,7 @@ static RPCHelpMan getrawtransaction()
// Accept either a bool (true) or a num (>=1) to indicate verbose output. // Accept either a bool (true) or a num (>=1) to indicate verbose output.
bool fVerbose = false; bool fVerbose = false;
if (!request.params[1].isNull()) { if (!request.params[1].isNull()) {
fVerbose = request.params[1].isNum() ? (request.params[1].get_int() != 0) : request.params[1].get_bool(); fVerbose = request.params[1].isNum() ? (request.params[1].getInt<int>() != 0) : request.params[1].get_bool();
} }
if (!request.params[2].isNull()) { if (!request.params[2].isNull()) {

View file

@ -40,7 +40,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
CMutableTransaction rawTx; CMutableTransaction rawTx;
if (!locktime.isNull()) { if (!locktime.isNull()) {
int64_t nLockTime = locktime.get_int64(); int64_t nLockTime = locktime.getInt<int64_t>();
if (nLockTime < 0 || nLockTime > LOCKTIME_MAX) if (nLockTime < 0 || nLockTime > LOCKTIME_MAX)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
rawTx.nLockTime = nLockTime; rawTx.nLockTime = nLockTime;
@ -55,7 +55,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
const UniValue& vout_v = find_value(o, "vout"); const UniValue& vout_v = find_value(o, "vout");
if (!vout_v.isNum()) if (!vout_v.isNum())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
int nOutput = vout_v.get_int(); int nOutput = vout_v.getInt<int>();
if (nOutput < 0) if (nOutput < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
@ -71,7 +71,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
// set the sequence number if passed in the parameters object // set the sequence number if passed in the parameters object
const UniValue& sequenceObj = find_value(o, "sequence"); const UniValue& sequenceObj = find_value(o, "sequence");
if (sequenceObj.isNum()) { if (sequenceObj.isNum()) {
int64_t seqNr64 = sequenceObj.get_int64(); int64_t seqNr64 = sequenceObj.getInt<int64_t>();
if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) { if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
} else { } else {
@ -177,7 +177,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst
uint256 txid = ParseHashO(prevOut, "txid"); uint256 txid = ParseHashO(prevOut, "txid");
int nOut = find_value(prevOut, "vout").get_int(); int nOut = find_value(prevOut, "vout").getInt<int>();
if (nOut < 0) { if (nOut < 0) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative");
} }

View file

@ -146,7 +146,7 @@ std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue& in)
if (!rec.isObject()) { if (!rec.isObject()) {
throw std::runtime_error("Batch member must be an object"); throw std::runtime_error("Batch member must be an object");
} }
size_t id = rec["id"].get_int(); size_t id = rec["id"].getInt<int>();
if (id >= num) { if (id >= num) {
throw std::runtime_error("Batch member id is larger than batch size"); throw std::runtime_error("Batch member id is larger than batch size");
} }

View file

@ -176,7 +176,7 @@ static RPCHelpMan stop()
// this reply will get back to the client. // this reply will get back to the client.
StartShutdown(); StartShutdown();
if (jsonRequest.params[0].isNum()) { if (jsonRequest.params[0].isNum()) {
UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].get_int()}); UninterruptibleSleep(std::chrono::milliseconds{jsonRequest.params[0].getInt<int>()});
} }
return RESULT; return RESULT;
}, },

View file

@ -337,7 +337,7 @@ UniValue DescribeAddress(const CTxDestination& dest)
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target) unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target)
{ {
const int target{value.get_int()}; const int target{value.getInt<int>()};
const unsigned int unsigned_target{static_cast<unsigned int>(target)}; const unsigned int unsigned_target{static_cast<unsigned int>(target)};
if (target < 1 || unsigned_target > max_target) { if (target < 1 || unsigned_target > max_target) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u and %u", 1, max_target)); throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u and %u", 1, max_target));
@ -1023,11 +1023,11 @@ std::string RPCArg::ToString(const bool oneline) const
static std::pair<int64_t, int64_t> ParseRange(const UniValue& value) static std::pair<int64_t, int64_t> ParseRange(const UniValue& value)
{ {
if (value.isNum()) { if (value.isNum()) {
return {0, value.get_int64()}; return {0, value.getInt<int64_t>()};
} }
if (value.isArray() && value.size() == 2 && value[0].isNum() && value[1].isNum()) { if (value.isArray() && value.size() == 2 && value[0].isNum() && value[1].isNum()) {
int64_t low = value[0].get_int64(); int64_t low = value[0].getInt<int64_t>();
int64_t high = value[1].get_int64(); int64_t high = value[1].getInt<int64_t>();
if (low > high) throw JSONRPCError(RPC_INVALID_PARAMETER, "Range specified as [begin,end] must not have begin after end"); if (low > high) throw JSONRPCError(RPC_INVALID_PARAMETER, "Range specified as [begin,end] must not have begin after end");
return {low, high}; return {low, high};
} }

View file

@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test)
} }
unsigned int pos = 0; unsigned int pos = 0;
/*int block_height =*/ test[pos++].get_int(); /*int block_height =*/ test[pos++].getInt<int>();
uint256 block_hash; uint256 block_hash;
BOOST_CHECK(ParseHashStr(test[pos++].get_str(), block_hash)); BOOST_CHECK(ParseHashStr(test[pos++].get_str(), block_hash));

View file

@ -149,7 +149,7 @@ void Test(const std::string& str)
CMutableTransaction tx = TxFromHex(test["tx"].get_str()); CMutableTransaction tx = TxFromHex(test["tx"].get_str());
const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]); const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]);
if (prevouts.size() != tx.vin.size()) throw std::runtime_error("Incorrect number of prevouts"); if (prevouts.size() != tx.vin.size()) throw std::runtime_error("Incorrect number of prevouts");
size_t idx = test["index"].get_int64(); size_t idx = test["index"].getInt<int64_t>();
if (idx >= tx.vin.size()) throw std::runtime_error("Invalid index"); if (idx >= tx.vin.size()) throw std::runtime_error("Invalid index");
unsigned int test_flags = ParseScriptFlags(test["flags"].get_str()); unsigned int test_flags = ParseScriptFlags(test["flags"].get_str());
bool final = test.exists("final") && test["final"].get_bool(); bool final = test.exists("final") && test["final"].get_bool();

View file

@ -66,9 +66,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
BOOST_CHECK_THROW(CallRPC("decoderawtransaction DEADBEEF"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("decoderawtransaction DEADBEEF"), std::runtime_error);
std::string rawtx = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"; std::string rawtx = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx)); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx));
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193); BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").getInt<int>(), 193);
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1); BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").getInt<int>(), 1);
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0); BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").getInt<int>(), 0);
BOOST_CHECK_THROW(CallRPC(std::string("decoderawtransaction ")+rawtx+" extra"), std::runtime_error); BOOST_CHECK_THROW(CallRPC(std::string("decoderawtransaction ")+rawtx+" extra"), std::runtime_error);
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false")); BOOST_CHECK_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false"));
BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false extra"), std::runtime_error); BOOST_CHECK_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false extra"), std::runtime_error);
@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(rpc_togglenetwork)
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false")); BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false"));
r = CallRPC("getnetworkinfo"); r = CallRPC("getnetworkinfo");
int numConnection = find_value(r.get_obj(), "connections").get_int(); int numConnection = find_value(r.get_obj(), "connections").getInt<int>();
BOOST_CHECK_EQUAL(numConnection, 0); BOOST_CHECK_EQUAL(numConnection, 0);
netState = find_value(r.get_obj(), "networkactive").get_bool(); netState = find_value(r.get_obj(), "networkactive").get_bool();
@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
ar = r.get_array(); ar = r.get_array();
o1 = ar[0].get_obj(); o1 = ar[0].get_obj();
adr = find_value(o1, "address"); adr = find_value(o1, "address");
int64_t banned_until{find_value(o1, "banned_until").get_int64()}; int64_t banned_until{find_value(o1, "banned_until").getInt<int64_t>()};
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24"); BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
BOOST_CHECK_EQUAL(banned_until, 9907731200); // absolute time check BOOST_CHECK_EQUAL(banned_until, 9907731200); // absolute time check
@ -279,10 +279,10 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
ar = r.get_array(); ar = r.get_array();
o1 = ar[0].get_obj(); o1 = ar[0].get_obj();
adr = find_value(o1, "address"); adr = find_value(o1, "address");
banned_until = find_value(o1, "banned_until").get_int64(); banned_until = find_value(o1, "banned_until").getInt<int64_t>();
const int64_t ban_created{find_value(o1, "ban_created").get_int64()}; const int64_t ban_created{find_value(o1, "ban_created").getInt<int64_t>()};
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()}; const int64_t ban_duration{find_value(o1, "ban_duration").getInt<int64_t>()};
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()}; const int64_t time_remaining{find_value(o1, "time_remaining").getInt<int64_t>()};
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24"); BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count()); BOOST_CHECK_EQUAL(banned_until, time_remaining_expected + now.count());
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created); BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
@ -337,22 +337,22 @@ BOOST_AUTO_TEST_CASE(rpc_convert_values_generatetoaddress)
UniValue result; UniValue result;
BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a"})); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a"}));
BOOST_CHECK_EQUAL(result[0].get_int(), 101); BOOST_CHECK_EQUAL(result[0].getInt<int>(), 101);
BOOST_CHECK_EQUAL(result[1].get_str(), "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a"); BOOST_CHECK_EQUAL(result[1].get_str(), "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a");
BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU"})); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"101", "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU"}));
BOOST_CHECK_EQUAL(result[0].get_int(), 101); BOOST_CHECK_EQUAL(result[0].getInt<int>(), 101);
BOOST_CHECK_EQUAL(result[1].get_str(), "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU"); BOOST_CHECK_EQUAL(result[1].get_str(), "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU");
BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a", "9"})); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a", "9"}));
BOOST_CHECK_EQUAL(result[0].get_int(), 1); BOOST_CHECK_EQUAL(result[0].getInt<int>(), 1);
BOOST_CHECK_EQUAL(result[1].get_str(), "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a"); BOOST_CHECK_EQUAL(result[1].get_str(), "mkESjLZW66TmHhiFX8MCaBjrhZ543PPh9a");
BOOST_CHECK_EQUAL(result[2].get_int(), 9); BOOST_CHECK_EQUAL(result[2].getInt<int>(), 9);
BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU", "9"})); BOOST_CHECK_NO_THROW(result = RPCConvertValues("generatetoaddress", {"1", "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU", "9"}));
BOOST_CHECK_EQUAL(result[0].get_int(), 1); BOOST_CHECK_EQUAL(result[0].getInt<int>(), 1);
BOOST_CHECK_EQUAL(result[1].get_str(), "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU"); BOOST_CHECK_EQUAL(result[1].get_str(), "mhMbmE2tE9xzJYCV9aNC8jKWN31vtGrguU");
BOOST_CHECK_EQUAL(result[2].get_int(), 9); BOOST_CHECK_EQUAL(result[2].getInt<int>(), 9);
} }
BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight) BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight)

View file

@ -406,8 +406,8 @@ BOOST_AUTO_TEST_CASE(bip341_spk_test_vectors)
if (node.isObject()) { if (node.isObject()) {
auto script_bytes = ParseHex(node["script"].get_str()); auto script_bytes = ParseHex(node["script"].get_str());
CScript script(script_bytes.begin(), script_bytes.end()); CScript script(script_bytes.begin(), script_bytes.end());
int idx = node["id"].get_int(); int idx = node["id"].getInt<int>();
int leaf_version = node["leafVersion"].get_int(); int leaf_version = node["leafVersion"].getInt<int>();
scriptposes[{script, leaf_version}] = idx; scriptposes[{script, leaf_version}] = idx;
spktest.Add(depth, script, leaf_version); spktest.Add(depth, script, leaf_version);
} else { } else {

View file

@ -1678,7 +1678,7 @@ static void AssetTest(const UniValue& test)
CMutableTransaction mtx = TxFromHex(test["tx"].get_str()); CMutableTransaction mtx = TxFromHex(test["tx"].get_str());
const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]); const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]);
BOOST_CHECK(prevouts.size() == mtx.vin.size()); BOOST_CHECK(prevouts.size() == mtx.vin.size());
size_t idx = test["index"].get_int64(); size_t idx = test["index"].getInt<int64_t>();
uint32_t test_flags{ParseScriptFlags(test["flags"].get_str())}; uint32_t test_flags{ParseScriptFlags(test["flags"].get_str())};
bool fin = test.exists("final") && test["final"].get_bool(); bool fin = test.exists("final") && test["final"].get_bool();
@ -1760,7 +1760,7 @@ BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors)
for (const auto& utxo_spent : vec["given"]["utxosSpent"].getValues()) { for (const auto& utxo_spent : vec["given"]["utxosSpent"].getValues()) {
auto script_bytes = ParseHex(utxo_spent["scriptPubKey"].get_str()); auto script_bytes = ParseHex(utxo_spent["scriptPubKey"].get_str());
CScript script{script_bytes.begin(), script_bytes.end()}; CScript script{script_bytes.begin(), script_bytes.end()};
CAmount amount{utxo_spent["amountSats"].get_int()}; CAmount amount{utxo_spent["amountSats"].getInt<int>()};
utxos.emplace_back(amount, script); utxos.emplace_back(amount, script);
} }
@ -1775,8 +1775,8 @@ BOOST_AUTO_TEST_CASE(bip341_keypath_test_vectors)
BOOST_CHECK_EQUAL(HexStr(txdata.m_sequences_single_hash), vec["intermediary"]["hashSequences"].get_str()); BOOST_CHECK_EQUAL(HexStr(txdata.m_sequences_single_hash), vec["intermediary"]["hashSequences"].get_str());
for (const auto& input : vec["inputSpending"].getValues()) { for (const auto& input : vec["inputSpending"].getValues()) {
int txinpos = input["given"]["txinIndex"].get_int(); int txinpos = input["given"]["txinIndex"].getInt<int>();
int hashtype = input["given"]["hashType"].get_int(); int hashtype = input["given"]["hashType"].getInt<int>();
// Load key. // Load key.
auto privkey = ParseHex(input["given"]["internalPrivkey"].get_str()); auto privkey = ParseHex(input["given"]["internalPrivkey"].get_str());

View file

@ -184,8 +184,8 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
// deserialize test data // deserialize test data
raw_tx = test[0].get_str(); raw_tx = test[0].get_str();
raw_script = test[1].get_str(); raw_script = test[1].get_str();
nIn = test[2].get_int(); nIn = test[2].getInt<int>();
nHashType = test[3].get_int(); nHashType = test[3].getInt<int>();
sigHashHex = test[4].get_str(); sigHashHex = test[4].get_str();
CDataStream stream(ParseHex(raw_tx), SER_NETWORK, PROTOCOL_VERSION); CDataStream stream(ParseHex(raw_tx), SER_NETWORK, PROTOCOL_VERSION);

View file

@ -217,11 +217,11 @@ BOOST_AUTO_TEST_CASE(tx_valid)
fValid = false; fValid = false;
break; break;
} }
COutPoint outpoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].get_int())}; COutPoint outpoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].getInt<int>())};
mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str()); mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str());
if (vinput.size() >= 4) if (vinput.size() >= 4)
{ {
mapprevOutValues[outpoint] = vinput[3].get_int64(); mapprevOutValues[outpoint] = vinput[3].getInt<int64_t>();
} }
} }
if (!fValid) if (!fValid)
@ -305,11 +305,11 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
fValid = false; fValid = false;
break; break;
} }
COutPoint outpoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].get_int())}; COutPoint outpoint{uint256S(vinput[0].get_str()), uint32_t(vinput[1].getInt<int>())};
mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str()); mapprevOutScriptPubKeys[outpoint] = ParseScript(vinput[2].get_str());
if (vinput.size() >= 4) if (vinput.size() >= 4)
{ {
mapprevOutValues[outpoint] = vinput[3].get_int64(); mapprevOutValues[outpoint] = vinput[3].getInt<int64_t>();
} }
} }
if (!fValid) if (!fValid)

View file

@ -20,7 +20,7 @@ namespace util {
//! @note UniValue is used here for convenience and because it can be easily //! @note UniValue is used here for convenience and because it can be easily
//! serialized in a readable format. But any other variant type that can //! serialized in a readable format. But any other variant type that can
//! be assigned strings, int64_t, and bool values and has get_str(), //! be assigned strings, int64_t, and bool values and has get_str(),
//! get_int64(), get_bool(), isNum(), isBool(), isFalse(), isTrue() and //! getInt<int64_t>(), get_bool(), isNum(), isBool(), isFalse(), isTrue() and
//! isNull() methods can be substituted if there's a need to move away //! isNull() methods can be substituted if there's a need to move away
//! from UniValue. (An implementation with boost::variant was posted at //! from UniValue. (An implementation with boost::variant was posted at
//! https://github.com/bitcoin/bitcoin/pull/15934/files#r337691812) //! https://github.com/bitcoin/bitcoin/pull/15934/files#r337691812)

View file

@ -606,7 +606,7 @@ std::string ArgsManager::GetArg(const std::string& strArg, const std::string& st
int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const int64_t ArgsManager::GetIntArg(const std::string& strArg, int64_t nDefault) const
{ {
const util::SettingsValue value = GetSetting(strArg); const util::SettingsValue value = GetSetting(strArg);
return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.get_int64() : LocaleIndependentAtoi<int64_t>(value.get_str()); return value.isNull() ? nDefault : value.isFalse() ? 0 : value.isTrue() ? 1 : value.isNum() ? value.getInt<int64_t>() : LocaleIndependentAtoi<int64_t>(value.get_str());
} }
bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const bool ArgsManager::GetBoolArg(const std::string& strArg, bool fDefault) const

View file

@ -264,7 +264,7 @@ RPCHelpMan addmultisigaddress()
if (!request.params[2].isNull()) if (!request.params[2].isNull())
label = LabelFromValue(request.params[2]); label = LabelFromValue(request.params[2]);
int required = request.params[0].get_int(); int required = request.params[0].getInt<int>();
// Get the public keys // Get the public keys
const UniValue& keys_or_addrs = request.params[1].get_array(); const UniValue& keys_or_addrs = request.params[1].get_array();
@ -340,9 +340,9 @@ RPCHelpMan keypoolrefill()
// 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool // 0 is interpreted by TopUpKeyPool() as the default keypool size given by -keypool
unsigned int kpSize = 0; unsigned int kpSize = 0;
if (!request.params[0].isNull()) { if (!request.params[0].isNull()) {
if (request.params[0].get_int() < 0) if (request.params[0].getInt<int>() < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size."); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected valid size.");
kpSize = (unsigned int)request.params[0].get_int(); kpSize = (unsigned int)request.params[0].getInt<int>();
} }
EnsureWalletIsUnlocked(*pwallet); EnsureWalletIsUnlocked(*pwallet);

View file

@ -1232,7 +1232,7 @@ static int64_t GetImportTimestamp(const UniValue& data, int64_t now)
if (data.exists("timestamp")) { if (data.exists("timestamp")) {
const UniValue& timestamp = data["timestamp"]; const UniValue& timestamp = data["timestamp"];
if (timestamp.isNum()) { if (timestamp.isNum()) {
return timestamp.get_int64(); return timestamp.getInt<int64_t>();
} else if (timestamp.isStr() && timestamp.get_str() == "now") { } else if (timestamp.isStr() && timestamp.get_str() == "now") {
return now; return now;
} }
@ -1473,7 +1473,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
next_index = range_start; next_index = range_start;
if (data.exists("next_index")) { if (data.exists("next_index")) {
next_index = data["next_index"].get_int64(); next_index = data["next_index"].getInt<int64_t>();
// bound checks // bound checks
if (next_index < range_start || next_index >= range_end) { if (next_index < range_start || next_index >= range_end) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "next_index is out of range"); throw JSONRPCError(RPC_INVALID_PARAMETER, "next_index is out of range");

View file

@ -45,7 +45,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
// Minimum confirmations // Minimum confirmations
int min_depth = 1; int min_depth = 1;
if (!params[1].isNull()) if (!params[1].isNull())
min_depth = params[1].get_int(); min_depth = params[1].getInt<int>();
const bool include_immature_coinbase{params[2].isNull() ? false : params[2].get_bool()}; const bool include_immature_coinbase{params[2].isNull() ? false : params[2].get_bool()};
@ -204,7 +204,7 @@ RPCHelpMan getbalance()
int min_depth = 0; int min_depth = 0;
if (!request.params[1].isNull()) { if (!request.params[1].isNull()) {
min_depth = request.params[1].get_int(); min_depth = request.params[1].getInt<int>();
} }
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet); bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
@ -328,7 +328,7 @@ RPCHelpMan lockunspent()
}); });
const uint256 txid(ParseHashO(o, "txid")); const uint256 txid(ParseHashO(o, "txid"));
const int nOutput = find_value(o, "vout").get_int(); const int nOutput = find_value(o, "vout").getInt<int>();
if (nOutput < 0) { if (nOutput < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
} }
@ -569,13 +569,13 @@ RPCHelpMan listunspent()
int nMinDepth = 1; int nMinDepth = 1;
if (!request.params[0].isNull()) { if (!request.params[0].isNull()) {
RPCTypeCheckArgument(request.params[0], UniValue::VNUM); RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
nMinDepth = request.params[0].get_int(); nMinDepth = request.params[0].getInt<int>();
} }
int nMaxDepth = 9999999; int nMaxDepth = 9999999;
if (!request.params[1].isNull()) { if (!request.params[1].isNull()) {
RPCTypeCheckArgument(request.params[1], UniValue::VNUM); RPCTypeCheckArgument(request.params[1], UniValue::VNUM);
nMaxDepth = request.params[1].get_int(); nMaxDepth = request.params[1].getInt<int>();
} }
std::set<CTxDestination> destinations; std::set<CTxDestination> destinations;
@ -627,7 +627,7 @@ RPCHelpMan listunspent()
nMinimumSumAmount = AmountFromValue(options["minimumSumAmount"]); nMinimumSumAmount = AmountFromValue(options["minimumSumAmount"]);
if (options.exists("maximumCount")) if (options.exists("maximumCount"))
nMaximumCount = options["maximumCount"].get_int64(); nMaximumCount = options["maximumCount"].getInt<int64_t>();
} }
// Make sure the results are valid at least up to the most recent block // Make sure the results are valid at least up to the most recent block

View file

@ -54,7 +54,7 @@ RPCHelpMan walletpassphrase()
strWalletPass = request.params[0].get_str().c_str(); strWalletPass = request.params[0].get_str().c_str();
// Get the timeout // Get the timeout
nSleepTime = request.params[1].get_int64(); nSleepTime = request.params[1].getInt<int64_t>();
// Timeout cannot be negative, otherwise it will relock immediately // Timeout cannot be negative, otherwise it will relock immediately
if (nSleepTime < 0) { if (nSleepTime < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative."); throw JSONRPCError(RPC_INVALID_PARAMETER, "Timeout cannot be negative.");

View file

@ -551,7 +551,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
} }
if (options.exists("changePosition") || options.exists("change_position")) { if (options.exists("changePosition") || options.exists("change_position")) {
change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).get_int(); change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).getInt<int>();
} }
if (options.exists("change_type")) { if (options.exists("change_type")) {
@ -659,7 +659,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
if (!vout_v.isNum()) { if (!vout_v.isNum()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
} }
int vout = vout_v.get_int(); int vout = vout_v.getInt<int>();
if (vout < 0) { if (vout < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
} }
@ -668,7 +668,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
if (!weight_v.isNum()) { if (!weight_v.isNum()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing weight key"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing weight key");
} }
int64_t weight = weight_v.get_int64(); int64_t weight = weight_v.getInt<int64_t>();
const int64_t min_input_weight = GetTransactionInputWeight(CTxIn()); const int64_t min_input_weight = GetTransactionInputWeight(CTxIn());
CHECK_NONFATAL(min_input_weight == 165); CHECK_NONFATAL(min_input_weight == 165);
if (weight < min_input_weight) { if (weight < min_input_weight) {
@ -689,7 +689,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds"); throw JSONRPCError(RPC_INVALID_PARAMETER, "changePosition out of bounds");
for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) { for (unsigned int idx = 0; idx < subtractFeeFromOutputs.size(); idx++) {
int pos = subtractFeeFromOutputs[idx].get_int(); int pos = subtractFeeFromOutputs[idx].getInt<int>();
if (setSubtractFeeFromOutputs.count(pos)) if (setSubtractFeeFromOutputs.count(pos))
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos)); throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid parameter, duplicated position: %d", pos));
if (pos < 0) if (pos < 0)

View file

@ -74,7 +74,7 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
// Minimum confirmations // Minimum confirmations
int nMinDepth = 1; int nMinDepth = 1;
if (!params[0].isNull()) if (!params[0].isNull())
nMinDepth = params[0].get_int(); nMinDepth = params[0].getInt<int>();
// Whether to include empty labels // Whether to include empty labels
bool fIncludeEmpty = false; bool fIncludeEmpty = false;
@ -514,10 +514,10 @@ RPCHelpMan listtransactions()
} }
int nCount = 10; int nCount = 10;
if (!request.params[1].isNull()) if (!request.params[1].isNull())
nCount = request.params[1].get_int(); nCount = request.params[1].getInt<int>();
int nFrom = 0; int nFrom = 0;
if (!request.params[2].isNull()) if (!request.params[2].isNull())
nFrom = request.params[2].get_int(); nFrom = request.params[2].getInt<int>();
isminefilter filter = ISMINE_SPENDABLE; isminefilter filter = ISMINE_SPENDABLE;
if (ParseIncludeWatchonly(request.params[3], *pwallet)) { if (ParseIncludeWatchonly(request.params[3], *pwallet)) {
@ -640,7 +640,7 @@ RPCHelpMan listsinceblock()
} }
if (!request.params[1].isNull()) { if (!request.params[1].isNull()) {
target_confirms = request.params[1].get_int(); target_confirms = request.params[1].getInt<int>();
if (target_confirms < 1) { if (target_confirms < 1) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
@ -894,14 +894,14 @@ RPCHelpMan rescanblockchain()
int tip_height = pwallet->GetLastBlockHeight(); int tip_height = pwallet->GetLastBlockHeight();
if (!request.params[0].isNull()) { if (!request.params[0].isNull()) {
start_height = request.params[0].get_int(); start_height = request.params[0].getInt<int>();
if (start_height < 0 || start_height > tip_height) { if (start_height < 0 || start_height > tip_height) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid start_height");
} }
} }
if (!request.params[1].isNull()) { if (!request.params[1].isNull()) {
stop_height = request.params[1].get_int(); stop_height = request.params[1].getInt<int>();
if (*stop_height < 0 || *stop_height > tip_height) { if (*stop_height < 0 || *stop_height > tip_height) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid stop_height"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid stop_height");
} else if (*stop_height < start_height) { } else if (*stop_height < start_height) {

View file

@ -559,7 +559,7 @@ static RPCHelpMan upgradewallet()
int version = 0; int version = 0;
if (!request.params[0].isNull()) { if (!request.params[0].isNull()) {
version = request.params[0].get_int(); version = request.params[0].getInt<int>();
} }
bilingual_str error; bilingual_str error;
const int previous_version{pwallet->GetVersion()}; const int previous_version{pwallet->GetVersion()};