Skip to content

Commit fa9af21

Browse files
author
MacroFake
committed
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-
1 parent e016c00 commit fa9af21

32 files changed

+114
-114
lines changed

src/bitcoin-cli.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
467467
if (!batch[ID_NETWORKINFO]["error"].isNull()) return batch[ID_NETWORKINFO];
468468

469469
const UniValue& networkinfo{batch[ID_NETWORKINFO]["result"]};
470-
if (networkinfo["version"].get_int() < 209900) {
470+
if (networkinfo["version"].getInt<int>() < 209900) {
471471
throw std::runtime_error("-netinfo requires bitcoind server to be running v0.21.0 and up");
472472
}
473473
const int64_t time_now{count_seconds(Now<CliSeconds>())};
@@ -488,16 +488,16 @@ class NetinfoRequestHandler : public BaseRequestHandler
488488
if (conn_type == "manual") ++m_manual_peers_count;
489489
if (DetailsRequested()) {
490490
// Push data for this peer to the peers vector.
491-
const int peer_id{peer["id"].get_int()};
492-
const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].get_int()};
493-
const int version{peer["version"].get_int()};
494-
const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].get_int64()};
495-
const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].get_int64()};
496-
const int64_t conn_time{peer["conntime"].get_int64()};
497-
const int64_t last_blck{peer["last_block"].get_int64()};
498-
const int64_t last_recv{peer["lastrecv"].get_int64()};
499-
const int64_t last_send{peer["lastsend"].get_int64()};
500-
const int64_t last_trxn{peer["last_transaction"].get_int64()};
491+
const int peer_id{peer["id"].getInt<int>()};
492+
const int mapped_as{peer["mapped_as"].isNull() ? 0 : peer["mapped_as"].getInt<int>()};
493+
const int version{peer["version"].getInt<int>()};
494+
const int64_t addr_processed{peer["addr_processed"].isNull() ? 0 : peer["addr_processed"].getInt<int64_t>()};
495+
const int64_t addr_rate_limited{peer["addr_rate_limited"].isNull() ? 0 : peer["addr_rate_limited"].getInt<int64_t>()};
496+
const int64_t conn_time{peer["conntime"].getInt<int64_t>()};
497+
const int64_t last_blck{peer["last_block"].getInt<int64_t>()};
498+
const int64_t last_recv{peer["lastrecv"].getInt<int64_t>()};
499+
const int64_t last_send{peer["lastsend"].getInt<int64_t>()};
500+
const int64_t last_trxn{peer["last_transaction"].getInt<int64_t>()};
501501
const double min_ping{peer["minping"].isNull() ? -1 : peer["minping"].get_real()};
502502
const double ping{peer["pingtime"].isNull() ? -1 : peer["pingtime"].get_real()};
503503
const std::string addr{peer["addr"].get_str()};
@@ -517,7 +517,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
517517
}
518518

519519
// Generate report header.
520-
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())};
520+
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())};
521521

522522
// Report detailed peer connections list sorted by direction and minimum ping time.
523523
if (DetailsRequested() && !m_peers.empty()) {
@@ -598,7 +598,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
598598
max_addr_size = std::max(addr["address"].get_str().length() + 1, max_addr_size);
599599
}
600600
for (const UniValue& addr : local_addrs) {
601-
result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].get_int(), addr["score"].get_int());
601+
result += strprintf("\n%-*s port %6i score %6i", max_addr_size, addr["address"].get_str(), addr["port"].getInt<int>(), addr["score"].getInt<int>());
602602
}
603603
}
604604

