@@ -1539,9 +1539,10 @@ impl KeysManager {
1539
1539
pub fn sign_spendable_outputs_psbt < C : Signing > ( & self , descriptors : & [ & SpendableOutputDescriptor ] , mut psbt : PartiallySignedTransaction , secp_ctx : & Secp256k1 < C > ) -> Result < PartiallySignedTransaction , ( ) > {
1540
1540
let mut keys_cache: Option < ( InMemorySigner , [ u8 ; 32 ] ) > = None ;
1541
1541
for outp in descriptors {
1542
+ let get_input_idx = |outpoint : & OutPoint | psbt. unsigned_tx . input . iter ( ) . position ( |i| i. previous_output == outpoint. into_bitcoin_outpoint ( ) ) . ok_or ( ( ) ) ;
1542
1543
match outp {
1543
1544
SpendableOutputDescriptor :: StaticPaymentOutput ( descriptor) => {
1544
- let input_idx = psbt . unsigned_tx . input . iter ( ) . position ( |i| i . previous_output == descriptor. outpoint . into_bitcoin_outpoint ( ) ) . ok_or ( ( ) ) ?;
1545
+ let input_idx = get_input_idx ( & descriptor. outpoint ) ?;
1545
1546
if keys_cache. is_none ( ) || keys_cache. as_ref ( ) . unwrap ( ) . 1 != descriptor. channel_keys_id {
1546
1547
let mut signer = self . derive_channel_keys ( descriptor. channel_value_satoshis , & descriptor. channel_keys_id ) ;
1547
1548
if let Some ( channel_params) = descriptor. channel_transaction_parameters . as_ref ( ) {
@@ -1553,7 +1554,7 @@ impl KeysManager {
1553
1554
psbt. inputs [ input_idx] . final_script_witness = Some ( witness) ;
1554
1555
} ,
1555
1556
SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) => {
1556
- let input_idx = psbt . unsigned_tx . input . iter ( ) . position ( |i| i . previous_output == descriptor. outpoint . into_bitcoin_outpoint ( ) ) . ok_or ( ( ) ) ?;
1557
+ let input_idx = get_input_idx ( & descriptor. outpoint ) ?;
1557
1558
if keys_cache. is_none ( ) || keys_cache. as_ref ( ) . unwrap ( ) . 1 != descriptor. channel_keys_id {
1558
1559
keys_cache = Some ( (
1559
1560
self . derive_channel_keys ( descriptor. channel_value_satoshis , & descriptor. channel_keys_id ) ,
@@ -1563,7 +1564,7 @@ impl KeysManager {
1563
1564
psbt. inputs [ input_idx] . final_script_witness = Some ( witness) ;
1564
1565
} ,
1565
1566
SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
1566
- let input_idx = psbt . unsigned_tx . input . iter ( ) . position ( |i| i . previous_output == outpoint. into_bitcoin_outpoint ( ) ) . ok_or ( ( ) ) ?;
1567
+ let input_idx = get_input_idx ( outpoint) ?;
1567
1568
let derivation_idx = if output. script_pubkey == self . destination_script {
1568
1569
1
1569
1570
} else {
0 commit comments