From c405207a18fdee75a4dea470bb0d13e59e15ce45 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Fri, 15 Sep 2023 16:46:09 +0100 Subject: [PATCH 1/3] rpc: `descriptorprocesspsbt` return hex encoded tx If processed psbt is complete return hex encoded network transaction in the output. --- src/rpc/rawtransaction.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index fa5dd281a1a7d..31ca1268623d7 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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{ @@ -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; }, }; From 2b4edf889a4b555c8c7f6793fa5d820e5513ecac Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Fri, 15 Sep 2023 16:48:36 +0100 Subject: [PATCH 2/3] test: check `descriptorprocesspsbt` return hex encoded tx Test that if the processed psbt is complete the hex encoded tx is returned and remove unneccessary rpc call to finalize the psbt. --- test/functional/rpc_psbt.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index c01dc64df0331..60df48f025cfc 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -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") From a99e9e655a58b2364a74aec5cafb827a73c6b0c4 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Fri, 15 Sep 2023 16:53:59 +0100 Subject: [PATCH 3/3] doc: add release note --- doc/release-notes-28414.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/release-notes-28414.md b/doc/release-notes-28414.md index 7fca11f8220bb..3f83a73252548 100644 --- a/doc/release-notes-28414.md +++ b/doc/release-notes-28414.md @@ -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`. +