Skip to content

Commit

Permalink
Merge bitcoin/bitcoin#28492: RPC: descriptorprocesspsbt returns hex…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
achow101 committed Sep 23, 2023
2 parents b000ed5 + a99e9e6 commit 719cb30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 3 additions & 2 deletions doc/release-notes-28414.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RPC Wallet
----------

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

10 changes: 9 additions & 1 deletion src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,7 @@ RPCHelpMan descriptorprocesspsbt()
{
{RPCResult::Type::STR, "psbt", "The base64-encoded partially signed transaction"},
{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "The hex-encoded network transaction if complete"},
}
},
RPCExamples{
Expand Down Expand Up @@ -1989,7 +1990,14 @@ RPCHelpMan descriptorprocesspsbt()

result.pushKV("psbt", EncodeBase64(ssTx));
result.pushKV("complete", complete);

if (complete) {
CMutableTransaction mtx;
PartiallySignedTransaction psbtx_copy = psbtx;
CHECK_NONFATAL(FinalizeAndExtractPSBT(psbtx_copy, mtx));
CDataStream ssTx_final(SER_NETWORK, PROTOCOL_VERSION);
ssTx_final << mtx;
result.pushKV("hex", HexStr(ssTx_final));
}
return result;
},
};
Expand Down
17 changes: 11 additions & 6 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,17 +978,22 @@ def test_psbt_input_keys(psbt_input, keys):
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo'])

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

psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)["psbt"]
decoded = self.nodes[2].decodepsbt(psbt)
# If psbt not finalized, test that result does not have hex
assert "hex" not in processed_psbt

processed_psbt = self.nodes[2].descriptorprocesspsbt(psbt=psbt, descriptors=[descriptor], sighashtype="ALL", bip32derivs=False, finalize=True)
decoded = self.nodes[2].decodepsbt(processed_psbt['psbt'])
test_psbt_input_keys(decoded['inputs'][0], ['witness_utxo', 'non_witness_utxo', 'final_scriptwitness'])

# Test psbt is complete
assert_equal(processed_psbt['complete'], True)

# Broadcast transaction
rawtx = self.nodes[2].finalizepsbt(psbt)["hex"]
self.nodes[2].sendrawtransaction(rawtx)
self.nodes[2].sendrawtransaction(processed_psbt['hex'])

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

0 comments on commit 719cb30

Please sign in to comment.