@@ -16,32 +16,9 @@ use crate::descriptor::DescriptorError;
1616use crate :: wallet:: coin_selection;
1717use crate :: { descriptor, wallet, FeeRate , KeychainKind } ;
1818use alloc:: string:: String ;
19- use bitcoin:: { absolute, psbt, OutPoint , Sequence , Txid } ;
19+ use bitcoin:: { absolute, psbt, OutPoint , ScriptBuf , Sequence , Txid } ;
2020use core:: fmt;
2121
22- /// Old catch-all errors enum that can be thrown by the [`Wallet`](crate::wallet::Wallet)
23- #[ derive( Debug ) ]
24- pub enum Error {
25- /// Generic error
26- Generic ( String ) ,
27- /// Happens when trying to spend an UTXO that is not in the internal database
28- UnknownUtxo ,
29- /// Node doesn't have data to estimate a fee rate
30- FeeRateUnavailable ,
31- /// Error while working with [`keys`](crate::keys)
32- Key ( crate :: keys:: KeyError ) ,
33- /// Descriptor checksum mismatch
34- ChecksumMismatch ,
35- /// Requested outpoint doesn't exist in the tx (vout greater than available outputs)
36- InvalidOutpoint ( OutPoint ) ,
37- /// Error related to the parsing and usage of descriptors
38- Descriptor ( crate :: descriptor:: error:: Error ) ,
39- /// Miniscript error
40- Miniscript ( miniscript:: Error ) ,
41- /// BIP32 error
42- Bip32 ( bitcoin:: bip32:: Error ) ,
43- }
44-
4522/// Errors returned by miniscript when updating inconsistent PSBTs
4623#[ derive( Debug , Clone ) ]
4724pub enum MiniscriptPsbtError {
@@ -66,30 +43,6 @@ impl fmt::Display for MiniscriptPsbtError {
6643#[ cfg( feature = "std" ) ]
6744impl std:: error:: Error for MiniscriptPsbtError { }
6845
69- #[ cfg( feature = "std" ) ]
70- impl fmt:: Display for Error {
71- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
72- match self {
73- Self :: Generic ( err) => write ! ( f, "Generic error: {}" , err) ,
74- Self :: UnknownUtxo => write ! ( f, "UTXO not found in the internal database" ) ,
75- Self :: FeeRateUnavailable => write ! ( f, "Fee rate unavailable" ) ,
76- Self :: Key ( err) => write ! ( f, "Key error: {}" , err) ,
77- Self :: ChecksumMismatch => write ! ( f, "Descriptor checksum mismatch" ) ,
78- Self :: InvalidOutpoint ( outpoint) => write ! (
79- f,
80- "Requested outpoint doesn't exist in the tx: {}" ,
81- outpoint
82- ) ,
83- Self :: Descriptor ( err) => write ! ( f, "Descriptor error: {}" , err) ,
84- Self :: Miniscript ( err) => write ! ( f, "Miniscript error: {}" , err) ,
85- Self :: Bip32 ( err) => write ! ( f, "BIP32 error: {}" , err) ,
86- }
87- }
88- }
89-
90- #[ cfg( feature = "std" ) ]
91- impl std:: error:: Error for Error { }
92-
9346macro_rules! impl_error {
9447 ( $from: ty, $to: ident ) => {
9548 impl_error!( $from, $to, Error ) ;
@@ -103,22 +56,6 @@ macro_rules! impl_error {
10356 } ;
10457}
10558
106- impl_error ! ( descriptor:: error:: Error , Descriptor ) ;
107-
108- impl From < crate :: keys:: KeyError > for Error {
109- fn from ( key_error : crate :: keys:: KeyError ) -> Error {
110- match key_error {
111- crate :: keys:: KeyError :: Miniscript ( inner) => Error :: Miniscript ( inner) ,
112- crate :: keys:: KeyError :: Bip32 ( inner) => Error :: Bip32 ( inner) ,
113- crate :: keys:: KeyError :: InvalidChecksum => Error :: ChecksumMismatch ,
114- e => Error :: Key ( e) ,
115- }
116- }
117- }
118-
119- impl_error ! ( miniscript:: Error , Miniscript ) ;
120- impl_error ! ( bitcoin:: bip32:: Error , Bip32 ) ;
121-
12259#[ derive( Debug ) ]
12360/// Error returned from [`TxBuilder::finish`]
12461///
@@ -330,25 +267,13 @@ impl<P: core::fmt::Display + core::fmt::Debug> std::error::Error for CreateTxErr
330267/// [`Wallet::build_fee_bump`]: wallet::Wallet::build_fee_bump
331268pub enum BuildFeeBumpError {
332269 /// Happens when trying to spend an UTXO that is not in the internal database
333- UnknownUtxo {
334- /// The outpoint of the missing UTXO
335- outpoint : OutPoint ,
336- } ,
270+ UnknownUtxo ( OutPoint ) ,
337271 /// Thrown when a tx is not found in the internal database
338- TransactionNotFound {
339- /// The txid of the missing transaction
340- txid : Txid ,
341- } ,
272+ TransactionNotFound ( Txid ) ,
342273 /// Happens when trying to bump a transaction that is already confirmed
343- TransactionConfirmed {
344- /// The txid of the already confirmed transaction
345- txid : Txid ,
346- } ,
274+ TransactionConfirmed ( Txid ) ,
347275 /// Trying to replace a tx that has a sequence >= `0xFFFFFFFE`
348- IrreplaceableTransaction {
349- /// The txid of the irreplaceable transaction
350- txid : Txid ,
351- } ,
276+ IrreplaceableTransaction ( Txid ) ,
352277 /// Node doesn't have data to estimate a fee rate
353278 FeeRateUnavailable ,
354279}
@@ -357,22 +282,22 @@ pub enum BuildFeeBumpError {
357282impl fmt:: Display for BuildFeeBumpError {
358283 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
359284 match self {
360- Self :: UnknownUtxo { outpoint } => write ! (
285+ Self :: UnknownUtxo ( outpoint) => write ! (
361286 f,
362287 "UTXO not found in the internal database with txid: {}, vout: {}" ,
363288 outpoint. txid, outpoint. vout
364289 ) ,
365- Self :: TransactionNotFound { txid } => {
290+ Self :: TransactionNotFound ( txid) => {
366291 write ! (
367292 f,
368293 "Transaction not found in the internal database with txid: {}" ,
369294 txid
370295 )
371296 }
372- Self :: TransactionConfirmed { txid } => {
297+ Self :: TransactionConfirmed ( txid) => {
373298 write ! ( f, "Transaction already confirmed with txid: {}" , txid)
374299 }
375- Self :: IrreplaceableTransaction { txid } => {
300+ Self :: IrreplaceableTransaction ( txid) => {
376301 write ! ( f, "Transaction can't be replaced with txid: {}" , txid)
377302 }
378303 Self :: FeeRateUnavailable => write ! ( f, "Fee rate unavailable" ) ,
@@ -406,3 +331,98 @@ impl fmt::Display for SignError {
406331
407332#[ cfg( feature = "std" ) ]
408333impl std:: error:: Error for SignError { }
334+
335+ #[ derive( Debug ) ]
336+ /// Error returned from [`TxBuilder::add_utxo`] and [`TxBuilder::add_utxos`]
337+ ///
338+ /// [`TxBuilder::add_utxo`]: wallet::tx_builder::TxBuilder::add_utxo
339+ /// [`TxBuilder::add_utxos`]: wallet::tx_builder::TxBuilder::add_utxos
340+ pub enum AddUtxoError {
341+ /// Happens when trying to spend an UTXO that is not in the internal database
342+ UnknownUtxo ( OutPoint ) ,
343+ }
344+
345+ #[ cfg( feature = "std" ) ]
346+ impl fmt:: Display for AddUtxoError {
347+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
348+ match self {
349+ Self :: UnknownUtxo ( outpoint) => write ! (
350+ f,
351+ "UTXO not found in the internal database for txid: {} with vout: {}" ,
352+ outpoint. txid, outpoint. vout
353+ ) ,
354+ }
355+ }
356+ }
357+
358+ #[ cfg( feature = "std" ) ]
359+ impl std:: error:: Error for AddUtxoError { }
360+
361+ #[ derive( Debug ) ]
362+ /// Error returned from [`TxBuilder::add_utxo`] and [`TxBuilder::add_utxos`]
363+ ///
364+ /// [`TxBuilder::add_utxo`]: wallet::tx_builder::TxBuilder::add_utxo
365+ /// [`TxBuilder::add_utxos`]: wallet::tx_builder::TxBuilder::add_utxos
366+ pub enum AddForeignUtxoError {
367+ /// Foreign utxo outpoint txid does not match PSBT input txid
368+ InvalidTxid {
369+ /// PSBT input txid
370+ input_txid : Txid ,
371+ /// Foreign UTXO outpoint
372+ foreign_utxo : OutPoint ,
373+ } ,
374+ /// Requested outpoint doesn't exist in the tx (vout greater than available outputs)
375+ InvalidOutpoint ( OutPoint ) ,
376+ /// Foreign utxo missing witness_utxo or non_witness_utxo
377+ MissingUtxo ,
378+ }
379+
380+ #[ cfg( feature = "std" ) ]
381+ impl fmt:: Display for AddForeignUtxoError {
382+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
383+ match self {
384+ Self :: InvalidTxid {
385+ input_txid,
386+ foreign_utxo,
387+ } => write ! (
388+ f,
389+ "Foreign UTXO outpoint txid: {} does not match PSBT input txid: {}" ,
390+ foreign_utxo. txid, input_txid,
391+ ) ,
392+ Self :: InvalidOutpoint ( outpoint) => write ! (
393+ f,
394+ "Requested outpoint doesn't exist for txid: {} with vout: {}" ,
395+ outpoint. txid, outpoint. vout,
396+ ) ,
397+ Self :: MissingUtxo => write ! ( f, "Foreign utxo missing witness_utxo or non_witness_utxo" ) ,
398+ }
399+ }
400+ }
401+
402+ #[ cfg( feature = "std" ) ]
403+ impl std:: error:: Error for AddForeignUtxoError { }
404+
405+ #[ derive( Debug ) ]
406+ /// Error returned from [`TxBuilder::allow_shrinking`]
407+ ///
408+ /// [`TxBuilder::allow_shrinking`]: wallet::tx_builder::TxBuilder::allow_shrinking
409+ pub enum AllowShrinkingError {
410+ /// Script/PubKey was not in the original transaction
411+ MissingScriptPubKey ( ScriptBuf ) ,
412+ }
413+
414+ #[ cfg( feature = "std" ) ]
415+ impl fmt:: Display for AllowShrinkingError {
416+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
417+ match self {
418+ Self :: MissingScriptPubKey ( script_buf) => write ! (
419+ f,
420+ "Script/PubKey was not in the original transaction: {}" ,
421+ script_buf,
422+ ) ,
423+ }
424+ }
425+ }
426+
427+ #[ cfg( feature = "std" ) ]
428+ impl std:: error:: Error for AllowShrinkingError { }
0 commit comments