diff --git a/contrib/signet/miner b/contrib/signet/miner index e020c4589c1..422bbf214dc 100755 --- a/contrib/signet/miner +++ b/contrib/signet/miner @@ -69,8 +69,8 @@ def signet_txs(block, challenge): def decode_psbt(b64psbt): psbt = PSBT.from_base64(b64psbt) - assert len(psbt.tx.vin) == 1 - assert len(psbt.tx.vout) == 1 + assert len(psbt.i) == 1 + assert len(psbt.i) == 1 assert PSBT_SIGNET_BLOCK in psbt.g.map scriptSig = psbt.i[0].map.get(PSBT_IN_FINAL_SCRIPTSIG, b"") diff --git a/doc/release-notes-21283.md b/doc/release-notes-21283.md new file mode 100644 index 00000000000..ed56e1d3e40 --- /dev/null +++ b/doc/release-notes-21283.md @@ -0,0 +1,6 @@ +Updated RPCs +------------ + +- `createpsbt` and `walletcreatepsbt` will now default to creating + version 2 PSBTs. An optional `psbt_version` argument is added to + both which allows specifying the version of PSBT to create. diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 51e252bffca..868d9dabbf7 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -22,11 +22,11 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) CAmount in_amt = 0; - result.inputs.resize(psbtx.tx->vin.size()); + result.inputs.resize(psbtx.inputs.size()); const PrecomputedTransactionData txdata = PrecomputePSBTData(psbtx); - for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) { + for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { PSBTInput& input = psbtx.inputs[i]; PSBTInputAnalysis& input_analysis = result.inputs[i]; @@ -35,7 +35,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) // Check for a UTXO CTxOut utxo; - if (psbtx.GetInputUTXO(utxo, i)) { + if (input.GetUTXO(utxo)) { if (!MoneyRange(utxo.nValue) || !MoneyRange(in_amt + utxo.nValue)) { result.SetInvalid(strprintf("PSBT is not valid. Input %u has invalid value", i)); return result; @@ -43,7 +43,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) in_amt += utxo.nValue; input_analysis.has_utxo = true; } else { - if (input.non_witness_utxo && psbtx.tx->vin[i].prevout.n >= input.non_witness_utxo->vout.size()) { + if (input.non_witness_utxo && input.prev_out >= input.non_witness_utxo->vout.size()) { result.SetInvalid(strprintf("PSBT is not valid. Input %u specifies invalid prevout", i)); return result; } @@ -89,7 +89,7 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) // Calculate next role for PSBT by grabbing "minimum" PSBTInput next role result.next = PSBTRole::EXTRACTOR; - for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) { + for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { PSBTInputAnalysis& input_analysis = result.inputs[i]; result.next = std::min(result.next, input_analysis.next); } @@ -97,12 +97,12 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) if (calc_fee) { // Get the output amount - CAmount out_amt = std::accumulate(psbtx.tx->vout.begin(), psbtx.tx->vout.end(), CAmount(0), - [](CAmount a, const CTxOut& b) { - if (!MoneyRange(a) || !MoneyRange(b.nValue) || !MoneyRange(a + b.nValue)) { + CAmount out_amt = std::accumulate(psbtx.outputs.begin(), psbtx.outputs.end(), CAmount(0), + [](CAmount a, const PSBTOutput& b) { + if (!MoneyRange(a) || !MoneyRange(*b.amount) || !MoneyRange(a + *b.amount)) { return CAmount(-1); } - return a += b.nValue; + return a += *b.amount; } ); if (!MoneyRange(out_amt)) { @@ -115,23 +115,23 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) result.fee = fee; // Estimate the size - CMutableTransaction mtx(*psbtx.tx); + CMutableTransaction mtx(psbtx.GetUnsignedTx()); CCoinsView view_dummy; CCoinsViewCache view(&view_dummy); bool success = true; - for (unsigned int i = 0; i < psbtx.tx->vin.size(); ++i) { + for (unsigned int i = 0; i < psbtx.inputs.size(); ++i) { PSBTInput& input = psbtx.inputs[i]; Coin newcoin; - if (!SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, nullptr, 1) || !psbtx.GetInputUTXO(newcoin.out, i)) { + if (!SignPSBTInput(DUMMY_SIGNING_PROVIDER, psbtx, i, nullptr, 1) || !input.GetUTXO(newcoin.out)) { success = false; break; } else { mtx.vin[i].scriptSig = input.final_script_sig; mtx.vin[i].scriptWitness = input.final_script_witness; newcoin.nHeight = 1; - view.AddCoin(psbtx.tx->vin[i].prevout, std::move(newcoin), true); + view.AddCoin(input.GetOutPoint(), std::move(newcoin), true); } } diff --git a/src/psbt.cpp b/src/psbt.cpp index 9369cfc334d..3789ab602ec 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -6,14 +6,19 @@ #include #include +#include #include