mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 17:24:58 +02:00
Merge bitcoin/bitcoin#25153: scripted-diff: Use getInt<T> over get_int/get_int64
fa9af21878scripted-diff: Use getInt<T> over get_int/get_int64 (MacroFake) Pull request description: Seems better to see the return type directly and be able to modify it easier, as the return type is used for exceptions (in-range checking and parsing feedback). ACKs for top commit: fanquake: ACKfa9af21878Tree-SHA512: 284aa2527d0f663ca01550115025c9c64c787531d595f866c718f6ad09b9b0cac1e683a7d77f8009b75de990fd37166b44063ffa83fba8a04e9a31600b4c2725
This commit is contained in:
@@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(blockfilters_json_test)
|
||||
}
|
||||
|
||||
unsigned int pos = 0;
|
||||
/*int block_height =*/ test[pos++].get_int();
|
||||
/*int block_height =*/ test[pos++].getInt<int>();
|
||||
uint256 block_hash;
|
||||
BOOST_CHECK(ParseHashStr(test[pos++].get_str(), block_hash));
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ void Test(const std::string& str)
|
||||
CMutableTransaction tx = TxFromHex(test["tx"].get_str());
|
||||
const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["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");
|
||||
unsigned int test_flags = ParseScriptFlags(test["flags"].get_str());
|
||||
bool final = test.exists("final") && test["final"].get_bool();
|
||||
|
||||
@@ -66,9 +66,9 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
|
||||
BOOST_CHECK_THROW(CallRPC("decoderawtransaction DEADBEEF"), std::runtime_error);
|
||||
std::string rawtx = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
|
||||
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(), "version").get_int(), 1);
|
||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0);
|
||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").getInt<int>(), 193);
|
||||
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").getInt<int>(), 1);
|
||||
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_NO_THROW(r = CallRPC(std::string("decoderawtransaction ")+rawtx+" false"));
|
||||
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"));
|
||||
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);
|
||||
|
||||
netState = find_value(r.get_obj(), "networkactive").get_bool();
|
||||
@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
|
||||
ar = r.get_array();
|
||||
o1 = ar[0].get_obj();
|
||||
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(banned_until, 9907731200); // absolute time check
|
||||
|
||||
@@ -279,10 +279,10 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
|
||||
ar = r.get_array();
|
||||
o1 = ar[0].get_obj();
|
||||
adr = find_value(o1, "address");
|
||||
banned_until = find_value(o1, "banned_until").get_int64();
|
||||
const int64_t ban_created{find_value(o1, "ban_created").get_int64()};
|
||||
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()};
|
||||
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()};
|
||||
banned_until = find_value(o1, "banned_until").getInt<int64_t>();
|
||||
const int64_t ban_created{find_value(o1, "ban_created").getInt<int64_t>()};
|
||||
const int64_t ban_duration{find_value(o1, "ban_duration").getInt<int64_t>()};
|
||||
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(banned_until, time_remaining_expected + now.count());
|
||||
BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
|
||||
@@ -337,22 +337,22 @@ BOOST_AUTO_TEST_CASE(rpc_convert_values_generatetoaddress)
|
||||
UniValue result;
|
||||
|
||||
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_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_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[2].get_int(), 9);
|
||||
BOOST_CHECK_EQUAL(result[2].getInt<int>(), 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[2].get_int(), 9);
|
||||
BOOST_CHECK_EQUAL(result[2].getInt<int>(), 9);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rpc_getblockstats_calculate_percentiles_by_weight)
|
||||
|
||||
@@ -406,8 +406,8 @@ BOOST_AUTO_TEST_CASE(bip341_spk_test_vectors)
|
||||
if (node.isObject()) {
|
||||
auto script_bytes = ParseHex(node["script"].get_str());
|
||||
CScript script(script_bytes.begin(), script_bytes.end());
|
||||
int idx = node["id"].get_int();
|
||||
int leaf_version = node["leafVersion"].get_int();
|
||||
int idx = node["id"].getInt<int>();
|
||||
int leaf_version = node["leafVersion"].getInt<int>();
|
||||
scriptposes[{script, leaf_version}] = idx;
|
||||
spktest.Add(depth, script, leaf_version);
|
||||
} else {
|
||||
|
||||
@@ -1678,7 +1678,7 @@ static void AssetTest(const UniValue& test)
|
||||
CMutableTransaction mtx = TxFromHex(test["tx"].get_str());
|
||||
const std::vector<CTxOut> prevouts = TxOutsFromJSON(test["prevouts"]);
|
||||
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())};
|
||||
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()) {
|
||||
auto script_bytes = ParseHex(utxo_spent["scriptPubKey"].get_str());
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
for (const auto& input : vec["inputSpending"].getValues()) {
|
||||
int txinpos = input["given"]["txinIndex"].get_int();
|
||||
int hashtype = input["given"]["hashType"].get_int();
|
||||
int txinpos = input["given"]["txinIndex"].getInt<int>();
|
||||
int hashtype = input["given"]["hashType"].getInt<int>();
|
||||
|
||||
// Load key.
|
||||
auto privkey = ParseHex(input["given"]["internalPrivkey"].get_str());
|
||||
|
||||
@@ -184,8 +184,8 @@ BOOST_AUTO_TEST_CASE(sighash_from_data)
|
||||
// deserialize test data
|
||||
raw_tx = test[0].get_str();
|
||||
raw_script = test[1].get_str();
|
||||
nIn = test[2].get_int();
|
||||
nHashType = test[3].get_int();
|
||||
nIn = test[2].getInt<int>();
|
||||
nHashType = test[3].getInt<int>();
|
||||
sigHashHex = test[4].get_str();
|
||||
|
||||
CDataStream stream(ParseHex(raw_tx), SER_NETWORK, PROTOCOL_VERSION);
|
||||
|
||||
@@ -217,11 +217,11 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
||||
fValid = false;
|
||||
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());
|
||||
if (vinput.size() >= 4)
|
||||
{
|
||||
mapprevOutValues[outpoint] = vinput[3].get_int64();
|
||||
mapprevOutValues[outpoint] = vinput[3].getInt<int64_t>();
|
||||
}
|
||||
}
|
||||
if (!fValid)
|
||||
@@ -305,11 +305,11 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
||||
fValid = false;
|
||||
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());
|
||||
if (vinput.size() >= 4)
|
||||
{
|
||||
mapprevOutValues[outpoint] = vinput[3].get_int64();
|
||||
mapprevOutValues[outpoint] = vinput[3].getInt<int64_t>();
|
||||
}
|
||||
}
|
||||
if (!fValid)
|
||||
|
||||
Reference in New Issue
Block a user