@@ -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:: * ;
@@ -1430,27 +1430,28 @@ impl<D> Wallet<D> {
14301430 /// # use bitcoin::*;
14311431 /// # use bdk::*;
14321432 /// # use bdk::wallet::ChangeSet;
1433- /// # use bdk::error::CreateTxError;
1433+ /// # use bdk::error::{ CreateTxError, SignError} ;
14341434 /// # use bdk_chain::PersistBackend;
14351435 /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
14361436 /// # let mut wallet = doctest_wallet!();
14371437 /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked();
14381438 /// let mut psbt = {
14391439 /// let mut builder = wallet.build_tx();
14401440 /// builder.add_recipient(to_address.script_pubkey(), 50_000);
1441- /// builder.finish().expect("psbt")
1441+ /// builder.finish()?
14421442 /// };
14431443 /// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
14441444 /// assert!(finalized, "we should have signed all the inputs");
1445- /// # Ok::<(), bdk ::Error>(())
1445+ /// # Ok::<(),anyhow ::Error>(())
14461446 pub fn sign (
14471447 & self ,
14481448 psbt : & mut psbt:: PartiallySignedTransaction ,
14491449 sign_options : SignOptions ,
1450- ) -> Result < bool , Error > {
1450+ ) -> Result < bool , SignError > {
14511451 // This adds all the PSBT metadata for the inputs, which will help us later figure out how
14521452 // to derive our keys
1453- self . update_psbt_with_descriptor ( psbt) ?;
1453+ self . update_psbt_with_descriptor ( psbt)
1454+ . map_err ( SignError :: MiniscriptPsbt ) ?;
14541455
14551456 // If we aren't allowed to use `witness_utxo`, ensure that every input (except p2tr and finalized ones)
14561457 // has the `non_witness_utxo`
@@ -1462,7 +1463,7 @@ impl<D> Wallet<D> {
14621463 . filter ( |i| i. tap_internal_key . is_none ( ) && i. tap_merkle_root . is_none ( ) )
14631464 . any ( |i| i. non_witness_utxo . is_none ( ) )
14641465 {
1465- return Err ( Error :: Signer ( signer :: SignerError :: MissingNonWitnessUtxo ) ) ;
1466+ return Err ( SignError :: Signer ( SignerError :: MissingNonWitnessUtxo ) ) ;
14661467 }
14671468
14681469 // If the user hasn't explicitly opted-in, refuse to sign the transaction unless every input
@@ -1475,7 +1476,7 @@ impl<D> Wallet<D> {
14751476 || i. sighash_type == Some ( TapSighashType :: Default . into ( ) )
14761477 } )
14771478 {
1478- return Err ( Error :: Signer ( signer :: SignerError :: NonStandardSighash ) ) ;
1479+ return Err ( SignError :: Signer ( SignerError :: NonStandardSighash ) ) ;
14791480 }
14801481
14811482 for signer in self
@@ -1484,7 +1485,9 @@ impl<D> Wallet<D> {
14841485 . iter ( )
14851486 . chain ( self . change_signers . signers ( ) . iter ( ) )
14861487 {
1487- signer. sign_transaction ( psbt, & sign_options, & self . secp ) ?;
1488+ signer
1489+ . sign_transaction ( psbt, & sign_options, & self . secp )
1490+ . map_err ( SignError :: Signer ) ?;
14881491 }
14891492
14901493 // attempt to finalize
@@ -1528,7 +1531,7 @@ impl<D> Wallet<D> {
15281531 & self ,
15291532 psbt : & mut psbt:: PartiallySignedTransaction ,
15301533 sign_options : SignOptions ,
1531- ) -> Result < bool , Error > {
1534+ ) -> Result < bool , SignError > {
15321535 let chain_tip = self . chain . tip ( ) . map ( |cp| cp. block_id ( ) ) . unwrap_or_default ( ) ;
15331536
15341537 let tx = & psbt. unsigned_tx ;
@@ -1538,7 +1541,7 @@ impl<D> Wallet<D> {
15381541 let psbt_input = & psbt
15391542 . inputs
15401543 . get ( n)
1541- . ok_or ( Error :: Signer ( SignerError :: InputIndexOutOfRange ) ) ?;
1544+ . ok_or ( SignError :: Signer ( SignerError :: InputIndexOutOfRange ) ) ?;
15421545 if psbt_input. final_script_sig . is_some ( ) || psbt_input. final_script_witness . is_some ( ) {
15431546 continue ;
15441547 }
0 commit comments