Skip to content

Commit e3d484b

Browse files
committed
wallet rpc: return final tx hex from walletprocesspsbt if complete
1 parent ecab855 commit e3d484b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/wallet/rpc/spend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,7 @@ RPCHelpMan walletprocesspsbt()
15661566
{
15671567
{RPCResult::Type::STR, "psbt", "The base64-encoded partially signed transaction"},
15681568
{RPCResult::Type::BOOL, "complete", "If the transaction has a complete set of signatures"},
1569+
{RPCResult::Type::STR_HEX, "hex", /*optional=*/true, "The hex-encoded network transaction if complete"},
15691570
}
15701571
},
15711572
RPCExamples{
@@ -1609,6 +1610,14 @@ RPCHelpMan walletprocesspsbt()
16091610
ssTx << psbtx;
16101611
result.pushKV("psbt", EncodeBase64(ssTx.str()));
16111612
result.pushKV("complete", complete);
1613+
if (complete) {
1614+
CMutableTransaction mtx;
1615+
// Returns true if complete, which we already think it is.
1616+
CHECK_NONFATAL(FinalizeAndExtractPSBT(psbtx, mtx));
1617+
CDataStream ssTx_final(SER_NETWORK, PROTOCOL_VERSION);
1618+
ssTx_final << mtx;
1619+
result.pushKV("hex", HexStr(ssTx_final));
1620+
}
16121621

16131622
return result;
16141623
},

test/functional/rpc_psbt.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,21 @@ def run_test(self):
217217

218218
self.nodes[0].walletpassphrase(passphrase="password", timeout=1000000)
219219

220-
# Sign the transaction and send
221-
signed_tx = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=False)['psbt']
222-
finalized_tx = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=True)['psbt']
223-
assert signed_tx != finalized_tx
224-
final_tx = self.nodes[0].finalizepsbt(signed_tx)['hex']
225-
self.nodes[0].sendrawtransaction(final_tx)
220+
# Sign the transaction but don't finalize
221+
processed_psbt = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=False)
222+
assert "hex" not in processed_psbt
223+
signed_psbt = processed_psbt['psbt']
224+
225+
# Finalize and send
226+
finalized_hex = self.nodes[0].finalizepsbt(signed_psbt)['hex']
227+
self.nodes[0].sendrawtransaction(finalized_hex)
228+
229+
# Alternative method: sign AND finalize in one command
230+
processed_finalized_psbt = self.nodes[0].walletprocesspsbt(psbt=psbtx, finalize=True)
231+
finalized_psbt = processed_finalized_psbt['psbt']
232+
finalized_psbt_hex = processed_finalized_psbt['hex']
233+
assert signed_psbt != finalized_psbt
234+
assert finalized_psbt_hex == finalized_hex
226235

227236
# Manually selected inputs can be locked:
228237
assert_equal(len(self.nodes[0].listlockunspent()), 0)

0 commit comments

Comments
 (0)