@@ -67,7 +67,7 @@ use crate::descriptor::{
6767 calc_checksum, into_wallet_descriptor_checked, DerivedDescriptor , DescriptorMeta ,
6868 ExtendedDescriptor , ExtractPolicy , IntoWalletDescriptor , Policy , XKeyUtils ,
6969} ;
70- use crate :: error:: { BuildFeeBumpError , CreateTxError , Error , MiniscriptPsbtError } ;
70+ use crate :: error:: { BuildFeeBumpError , CreateTxError , Error , MiniscriptPsbtError , SignError } ;
7171use crate :: psbt:: PsbtUtils ;
7272use crate :: signer:: SignerError ;
7373use crate :: types:: * ;
@@ -1702,27 +1702,28 @@ impl<D> Wallet<D> {
17021702 /// # use bitcoin::*;
17031703 /// # use bdk::*;
17041704 /// # use bdk::wallet::ChangeSet;
1705- /// # use bdk::error::CreateTxError;
1705+ /// # use bdk::error::{ CreateTxError, SignError} ;
17061706 /// # use bdk_chain::PersistBackend;
17071707 /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
17081708 /// # let mut wallet = doctest_wallet!();
17091709 /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
17101710 /// let mut psbt = {
17111711 /// let mut builder = wallet.build_tx();
17121712 /// builder.add_recipient(to_address.script_pubkey(), 50_000);
1713- /// builder.finish().expect("psbt")
1713+ /// builder.finish()?
17141714 /// };
17151715 /// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
17161716 /// assert!(finalized, "we should have signed all the inputs");
1717- /// # Ok::<(), bdk ::Error>(())
1717+ /// # Ok::<(),anyhow ::Error>(())
17181718 pub fn sign (
17191719 & self ,
17201720 psbt : & mut psbt:: PartiallySignedTransaction ,
17211721 sign_options : SignOptions ,
1722- ) -> Result < bool , Error > {
1722+ ) -> Result < bool , SignError > {
17231723 // This adds all the PSBT metadata for the inputs, which will help us later figure out how
17241724 // to derive our keys
1725- self . update_psbt_with_descriptor ( psbt) ?;
1725+ self . update_psbt_with_descriptor ( psbt)
1726+ . map_err ( SignError :: MiniscriptPsbt ) ?;
17261727
17271728 // If we aren't allowed to use `witness_utxo`, ensure that every input (except p2tr and finalized ones)
17281729 // has the `non_witness_utxo`
@@ -1734,7 +1735,7 @@ impl<D> Wallet<D> {
17341735 . filter ( |i| i. tap_internal_key . is_none ( ) && i. tap_merkle_root . is_none ( ) )
17351736 . any ( |i| i. non_witness_utxo . is_none ( ) )
17361737 {
1737- return Err ( Error :: Signer ( signer :: SignerError :: MissingNonWitnessUtxo ) ) ;
1738+ return Err ( SignError :: Signer ( SignerError :: MissingNonWitnessUtxo ) ) ;
17381739 }
17391740
17401741 // If the user hasn't explicitly opted-in, refuse to sign the transaction unless every input
@@ -1747,7 +1748,7 @@ impl<D> Wallet<D> {
17471748 || i. sighash_type == Some ( TapSighashType :: Default . into ( ) )
17481749 } )
17491750 {
1750- return Err ( Error :: Signer ( signer :: SignerError :: NonStandardSighash ) ) ;
1751+ return Err ( SignError :: Signer ( SignerError :: NonStandardSighash ) ) ;
17511752 }
17521753
17531754 for signer in self
@@ -1756,7 +1757,9 @@ impl<D> Wallet<D> {
17561757 . iter ( )
17571758 . chain ( self . change_signers . signers ( ) . iter ( ) )
17581759 {
1759- signer. sign_transaction ( psbt, & sign_options, & self . secp ) ?;
1760+ signer
1761+ . sign_transaction ( psbt, & sign_options, & self . secp )
1762+ . map_err ( SignError :: Signer ) ?;
17601763 }
17611764
17621765 // attempt to finalize
@@ -1800,8 +1803,8 @@ impl<D> Wallet<D> {
18001803 & self ,
18011804 psbt : & mut psbt:: PartiallySignedTransaction ,
18021805 sign_options : SignOptions ,
1803- ) -> Result < bool , Error > {
1804- let chain_tip = self . chain . tip ( ) . block_id ( ) ;
1806+ ) -> Result < bool , SignerError > {
1807+ let chain_tip = self . chain . tip ( ) . map ( |cp| cp . block_id ( ) ) . unwrap_or_default ( ) ;
18051808
18061809 let tx = & psbt. unsigned_tx ;
18071810 let mut finished = true ;
@@ -1810,7 +1813,7 @@ impl<D> Wallet<D> {
18101813 let psbt_input = & psbt
18111814 . inputs
18121815 . get ( n)
1813- . ok_or ( Error :: Signer ( SignerError :: InputIndexOutOfRange ) ) ?;
1816+ . ok_or ( SignerError :: Signer ( SignerError :: InputIndexOutOfRange ) ) ?;
18141817 if psbt_input. final_script_sig . is_some ( ) || psbt_input. final_script_witness . is_some ( ) {
18151818 continue ;
18161819 }
0 commit comments