1- use bitcoin:: util:: {
2- bip32:: { ExtendedPubKey , Fingerprint } ,
3- psbt:: PartiallySignedTransaction as Psbt ,
4- } ;
1+ use bitcoin:: util:: { bip32:: Fingerprint , psbt:: PartiallySignedTransaction as Psbt } ;
52use std:: convert:: From ;
63
74use bitcoin:: OutPoint ;
@@ -52,12 +49,7 @@ impl SpendTransactionState {
5249 change_index : None ,
5350 action : SpendTransactionAction :: new (
5451 ctx. managers_threshold ,
55- & ctx. config
56- . daemon
57- . manager_config
58- . as_ref ( )
59- . expect ( "User is a manager" )
60- . xpub ,
52+ ctx. user_signed ( & psbt) ,
6153 & ctx. managers_xpubs ( ) ,
6254 & psbt,
6355 ) ,
@@ -142,6 +134,7 @@ impl State for SpendTransactionState {
142134 self . action . view ( ctx, & self . psbt ) ,
143135 self . warning . as_ref ( ) ,
144136 show_delete_button,
137+ ctx. user_signed ( & self . psbt ) ,
145138 )
146139 }
147140
@@ -185,7 +178,7 @@ pub enum SpendTransactionAction {
185178impl SpendTransactionAction {
186179 fn new (
187180 managers_threshold : usize ,
188- user_manager_xpub : & ExtendedPubKey ,
181+ user_signed : bool ,
189182 managers_xpubs : & Vec < DescriptorPublicKey > ,
190183 psbt : & Psbt ,
191184 ) -> Self {
@@ -198,13 +191,7 @@ impl SpendTransactionAction {
198191 warning : None ,
199192 view : SpendTransactionBroadcastView :: new ( ) ,
200193 } ;
201- } else if input. partial_sigs . keys ( ) . any ( |key| {
202- input
203- . bip32_derivation
204- . get ( key)
205- . map ( |( fingerprint, _) | user_manager_xpub. fingerprint ( ) == * fingerprint)
206- . unwrap_or ( false )
207- } ) {
194+ } else if user_signed {
208195 return Self :: SharePsbt {
209196 psbt_input : form:: Value :: default ( ) ,
210197 processing : false ,
@@ -277,12 +264,7 @@ impl SpendTransactionAction {
277264 SpendTxMessage :: UnselectDelete => {
278265 * self = Self :: new (
279266 ctx. managers_threshold ,
280- & ctx. config
281- . daemon
282- . manager_config
283- . as_ref ( )
284- . expect ( "User is a manager" )
285- . xpub ,
267+ ctx. user_signed ( psbt) ,
286268 & ctx. managers_xpubs ( ) ,
287269 psbt,
288270 ) ;
@@ -320,12 +302,7 @@ impl SpendTransactionAction {
320302 * psbt = signer. target . spend_tx . clone ( ) ;
321303 * self = Self :: new (
322304 ctx. managers_threshold ,
323- & ctx. config
324- . daemon
325- . manager_config
326- . as_ref ( )
327- . expect ( "User is a manager" )
328- . xpub ,
305+ true ,
329306 & ctx. managers_xpubs ( ) ,
330307 psbt,
331308 ) ;
@@ -599,7 +576,7 @@ mod tests {
599576 let mut psbt = Psbt :: from_str ( "cHNidP8BALQCAAAAAc1946BSKWX5trghNlBq/IIYScLPYqr9Bqs2LfqOYuqcAAAAAAAIAAAAA+BAAAAAAAAAIgAgCOQxrx6W/t0dSZikMBNYG2Yyam/3LIoVrAy6e8ZDUAyA8PoCAAAAACIAIMuwqNTx88KHHtIR0EeURzEu9pUmbnUxd22KzYKi25A2CBH6AgAAAAAiACB18mkXdMgWd4MYRrAoIgDiiLLFlxC1j3Qxg9SSVQfbxQAAAAAAAQEruFn1BQAAAAAiACBI6M9l6zams92tyCK/4gbWyNfJMJzgoOv34L0X7GTovAEDBAEAAAABBWEhAgKTOrEDfq0KpKeFjG1J1nBeH7O8X2awCRive58A7NUmrFGHZHapFHKpXyKvmhuuuFL5qVJy+MIdmPJkiKxrdqkUtsmtuJyMk3Jsg+KhtdlHidd7lWGIrGyTUodnWLJoIgYCApM6sQN+rQqkp4WMbUnWcF4fs7xfZrAJGK97nwDs1SYIJR1gCQAAAAAAIgICUHL04HZXilyJ1B118e1Smr+S8c1qtja46Le7DzMCaUMI+93szQAAAAAAACICAlgt7b9E9GVk5djNsGdTbWDr40zR0YAc/1G7+desKJtDCNZ9f+kAAAAAIgIDRwTey1W1qoj/0e9dBjZiSMExThllURNv8U6ri7pKSQ4IcqlfIgAAAAAA" ) . unwrap ( ) ;
600577 let user_manager_xpub = ExtendedPubKey :: from_str ( "xpub6CZFHPW1GiB8YgV7zGpeQDB6mMHZYPQyUaHrM1nMvKMgLxwok4xCtnzjuxQ3p1LHJUkz5i1Y7bRy5fmGrdg8UBVb39XdXNtWWd2wTsNd7T9" ) . unwrap ( ) ;
601578
602- let action = SpendTransactionAction :: new ( 2 , & user_manager_xpub , & Vec :: new ( ) , & psbt) ;
579+ let action = SpendTransactionAction :: new ( 2 , false , & Vec :: new ( ) , & psbt) ;
603580 assert ! ( matches!( action, SpendTransactionAction :: Sign { .. } ) ) ;
604581
605582 psbt. inputs [ 0 ] . partial_sigs . insert (
@@ -610,13 +587,13 @@ mod tests {
610587 "304402202f5eec50f34929e4bd8f6b7e81426795b0cd3608a4dad53ffab3e7af38ab627a02204ff61d9df2432ff3272c17d9baee1ec6b6dcb72b198be7f4ef843d5d47010a0401" . as_bytes ( ) . to_vec ( ) ,
611588 ) ;
612589
613- let action = SpendTransactionAction :: new ( 2 , & user_manager_xpub , & Vec :: new ( ) , & psbt) ;
590+ let action = SpendTransactionAction :: new ( 2 , true , & Vec :: new ( ) , & psbt) ;
614591 assert ! ( matches!( action, SpendTransactionAction :: SharePsbt { .. } ) ) ;
615592
616- let action = SpendTransactionAction :: new ( 1 , & user_manager_xpub , & Vec :: new ( ) , & psbt) ;
593+ let action = SpendTransactionAction :: new ( 1 , true , & Vec :: new ( ) , & psbt) ;
617594 assert ! ( matches!( action, SpendTransactionAction :: Broadcast { .. } ) ) ;
618595
619- let action = SpendTransactionAction :: new ( 0 , & user_manager_xpub , & Vec :: new ( ) , & psbt) ;
596+ let action = SpendTransactionAction :: new ( 0 , true , & Vec :: new ( ) , & psbt) ;
620597 assert ! ( matches!( action, SpendTransactionAction :: Broadcast { .. } ) ) ;
621598 }
622599}
0 commit comments