@@ -851,7 +851,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
851851
response = CallRPC(rh, strMethod, args, rpcwallet);
852852
if (fWait) {
853853
const UniValue& error = find_value(response, "error");
854-
if (!error.isNull() && error["code"].get_int() == RPC_IN_WARMUP) {
854+
if (!error.isNull() && error["code"].getInt<int>() == RPC_IN_WARMUP) {
855855
throw CConnectionFailed("server in warmup");
856856
}
857857
}
@@ -886,13 +886,13 @@ static void ParseError(const UniValue& error, std::string& strPrint, int& nRet)
886886
if (err_msg.isStr()) {
887887
strPrint += ("error message:\n" + err_msg.get_str());
888888
}
889-
if (err_code.isNum() && err_code.get_int() == RPC_WALLET_NOT_SPECIFIED) {
889+
if (err_code.isNum() && err_code.getInt<int>() == RPC_WALLET_NOT_SPECIFIED) {
890890
strPrint += "\nTry adding \"-rpcwallet=<filename>\" option to bitcoin-cli command line.";
891891
}
892892
} else {
893893
strPrint = "error: " + error.write();
894894
}
895-
nRet = abs(error["code"].get_int());
895+
nRet = abs(error["code"].getInt<int>());
896896
}
897897

898898
/**

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
612612
throw std::runtime_error("txid must be hexadecimal string (not '" + prevOut["txid"].get_str() + "')");
613613
}
614614

615-
const int nOut = prevOut["vout"].get_int();
615+
const int nOut = prevOut["vout"].getInt<int>();
616616
if (nOut < 0)
617617
throw std::runtime_error("vout cannot be negative");
618618

src/httprpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const Uni
7575
{
7676
// Send error reply from json-rpc error object
7777
int nStatus = HTTP_INTERNAL_SERVER_ERROR;
78-
int code = find_value(objError, "code").get_int();
78+
int code = find_value(objError, "code").getInt<int>();
7979

8080
if (code == RPC_INVALID_REQUEST)
8181
nStatus = HTTP_BAD_REQUEST;

src/net_types.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
static const char* BANMAN_JSON_VERSION_KEY{"version"};
1313

1414
CBanEntry::CBanEntry(const UniValue& json)
15-
: nVersion(json[BANMAN_JSON_VERSION_KEY].get_int()),
16-
nCreateTime(json["ban_created"].get_int64()),
17-
nBanUntil(json["banned_until"].get_int64())
15+
: nVersion(json[BANMAN_JSON_VERSION_KEY].getInt<int>()),
16+
nCreateTime(json["ban_created"].getInt<int64_t>()),
17+
nBanUntil(json["banned_until"].getInt<int64_t>())
1818
{
1919
}
2020

@@ -58,7 +58,7 @@ UniValue BanMapToJson(const banmap_t& bans)
5858
void BanMapFromJson(const UniValue& bans_json, banmap_t& bans)
5959
{
6060
for (const auto& ban_entry_json : bans_json.getValues()) {
61-
const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].get_int()};
61+
const int version{ban_entry_json[BANMAN_JSON_VERSION_KEY].getInt<int>()};
6262
if (version != CBanEntry::CURRENT_VERSION) {
6363
LogPrintf("Dropping entry with unknown version (%s) from ban list\n", version);
6464
continue;

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class RpcHandlerImpl : public Handler
426426
// try to handle the request. Otherwise, reraise the exception.
427427
if (!last_handler) {
428428
const UniValue& code = e["code"];
429-
if (code.isNum() && code.get_int() == RPC_WALLET_NOT_FOUND) {
429+
if (code.isNum() && code.getInt<int>() == RPC_WALLET_NOT_FOUND) {
430430
return false;
431431
}
432432
}

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ void RPCExecutor::request(const QString &command, const WalletModel* wallet_mode
457457
{
458458
try // Nice formatting for standard-format error
459459
{
460-
int code = find_value(objError, "code").get_int();
460+
int code = find_value(objError, "code").getInt<int>();
461461
std::string message = find_value(objError, "message").get_str();
462462
Q_EMIT reply(RPCConsole::CMD_ERROR, QString::fromStdString(message) + " (code " + QString::number(code) + ")");
463463
}

src/rpc/blockchain.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateMan
110110
CChain& active_chain = chainman.ActiveChain();
111111

112112
if (param.isNum()) {
113-
const int height{param.get_int()};
113+
const int height{param.getInt<int>()};
114114
if (height < 0) {
115115
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d is negative", height));
116116
}
@@ -271,7 +271,7 @@ static RPCHelpMan waitfornewblock()
271271
{
272272
int timeout = 0;
273273
if (!request.params[0].isNull())
274-
timeout = request.params[0].get_int();
274+
timeout = request.params[0].getInt<int>();
275275

276276
CUpdatedBlock block;
277277
{
@@ -317,7 +317,7 @@ static RPCHelpMan waitforblock()
317317
uint256 hash(ParseHashV(request.params[0], "blockhash"));
318318

319319
if (!request.params[1].isNull())
320-
timeout = request.params[1].get_int();
320+
timeout = request.params[1].getInt<int>();
321321

322322
CUpdatedBlock block;
323323
{
@@ -361,10 +361,10 @@ static RPCHelpMan waitforblockheight()
361361
{
362362
int timeout = 0;
363363

364-
int height = request.params[0].get_int();
364+
int height = request.params[0].getInt<int>();
365365

366366
if (!request.params[1].isNull())
367-
timeout = request.params[1].get_int();
367+
timeout = request.params[1].getInt<int>();
368368

369369
CUpdatedBlock block;
370370
{
@@ -445,7 +445,7 @@ static RPCHelpMan getblockfrompeer()
445445
PeerManager& peerman = EnsurePeerman(node);
446446

447447
const uint256& block_hash{ParseHashV(request.params[0], "blockhash")};
448-
const NodeId peer_id{request.params[1].get_int64()};
448+
const NodeId peer_id{request.params[1].getInt<int64_t>()};
449449

450450
const CBlockIndex* const index = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(block_hash););
451451

@@ -485,7 +485,7 @@ static RPCHelpMan getblockhash()
485485
LOCK(cs_main);
486486
const CChain& active_chain = chainman.ActiveChain();
487487

488-
int nHeight = request.params[0].get_int();
488+
int nHeight = request.params[0].getInt<int>();
489489
if (nHeight < 0 || nHeight > active_chain.Height())
490490
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
491491

@@ -694,7 +694,7 @@ static RPCHelpMan getblock()
694694
if (request.params[1].isBool()) {
695695
verbosity = request.params[1].get_bool() ? 1 : 0;
696696
} else {
697-
verbosity = request.params[1].get_int();
697+
verbosity = request.params[1].getInt<int>();
698698
}
699699
}
700700

@@ -759,7 +759,7 @@ static RPCHelpMan pruneblockchain()
759759
CChainState& active_chainstate = chainman.ActiveChainstate();
760760
CChain& active_chain = active_chainstate.m_chain;
761761

762-
int heightParam = request.params[0].get_int();
762+
int heightParam = request.params[0].getInt<int>();
763763
if (heightParam < 0) {
764764
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
765765
}
@@ -1050,8 +1050,8 @@ static RPCHelpMan verifychain()
10501050
},
10511051
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
10521052
{
1053-
const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].get_int()};
1054-
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()};
1053+
const int check_level{request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].getInt<int>()};
1054+
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].getInt<int>()};
10551055

10561056
ChainstateManager& chainman = EnsureAnyChainman(request.context);
10571057
LOCK(cs_main);
@@ -1585,7 +1585,7 @@ static RPCHelpMan getchaintxstats()
15851585
if (request.params[0].isNull()) {
15861586
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1));
15871587
} else {
1588-
blockcount = request.params[0].get_int();
1588+
blockcount = request.params[0].getInt<int>();
15891589

15901590
if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) {
15911591
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 0 and the block's height - 1");

src/rpc/mining.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static RPCHelpMan getnetworkhashps()
109109
{
110110
ChainstateManager& chainman = EnsureAnyChainman(request.context);
111111
LOCK(cs_main);
112-
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, chainman.ActiveChain());
112+
return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].getInt<int>() : 120, !request.params[1].isNull() ? request.params[1].getInt<int>() : -1, chainman.ActiveChain());
113113
},
114114
};
115115
}
@@ -217,8 +217,8 @@ static RPCHelpMan generatetodescriptor()
217217
"\nGenerate 11 blocks to mydesc\n" + HelpExampleCli("generatetodescriptor", "11 \"mydesc\"")},
218218
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
219219
{
220-
const int num_blocks{request.params[0].get_int()};
221-
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
220+
const int num_blocks{request.params[0].getInt<int>()};
221+
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
222222

223223
CScript coinbase_script;
224224
std::string error;
@@ -264,8 +264,8 @@ static RPCHelpMan generatetoaddress()
264264
},
265265
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
266266
{
267-
const int num_blocks{request.params[0].get_int()};
268-
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
267+
const int num_blocks{request.params[0].getInt<int>()};
268+
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].getInt<int>()};
269269

270270
CTxDestination destination = DecodeDestination(request.params[1].get_str());
271271
if (!IsValidDestination(destination)) {
@@ -462,7 +462,7 @@ static RPCHelpMan prioritisetransaction()
462462
LOCK(cs_main);
463463

464464
uint256 hash(ParseHashV(request.params[0], "txid"));
465-
CAmount nAmount = request.params[2].get_int64();
465+
CAmount nAmount = request.params[2].getInt<int64_t>();
466466

467467
if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) {
468468
throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.");
@@ -657,7 +657,7 @@ static RPCHelpMan getblocktemplate()
657657
// NOTE: It is important that this NOT be read if versionbits is supported
658658
const UniValue& uvMaxVersion = find_value(oparam, "maxversion");
659659
if (uvMaxVersion.isNum()) {
660-
nMaxVersionPreVB = uvMaxVersion.get_int64();
660+
nMaxVersionPreVB = uvMaxVersion.getInt<int64_t>();
661661
}
662662
}
663663
}

src/rpc/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static RPCHelpMan disconnectnode()
412412
success = connman.DisconnectNode(address_arg.get_str());
413413
} else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
414414
/* handle disconnect-by-id */
415-
NodeId nodeid = (NodeId) id_arg.get_int64();
415+
NodeId nodeid = (NodeId) id_arg.getInt<int64_t>();
416416
success = connman.DisconnectNode(nodeid);
417417
} else {
418418
throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
@@ -720,7 +720,7 @@ static RPCHelpMan setban()
720720

721721
int64_t banTime = 0; //use standard bantime if not specified
722722
if (!request.params[2].isNull())
723-
banTime = request.params[2].get_int64();
723+
banTime = request.params[2].getInt<int64_t>();
724724

725725
bool absolute = false;
726726
if (request.params[3].isTrue())
@@ -879,7 +879,7 @@ static RPCHelpMan getnodeaddresses()
879879
NodeContext& node = EnsureAnyNodeContext(request.context);
880880
const CConnman& connman = EnsureConnman(node);
881881

882-
const int count{request.params[0].isNull() ? 1 : request.params[0].get_int()};
882+
const int count{request.params[0].isNull() ? 1 : request.params[0].getInt<int>()};
883883
if (count < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Address count out of range");
884884

885885
const std::optional<Network> network{request.params[1].isNull() ? std::nullopt : std::optional<Network>{ParseNetwork(request.params[1].get_str())}};

src/rpc/node.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static RPCHelpMan setmocktime()
5353
LOCK(cs_main);
5454

5555
RPCTypeCheck(request.params, {UniValue::VNUM});
56-
const int64_t time{request.params[0].get_int64()};
56+
const int64_t time{request.params[0].getInt<int64_t>()};
5757
if (time < 0) {
5858
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Mocktime cannot be negative: %s.", time));
5959
}
@@ -108,7 +108,7 @@ static RPCHelpMan mockscheduler()
108108

109109
// check params are valid values
110110
RPCTypeCheck(request.params, {UniValue::VNUM});
111-
int64_t delta_seconds = request.params[0].get_int64();
111+
int64_t delta_seconds = request.params[0].getInt<int64_t>();
112112
if (delta_seconds <= 0 || delta_seconds > 3600) {
113113
throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)");
114114
}

0 commit comments

Comments
 (0)