Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backports and changes to fix CI #1161

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use o.find_value instead of find_value(o) to fix dangling pointer war…
…ning
psgreco committed Mar 5, 2025
commit f45869b0999e0f4ba82624c64270c76dc8fb2b82
18 changes: 9 additions & 9 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
@@ -848,7 +848,7 @@ static UniValue ConnectAndCallRPC(BaseRequestHandler* rh, const std::string& str
try {
response = CallRPC(rh, strMethod, args, rpcwallet);
if (fWait) {
const UniValue& error = find_value(response, "error");
const UniValue& error = response.find_value("error");
if (!error.isNull() && error["code"].get_int() == RPC_IN_WARMUP) {
throw CConnectionFailed("server in warmup");
}
@@ -877,8 +877,8 @@ static void ParseResult(const UniValue& result, std::string& strPrint)
static void ParseError(const UniValue& error, std::string& strPrint, int& nRet)
{
if (error.isObject()) {
const UniValue& err_code = find_value(error, "code");
const UniValue& err_msg = find_value(error, "message");
const UniValue& err_code = error.find_value("code");
const UniValue& err_msg = error.find_value("message");
if (!err_code.isNull()) {
strPrint = "error code: " + err_code.getValStr() + "\n";
}
@@ -904,15 +904,15 @@ static void GetWalletBalances(UniValue& result)
{
DefaultRequestHandler rh;
const UniValue listwallets = ConnectAndCallRPC(&rh, "listwallets", /* args=*/{});
if (!find_value(listwallets, "error").isNull()) return;
const UniValue& wallets = find_value(listwallets, "result");
if (!listwallets.find_value("error").isNull()) return;
const UniValue& wallets = listwallets.find_value("result");
if (wallets.size() <= 1) return;

UniValue balances(UniValue::VOBJ);
for (const UniValue& wallet : wallets.getValues()) {
const std::string wallet_name = wallet.get_str();
const UniValue getbalances = ConnectAndCallRPC(&rh, "getbalances", /* args=*/{}, wallet_name);
const UniValue& balance = find_value(getbalances, "result")["mine"]["trusted"];
const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"];
balances.pushKV(wallet_name, balance);
}
result.pushKV("balances", balances);
@@ -948,7 +948,7 @@ static void GetProgressBar(double progress, std::string& progress_bar)
*/
static void ParseGetInfoResult(UniValue& result)
{
if (!find_value(result, "error").isNull()) return;
if (!result.find_value("error").isNull()) return;

std::string RESET, GREEN, BLUE, YELLOW, MAGENTA, CYAN;
bool should_colorize = false;
@@ -1157,9 +1157,9 @@ static int CommandLineRPC(int argc, char *argv[])
rh.reset(new NetinfoRequestHandler());
} else if (gArgs.GetBoolArg("-generate", false)) {
const UniValue getnewaddress{GetNewAddress()};
const UniValue& error{find_value(getnewaddress, "error")};
const UniValue& error{getnewaddress.find_value("error")};
if (error.isNull()) {
SetGenerateToAddressArgs(find_value(getnewaddress, "result").get_str(), args);
SetGenerateToAddressArgs(getnewaddress.find_value("result").get_str(), args);
rh.reset(new GenerateToAddressRequestHandler());
} else {
ParseError(error, strPrint, nRet);
6 changes: 3 additions & 3 deletions src/external_signer.cpp
Original file line number Diff line number Diff line change
@@ -30,15 +30,15 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
}
for (UniValue signer : result.getValues()) {
// Check for error
const UniValue& error = find_value(signer, "error");
const UniValue& error = signer.find_value("error");
if (!error.isNull()) {
if (!error.isStr()) {
throw std::runtime_error(strprintf("'%s' error", command));
}
throw std::runtime_error(strprintf("'%s' error: %s", command, error.getValStr()));
}
// Check if fingerprint is present
const UniValue& fingerprint = find_value(signer, "fingerprint");
const UniValue& fingerprint = signer.find_value("fingerprint");
if (fingerprint.isNull()) {
throw std::runtime_error(strprintf("'%s' received invalid response, missing signer fingerprint", command));
}
@@ -50,7 +50,7 @@ bool ExternalSigner::Enumerate(const std::string& command, std::vector<ExternalS
}
if (duplicate) break;
std::string name = "";
const UniValue& model_field = find_value(signer, "model");
const UniValue& model_field = signer.find_value("model");
if (model_field.isStr() && model_field.getValStr() != "") {
name += model_field.getValStr();
}
4 changes: 2 additions & 2 deletions src/mainchainrpc.cpp
Original file line number Diff line number Diff line change
@@ -158,12 +158,12 @@ bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDept
UniValue params(UniValue::VARR);
params.push_back(hash.GetHex());
UniValue reply = CallMainChainRPC("getblockheader", params);
UniValue errval = find_value(reply, "error");
UniValue errval = reply.find_value("error");
if (!errval.isNull()) {
LogPrintf("WARNING: Got error reply from bitcoind getblockheader: %s\n", errval.write());
return false;
}
UniValue result = find_value(reply, "result");
UniValue result = reply.find_value("result");
if (!result.isObject()) {
LogPrintf("ERROR: bitcoind getblockheader result was malformed (not object): %s\n", result.write());
return false;
10 changes: 5 additions & 5 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
@@ -646,7 +646,7 @@ static RPCHelpMan getblocktemplate()
if (!request.params[0].isNull())
{
const UniValue& oparam = request.params[0].get_obj();
const UniValue& modeval = find_value(oparam, "mode");
const UniValue& modeval = oparam.find_value("mode");
if (modeval.isStr())
strMode = modeval.get_str();
else if (modeval.isNull())
@@ -655,11 +655,11 @@ static RPCHelpMan getblocktemplate()
}
else
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
lpval = find_value(oparam, "longpollid");
lpval = oparam.find_value("longpollid");

if (strMode == "proposal")
{
const UniValue& dataval = find_value(oparam, "data");
const UniValue& dataval = oparam.find_value("data");
if (!dataval.isStr())
throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");

@@ -686,15 +686,15 @@ static RPCHelpMan getblocktemplate()
return BIP22ValidationResult(state);
}

const UniValue& aClientRules = find_value(oparam, "rules");
const UniValue& aClientRules = oparam.find_value("rules");
if (aClientRules.isArray()) {
for (unsigned int i = 0; i < aClientRules.size(); ++i) {
const UniValue& v = aClientRules[i];
setClientRules.insert(v.get_str());
}
} else {
// NOTE: It is important that this NOT be read if versionbits is supported
const UniValue& uvMaxVersion = find_value(oparam, "maxversion");
const UniValue& uvMaxVersion = oparam.find_value("maxversion");
if (uvMaxVersion.isNum()) {
nMaxVersionPreVB = uvMaxVersion.get_int64();
}
2 changes: 1 addition & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
@@ -2165,7 +2165,7 @@ static RPCHelpMan createpsbt()
std::set<uint256> new_reissuance;
for (unsigned int i = 0; i < rawTx.vin.size(); ++i) {
if (!rawTx.vin[i].assetIssuance.IsNull()) {
const UniValue& blind_reissuance_v = find_value(request.params[0].get_array()[i].get_obj(), "blind_reissuance");
const UniValue& blind_reissuance_v = request.params[0].get_array()[i].get_obj().find_value("blind_reissuance");
bool blind_reissuance = blind_reissuance_v.isNull() ? true : blind_reissuance_v.get_bool();
uint256 entropy;
CAsset asset;
20 changes: 10 additions & 10 deletions src/rpc/rawtransaction_util.cpp
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal

uint256 txid = ParseHashO(o, "txid");

const UniValue& vout_v = find_value(o, "vout");
const UniValue& vout_v = o.find_value("vout");
if (!vout_v.isNum())
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
int nOutput = vout_v.get_int();
@@ -192,7 +192,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
}

// set the sequence number if passed in the parameters object
const UniValue& sequenceObj = find_value(o, "sequence");
const UniValue& sequenceObj = o.find_value("sequence");
if (sequenceObj.isNum()) {
int64_t seqNr64 = sequenceObj.get_int64();
if (seqNr64 < 0 || seqNr64 > CTxIn::SEQUENCE_FINAL) {
@@ -205,11 +205,11 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
CTxIn in(COutPoint(txid, nOutput), CScript(), nSequence);

// Get issuance stuff if it's there
const UniValue& blinding_nonce_v = find_value(o, "asset_blinding_nonce");
const UniValue& entropy_v = find_value(o, "asset_entropy");
const UniValue& amount_v = find_value(o, "issuance_amount");
const UniValue& issuance_tokens_v = find_value(o, "issuance_tokens");
const UniValue& blind_reissuance_v = find_value(o, "blind_reissuance");
const UniValue& blinding_nonce_v = o.find_value("asset_blinding_nonce");
const UniValue& entropy_v = o.find_value("asset_entropy");
const UniValue& amount_v = o.find_value("issuance_amount");
const UniValue& issuance_tokens_v = o.find_value("issuance_tokens");
const UniValue& blind_reissuance_v = o.find_value("blind_reissuance");
if (!amount_v.isNull() && allow_issuance) {
if (!amount_v.isNum()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "issuance_amount is not a number");
@@ -242,9 +242,9 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
rawTx.vin.push_back(in);

// Get the pegin stuff if it's there
const UniValue& pegin_tx = find_value(o, "pegin_bitcoin_tx");
const UniValue& pegin_tx_proof = find_value(o, "pegin_txout_proof");
const UniValue& pegin_script = find_value(o, "pegin_claim_script");
const UniValue& pegin_tx = o.find_value("pegin_bitcoin_tx");
const UniValue& pegin_tx_proof = o.find_value("pegin_txout_proof");
const UniValue& pegin_script = o.find_value("pegin_claim_script");
if (!pegin_tx.isNull() && !pegin_tx_proof.isNull() && !pegin_script.isNull() && allow_peg_in) {
if (!IsHex(pegin_script.get_str())) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Given claim_script is not hex.");
4 changes: 2 additions & 2 deletions src/test/system_tests.cpp
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(run_command)
const UniValue result = RunCommandParseJSON("echo \"{\"success\": true}\"");
#endif
BOOST_CHECK(result.isObject());
const UniValue& success = find_value(result, "success");
const UniValue& success = result.find_value("success");
BOOST_CHECK(!success.isNull());
BOOST_CHECK_EQUAL(success.getBool(), true);
}
@@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(run_command)
{
const UniValue result = RunCommandParseJSON("cat", "{\"success\": true}");
BOOST_CHECK(result.isObject());
const UniValue& success = find_value(result, "success");
const UniValue& success = result.find_value("success");
BOOST_CHECK(!success.isNull());
BOOST_CHECK_EQUAL(success.getBool(), true);
}
2 changes: 1 addition & 1 deletion src/wallet/rpc/coins.cpp
Original file line number Diff line number Diff line change
@@ -378,7 +378,7 @@ RPCHelpMan lockunspent()
});

const uint256 txid(ParseHashO(o, "txid"));
const int nOutput = find_value(o, "vout").get_int();
const int nOutput = o.find_value("vout").get_int();
if (nOutput < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
}
6 changes: 3 additions & 3 deletions src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
@@ -634,7 +634,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
for (const UniValue& input : options["input_weights"].get_array().getValues()) {
uint256 txid = ParseHashO(input, "txid");

const UniValue& vout_v = find_value(input, "vout");
const UniValue& vout_v = input.find_value("vout");
if (!vout_v.isNum()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
}
@@ -643,7 +643,7 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
}

const UniValue& weight_v = find_value(input, "weight");
const UniValue& weight_v = input.find_value("weight");
if (!weight_v.isNum()) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing weight key");
}
@@ -1617,7 +1617,7 @@ RPCHelpMan walletcreatefundedpsbt()
std::set<uint256> new_reissuance;
for (unsigned int i = 0; i < rawTx.vin.size(); ++i) {
if (!rawTx.vin[i].assetIssuance.IsNull()) {
const UniValue& blind_reissuance_v = find_value(request.params[0].get_array()[i].get_obj(), "blind_reissuance");
const UniValue& blind_reissuance_v = request.params[0].get_array()[i].get_obj().find_value("blind_reissuance");
bool blind_reissuance = blind_reissuance_v.isNull() ? true : blind_reissuance_v.get_bool();
uint256 entropy;
CAsset asset;
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
@@ -3701,7 +3701,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()

if (!signer_res.isObject()) throw std::runtime_error(std::string(__func__) + ": Unexpected result");
for (bool internal : {false, true}) {
const UniValue& descriptor_vals = find_value(signer_res, internal ? "internal" : "receive");
const UniValue& descriptor_vals = signer_res.find_value(internal ? "internal" : "receive");
if (!descriptor_vals.isArray()) throw std::runtime_error(std::string(__func__) + ": Unexpected result");
for (const UniValue& desc_val : descriptor_vals.get_array().getValues()) {
std::string desc_str = desc_val.getValStr();