@@ -106,11 +106,11 @@ def test_utxo_conversion(self):
106
106
assert "non_witness_utxo" in mining_node .decodepsbt (psbt_new .to_base64 ())["inputs" ][0 ]
107
107
108
108
# Have the offline node sign the PSBT (which will remove the non-witness UTXO)
109
- signed_psbt = offline_node .walletprocesspsbt (psbt_new .to_base64 ())[ "psbt" ]
110
- assert not "non_witness_utxo" in mining_node .decodepsbt (signed_psbt )["inputs" ][0 ]
109
+ signed_psbt = offline_node .walletprocesspsbt (psbt_new .to_base64 ())
110
+ assert not "non_witness_utxo" in mining_node .decodepsbt (signed_psbt [ "psbt" ] )["inputs" ][0 ]
111
111
112
112
# Make sure we can mine the resulting transaction
113
- txid = mining_node .sendrawtransaction (mining_node . finalizepsbt ( signed_psbt ) ["hex" ])
113
+ txid = mining_node .sendrawtransaction (signed_psbt ["hex" ])
114
114
self .generate (mining_node , nblocks = 1 , sync_fun = lambda : self .sync_all ([online_node , mining_node ]))
115
115
assert_equal (online_node .gettxout (txid ,0 )["confirmations" ], 1 )
116
116
@@ -142,9 +142,8 @@ def test_input_confs_control(self):
142
142
utxo1 = tx1_inputs [0 ]
143
143
assert_equal (unconfirmed_txid , utxo1 ['txid' ])
144
144
145
- signed_tx1 = wallet .walletprocesspsbt (psbtx1 )['psbt' ]
146
- final_tx1 = wallet .finalizepsbt (signed_tx1 )['hex' ]
147
- txid1 = self .nodes [0 ].sendrawtransaction (final_tx1 )
145
+ signed_tx1 = wallet .walletprocesspsbt (psbtx1 )
146
+ txid1 = self .nodes [0 ].sendrawtransaction (signed_tx1 ['hex' ])
148
147
149
148
mempool = self .nodes [0 ].getrawmempool ()
150
149
assert txid1 in mempool
@@ -157,9 +156,8 @@ def test_input_confs_control(self):
157
156
158
157
self .log .info ("Fail to broadcast a new PSBT with maxconf 0 due to BIP125 rules to verify it actually chose unconfirmed outputs" )
159
158
psbt_invalid = wallet .walletcreatefundedpsbt ([{'txid' : utxo1 ['txid' ], 'vout' : utxo1 ['vout' ]}], {target_address : 1 }, 0 , {'add_inputs' : True , 'maxconf' : 0 , 'fee_rate' : 10 })['psbt' ]
160
- signed_invalid = wallet .walletprocesspsbt (psbt_invalid )['psbt' ]
161
- final_invalid = wallet .finalizepsbt (signed_invalid )['hex' ]
162
- assert_raises_rpc_error (- 26 , "bad-txns-spends-conflicting-tx" , self .nodes [0 ].sendrawtransaction , final_invalid )
159
+ signed_invalid = wallet .walletprocesspsbt (psbt_invalid )
160
+ assert_raises_rpc_error (- 26 , "bad-txns-spends-conflicting-tx" , self .nodes [0 ].sendrawtransaction , signed_invalid ['hex' ])
163
161
164
162
self .log .info ("Craft a replacement adding inputs with highest confs possible" )
165
163
psbtx2 = wallet .walletcreatefundedpsbt ([{'txid' : utxo1 ['txid' ], 'vout' : utxo1 ['vout' ]}], {target_address : 1 }, 0 , {'add_inputs' : True , 'minconf' : 2 , 'fee_rate' : 10 })['psbt' ]
@@ -169,9 +167,8 @@ def test_input_confs_control(self):
169
167
if vin ['txid' ] != unconfirmed_txid :
170
168
assert_greater_than_or_equal (self .nodes [0 ].gettxout (vin ['txid' ], vin ['vout' ])['confirmations' ], 2 )
171
169
172
- signed_tx2 = wallet .walletprocesspsbt (psbtx2 )['psbt' ]
173
- final_tx2 = wallet .finalizepsbt (signed_tx2 )['hex' ]
174
- txid2 = self .nodes [0 ].sendrawtransaction (final_tx2 )
170
+ signed_tx2 = wallet .walletprocesspsbt (psbtx2 )
171
+ txid2 = self .nodes [0 ].sendrawtransaction (signed_tx2 ['hex' ])
175
172
176
173
mempool = self .nodes [0 ].getrawmempool ()
177
174
assert txid1 not in mempool
@@ -217,12 +214,21 @@ def run_test(self):
217
214
218
215
self .nodes [0 ].walletpassphrase (passphrase = "password" , timeout = 1000000 )
219
216
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 )
217
+ # Sign the transaction but don't finalize
218
+ processed_psbt = self .nodes [0 ].walletprocesspsbt (psbt = psbtx , finalize = False )
219
+ assert "hex" not in processed_psbt
220
+ signed_psbt = processed_psbt ['psbt' ]
221
+
222
+ # Finalize and send
223
+ finalized_hex = self .nodes [0 ].finalizepsbt (signed_psbt )['hex' ]
224
+ self .nodes [0 ].sendrawtransaction (finalized_hex )
225
+
226
+ # Alternative method: sign AND finalize in one command
227
+ processed_finalized_psbt = self .nodes [0 ].walletprocesspsbt (psbt = psbtx , finalize = True )
228
+ finalized_psbt = processed_finalized_psbt ['psbt' ]
229
+ finalized_psbt_hex = processed_finalized_psbt ['hex' ]
230
+ assert signed_psbt != finalized_psbt
231
+ assert finalized_psbt_hex == finalized_hex
226
232
227
233
# Manually selected inputs can be locked:
228
234
assert_equal (len (self .nodes [0 ].listlockunspent ()), 0 )
@@ -296,7 +302,7 @@ def run_test(self):
296
302
# Check decodepsbt fee calculation (input values shall only be counted once per UTXO)
297
303
assert_equal (decoded ['fee' ], created_psbt ['fee' ])
298
304
assert_equal (walletprocesspsbt_out ['complete' ], True )
299
- self .nodes [1 ].sendrawtransaction (self . nodes [ 1 ]. finalizepsbt ( walletprocesspsbt_out [ 'psbt' ]) ['hex' ])
305
+ self .nodes [1 ].sendrawtransaction (walletprocesspsbt_out ['hex' ])
300
306
301
307
self .log .info ("Test walletcreatefundedpsbt fee rate of 10000 sat/vB and 0.1 BTC/kvB produces a total fee at or slightly below -maxtxfee (~0.05290000)" )
302
308
res1 = self .nodes [1 ].walletcreatefundedpsbt (inputs , outputs , 0 , {"fee_rate" : 10000 , "add_inputs" : True })
@@ -387,7 +393,7 @@ def run_test(self):
387
393
# partially sign with node 2. This should be complete and sendable
388
394
walletprocesspsbt_out = self .nodes [2 ].walletprocesspsbt (psbtx )
389
395
assert_equal (walletprocesspsbt_out ['complete' ], True )
390
- self .nodes [2 ].sendrawtransaction (self . nodes [ 2 ]. finalizepsbt ( walletprocesspsbt_out [ 'psbt' ]) ['hex' ])
396
+ self .nodes [2 ].sendrawtransaction (walletprocesspsbt_out ['hex' ])
391
397
392
398
# check that walletprocesspsbt fails to decode a non-psbt
393
399
rawtx = self .nodes [1 ].createrawtransaction ([{"txid" :txid ,"vout" :p2wpkh_pos }], {self .nodes [1 ].getnewaddress ():9.99 })
@@ -739,14 +745,13 @@ def test_psbt_input_keys(psbt_input, keys):
739
745
assert not signed ['complete' ]
740
746
signed = self .nodes [0 ].walletprocesspsbt (signed ['psbt' ])
741
747
assert signed ['complete' ]
742
- self .nodes [0 ].finalizepsbt (signed ['psbt' ])
743
748
744
749
psbt = wallet .walletcreatefundedpsbt ([ext_utxo ], {self .nodes [0 ].getnewaddress (): 15 }, 0 , {"add_inputs" : True , "solving_data" :{"descriptors" : [desc ]}})
745
750
signed = wallet .walletprocesspsbt (psbt ['psbt' ])
746
751
assert not signed ['complete' ]
747
752
signed = self .nodes [0 ].walletprocesspsbt (signed ['psbt' ])
748
753
assert signed ['complete' ]
749
- final = self . nodes [ 0 ]. finalizepsbt ( signed ['psbt' ], False )
754
+ final = signed ['hex' ]
750
755
751
756
dec = self .nodes [0 ].decodepsbt (signed ["psbt" ])
752
757
for i , txin in enumerate (dec ["tx" ]["vin" ]):
@@ -781,8 +786,8 @@ def test_psbt_input_keys(psbt_input, keys):
781
786
)
782
787
signed = wallet .walletprocesspsbt (psbt ["psbt" ])
783
788
signed = self .nodes [0 ].walletprocesspsbt (signed ["psbt" ])
784
- final = self . nodes [ 0 ]. finalizepsbt ( signed ["psbt" ])
785
- assert self .nodes [0 ].testmempoolaccept ([final [ "hex" ] ])[0 ]["allowed" ]
789
+ final = signed ["hex" ]
790
+ assert self .nodes [0 ].testmempoolaccept ([final ])[0 ]["allowed" ]
786
791
# Reducing the weight should have a lower fee
787
792
psbt2 = wallet .walletcreatefundedpsbt (
788
793
inputs = [{"txid" : ext_utxo ["txid" ], "vout" : ext_utxo ["vout" ], "weight" : low_input_weight }],
@@ -837,8 +842,8 @@ def test_psbt_input_keys(psbt_input, keys):
837
842
self .nodes [0 ].importprivkey (privkey )
838
843
839
844
psbt = watchonly .sendall ([wallet .getnewaddress ()])["psbt" ]
840
- psbt = self .nodes [0 ].walletprocesspsbt (psbt )[ "psbt" ]
841
- self .nodes [0 ].sendrawtransaction (self . nodes [ 0 ]. finalizepsbt ( psbt ) ["hex" ])
845
+ signed_tx = self .nodes [0 ].walletprocesspsbt (psbt )
846
+ self .nodes [0 ].sendrawtransaction (signed_tx ["hex" ])
842
847
843
848
# Same test but for taproot
844
849
if self .options .descriptors :
@@ -853,8 +858,8 @@ def test_psbt_input_keys(psbt_input, keys):
853
858
self .nodes [0 ].importdescriptors ([{"desc" : descsum_create ("tr({})" .format (privkey )), "timestamp" :"now" }])
854
859
855
860
psbt = watchonly .sendall ([wallet .getnewaddress (), addr ])["psbt" ]
856
- psbt = self .nodes [0 ].walletprocesspsbt (psbt )[ "psbt" ]
857
- txid = self .nodes [0 ].sendrawtransaction (self . nodes [ 0 ]. finalizepsbt ( psbt ) ["hex" ])
861
+ processed_psbt = self .nodes [0 ].walletprocesspsbt (psbt )
862
+ txid = self .nodes [0 ].sendrawtransaction (processed_psbt ["hex" ])
858
863
vout = find_vout_for_address (self .nodes [0 ], txid , addr )
859
864
860
865
# Make sure tap tree is in psbt
@@ -871,7 +876,7 @@ def test_psbt_input_keys(psbt_input, keys):
871
876
vout = find_vout_for_address (self .nodes [0 ], txid , addr )
872
877
psbt = self .nodes [0 ].createpsbt ([{"txid" : txid , "vout" : vout }], [{self .nodes [0 ].getnewaddress (): 0.9999 }])
873
878
signed = self .nodes [0 ].walletprocesspsbt (psbt )
874
- rawtx = self . nodes [ 0 ]. finalizepsbt ( signed [ "psbt" ]) ["hex" ]
879
+ rawtx = signed ["hex" ]
875
880
self .nodes [0 ].sendrawtransaction (rawtx )
876
881
self .generate (self .nodes [0 ], 1 )
877
882
0 commit comments