11use bdk_chain:: keychain_txout:: DEFAULT_LOOKAHEAD ;
2+ use bdk_chain:: miniscript:: descriptor:: KeyMapWrapper ;
23use serde_json:: json;
34use std:: cmp;
4- use std:: collections:: HashMap ;
55use std:: env;
66use std:: fmt;
77use std:: str:: FromStr ;
@@ -11,11 +11,10 @@ use anyhow::bail;
1111use anyhow:: Context ;
1212use bdk_chain:: bitcoin:: {
1313 absolute, address:: NetworkUnchecked , bip32, consensus, constants, hex:: DisplayHex , relative,
14- secp256k1:: Secp256k1 , transaction, Address , Amount , Network , NetworkKind , PrivateKey , Psbt ,
15- PublicKey , Sequence , Transaction , TxIn , TxOut ,
14+ secp256k1:: Secp256k1 , transaction, Address , Amount , Network , NetworkKind , Psbt , Sequence ,
15+ Transaction , TxIn , TxOut ,
1616} ;
1717use bdk_chain:: miniscript:: {
18- descriptor:: { DescriptorSecretKey , SinglePubKey } ,
1918 plan:: { Assets , Plan } ,
2019 psbt:: PsbtExt ,
2120 Descriptor , DescriptorPublicKey , ForEachKey ,
@@ -696,27 +695,15 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
696695
697696 let secp = Secp256k1 :: new ( ) ;
698697 let ( _, keymap) = Descriptor :: parse_descriptor ( & secp, & desc_str) ?;
698+
699699 if keymap. is_empty ( ) {
700700 bail ! ( "unable to sign" )
701701 }
702702
703- // note: we're only looking at the first entry in the keymap
704- // the idea is to find something that impls `GetKey`
705- let sign_res = match keymap. iter ( ) . next ( ) . expect ( "not empty" ) {
706- ( DescriptorPublicKey :: Single ( single_pub) , DescriptorSecretKey :: Single ( prv) ) => {
707- let pk = match single_pub. key {
708- SinglePubKey :: FullKey ( pk) => pk,
709- SinglePubKey :: XOnly ( _) => unimplemented ! ( "single xonly pubkey" ) ,
710- } ;
711- let keys: HashMap < PublicKey , PrivateKey > = [ ( pk, prv. key ) ] . into ( ) ;
712- psbt. sign ( & keys, & secp)
713- }
714- ( _, DescriptorSecretKey :: XPrv ( k) ) => psbt. sign ( & k. xkey , & secp) ,
715- _ => unimplemented ! ( "multi xkey signer" ) ,
716- } ;
717-
718- let _ =
719- sign_res. map_err ( |errors| anyhow:: anyhow!( "failed to sign PSBT {errors:?}" ) ) ?;
703+ let keymap_wrapper: KeyMapWrapper = keymap. into ( ) ;
704+ let _sign_res = psbt
705+ . sign ( & keymap_wrapper, & secp)
706+ . map_err ( |errors| anyhow:: anyhow!( "failed to sign PSBT {errors:?}" ) ) ?;
720707
721708 let mut obj = serde_json:: Map :: new ( ) ;
722709 obj. insert ( "psbt" . to_string ( ) , json ! ( psbt. to_string( ) ) ) ;
0 commit comments