From e9bfff25db60129fe7dfc7a1aaea82c6b80a4491 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Fri, 16 Apr 2021 16:00:08 -0400 Subject: [PATCH] Allow empty scriptPubKeys --- src/blindpsbt.cpp | 2 +- src/psbt.cpp | 6 +++--- src/psbt.h | 12 +++++++----- src/qt/psbtoperationsdialog.cpp | 2 +- src/rpc/rawtransaction.cpp | 4 ++-- src/wallet/scriptpubkeyman.cpp | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/blindpsbt.cpp b/src/blindpsbt.cpp index 55ad807710..2ffc897810 100644 --- a/src/blindpsbt.cpp +++ b/src/blindpsbt.cpp @@ -393,7 +393,7 @@ BlindingStatus BlindPSBT(PartiallySignedTransaction& psbt, std::mapvout.push_back(txout); outputs.push_back(psbtout); return true; diff --git a/src/psbt.h b/src/psbt.h index b81a785042..826d8dd05a 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -904,7 +904,7 @@ struct PSBTOutput CScript witness_script; std::map hd_keypaths; Optional amount; - CScript script; + Optional script; std::map, std::vector> unknown; std::set m_proprietary; @@ -948,9 +948,9 @@ struct PSBTOutput if (m_psbt_version >= 2) { // Write spk - if (!script.empty()) { + if (script != nullopt) { SerializeToVector(s, CompactSizeWriter(PSBT_OUT_SCRIPT)); - s << script; + s << *script; } // Elements proprietary fields are v2 only @@ -1090,7 +1090,9 @@ struct PSBTOutput } else if (key.size() != 1) { throw std::ios_base::failure("Output script key is more than one byte type"); } - s >> script; + CScript sc; + s >> sc; + script = sc; break; } case PSBT_OUT_PROPRIETARY: @@ -1224,7 +1226,7 @@ struct PSBTOutput if (amount == nullopt) { throw std::ios_base::failure("Output amount is required in PSBTv2"); } - if (script.empty()) { + if (script == nullopt) { throw std::ios_base::failure("Output script is required in PSBTv2"); } } diff --git a/src/qt/psbtoperationsdialog.cpp b/src/qt/psbtoperationsdialog.cpp index 96c97a9c2d..bd15657b40 100644 --- a/src/qt/psbtoperationsdialog.cpp +++ b/src/qt/psbtoperationsdialog.cpp @@ -163,7 +163,7 @@ std::string PSBTOperationsDialog::renderTransaction(const PartiallySignedTransac int unit = m_client_model->getOptionsModel()->getDisplayUnit(); for (const PSBTOutput& out : psbtx.outputs) { CTxDestination address; - ExtractDestination(out.script, address); + ExtractDestination(*out.script, address); totalAmount += *out.amount; tx_description.append(tr(" * Sends %1 to %2") .arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, *out.amount)) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 2c93b51fc6..523bb3ef89 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1719,9 +1719,9 @@ static RPCHelpMan decodepsbt() if (output.amount != nullopt) { out.pushKV("amount", ValueFromAmount(*output.amount)); } - if (!output.script.empty()) { + if (output.script != nullopt) { UniValue spk(UniValue::VOBJ); - ScriptPubKeyToUniv(output.script, spk, true); + ScriptPubKeyToUniv(*output.script, spk, true); out.pushKV("script", spk); } } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index b3e07976a3..099ab12ee3 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -2150,7 +2150,7 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& // Fill in the bip32 keypaths and redeemscripts for the outputs so that hardware wallets can identify change for (unsigned int i = 0; i < psbtx.outputs.size(); ++i) { - std::unique_ptr keys = GetSolvingProvider(psbtx.outputs.at(i).script); + std::unique_ptr keys = GetSolvingProvider(*psbtx.outputs.at(i).script); if (!keys) { continue; }