Skip to content

Commit 719cb30

Browse files
committed
Merge bitcoin/bitcoin#28492: RPC: descriptorprocesspsbt returns hex encoded tx if complete
a99e9e6 doc: add release note (ismaelsadeeq) 2b4edf8 test: check `descriptorprocesspsbt` return hex encoded tx (ismaelsadeeq) c405207 rpc: `descriptorprocesspsbt` return hex encoded tx (ismaelsadeeq) Pull request description: Coming from [#28414 comment](bitcoin/bitcoin#28414 (review)) Same thing also for `descriptorprocesspsbt`. Before this PR `descriptorprocesspsbt` returns a boolean `complete` which indicates that the psbt is final, users then have to call `finalizepsbt` to get the hex encoded network transaction. In this PR if the psbt is complete the return object also has the hex encoded network transaction ready for broadcast with `sendrawtransaction`. This save users calling `finalizepsbt` with the descriptor, if it is already complete. ACKs for top commit: achow101: ACK a99e9e6 pinheadmz: ACK a99e9e6 ishaanam: ACK a99e9e6 Tree-SHA512: c3f1b1391d4df05216c463127cd593f8703840430a99febb54890bc66fadabf9d9530860605f347ec54c1694019173247a0e7a9eb879d3cbb420f9e8d9839b75
2 parents b000ed5 + a99e9e6 commit 719cb30

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

doc/release-notes-28414.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
RPC Wallet
22
----------
33

4-
- RPC `walletprocesspsbt` return object now includes field `hex` (if the transaction
5-
is complete) containing the serialized transaction suitable for RPC `sendrawtransaction`. (#28414)
4+
- RPC `walletprocesspsbt`, and `descriptorprocesspsbt` return object now includes field `hex` (if the transaction
5+
is complete) containing the serialized transaction suitable for RPC `sendrawtransaction`.
6+

src/rpc/rawtransaction.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,7 @@ RPCHelpMan descriptorprocesspsbt()
19491949
{
19501950
{RPCResult::Type::STR, "psbt", "The base64-encoded partially signed transaction"},
19511951
{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
1952+
{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "The hex-encoded network transaction if complete"},
19521953
}
19531954
},
19541955
RPCExamples{
@@ -1989,7 +1990,14 @@ RPCHelpMan descriptorprocesspsbt()
19891990

19901991
result.pushKV("psbt", EncodeBase64(ssTx));
19911992
result.pushKV("complete", complete);
1992-
1993+
if (complete) {
1994+
CMutableTransaction mtx;
1995+
PartiallySignedTransaction psbtx_copy = psbtx;
1996+
CHECK_NONFATAL(FinalizeAndExtractPSBT(psbtx_copy, mtx));
1997+
CDataStream ssTx_final(SER_NETWORK, PROTOCOL_VERSION);
1998+
ssTx_final << mtx;
1999+
result.pushKV("hex", HexStr(ssTx_final));
2000+
}
19932001
return result;
19942002
},
19952003
};

test/functional/rpc_psbt.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -978,17 +978,22 @@ def test_psbt_input_keys(psbt_input, keys):
978978
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo'])
979979

980980
# Test that the psbt is not finalized and does not have bip32_derivs unless specified
981-
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)["psbt"]
982-
decoded = self.nodes[2].decodepsbt(psbt)
981+
processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=True, finalize=False)
982+
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
983983
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'partial_signatures', 'bip32_derivs'])
984984

985-
psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)["psbt"]
986-
decoded = self.nodes[2].decodepsbt(psbt)
985+
# If psbt not finalized, test that result does not have hex
986+
assert "hex" not in processed_psbt
987+
988+
processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)
989+
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
987990
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness'])
988991

992+
# Test psbt is complete
993+
assert_equal(processed_psbt['complete'], True)
994+
989995
# Broadcast transaction
990-
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"]
991-
self.nodes[2].sendrawtransaction(rawtx)
996+
self.nodes[2].sendrawtransaction(processed_psbt['hex'])
992997

993998
self.log.info("Test descriptorprocesspsbt raises if an invalid sighashtype is passed")
994999
assert_raises_rpc_error(-8, "all is not a valid sighash parameter.", self.nodes[2].descriptorprocesspsbt, psbt, [descriptor], sighashtype="all")

0 commit comments

Comments
 (0)