@@ -40,8 +40,8 @@ use bitcoin::{
4040 psbt,
4141 secp256k1:: Secp256k1 ,
4242 sighash:: { EcdsaSighashType , TapSighashType } ,
43- transaction, Address , Amount , Block , BlockHash , FeeRate , Network , NetworkKind , OutPoint , Psbt ,
44- ScriptBuf , Sequence , SignedAmount , Transaction , TxOut , Txid , Weight , Witness ,
43+ transaction, Address , Amount , Block , FeeRate , Network , NetworkKind , OutPoint , Psbt , ScriptBuf ,
44+ Sequence , SignedAmount , Transaction , TxOut , Txid , Weight , Witness ,
4545} ;
4646use miniscript:: {
4747 descriptor:: KeyMap ,
@@ -80,6 +80,7 @@ use crate::wallet::{
8080// re-exports
8181pub use bdk_chain:: Balance ;
8282pub use changeset:: ChangeSet ;
83+ pub use error:: { ApplyBlockError , LoadError , LoadMismatch } ;
8384pub use event:: * ;
8485pub use params:: * ;
8586pub use persisted:: * ;
@@ -177,143 +178,6 @@ impl fmt::Display for AddressInfo {
177178 }
178179}
179180
180- /// The error type when loading a [`Wallet`] from a [`ChangeSet`].
181- #[ derive( Debug , PartialEq ) ]
182- pub enum LoadError {
183- /// There was a problem with the passed-in descriptor(s).
184- Descriptor ( crate :: descriptor:: DescriptorError ) ,
185- /// Data loaded from persistence is missing network type.
186- MissingNetwork ,
187- /// Data loaded from persistence is missing genesis hash.
188- MissingGenesis ,
189- /// Data loaded from persistence is missing descriptor.
190- MissingDescriptor ( KeychainKind ) ,
191- /// Data loaded is unexpected.
192- Mismatch ( LoadMismatch ) ,
193- }
194-
195- impl fmt:: Display for LoadError {
196- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
197- match self {
198- LoadError :: Descriptor ( e) => e. fmt ( f) ,
199- LoadError :: MissingNetwork => write ! ( f, "loaded data is missing network type" ) ,
200- LoadError :: MissingGenesis => write ! ( f, "loaded data is missing genesis hash" ) ,
201- LoadError :: MissingDescriptor ( k) => {
202- write ! ( f, "loaded data is missing descriptor for {k} keychain" )
203- }
204- LoadError :: Mismatch ( e) => write ! ( f, "{e}" ) ,
205- }
206- }
207- }
208-
209- #[ cfg( feature = "std" ) ]
210- impl std:: error:: Error for LoadError { }
211-
212- /// Represents a mismatch with what is loaded and what is expected from [`LoadParams`].
213- #[ derive( Debug , PartialEq ) ]
214- pub enum LoadMismatch {
215- /// Network does not match.
216- Network {
217- /// The network that is loaded.
218- loaded : Network ,
219- /// The expected network.
220- expected : Network ,
221- } ,
222- /// Genesis hash does not match.
223- Genesis {
224- /// The genesis hash that is loaded.
225- loaded : BlockHash ,
226- /// The expected genesis hash.
227- expected : BlockHash ,
228- } ,
229- /// Descriptor's [`DescriptorId`](bdk_chain::DescriptorId) does not match.
230- Descriptor {
231- /// Keychain identifying the descriptor.
232- keychain : KeychainKind ,
233- /// The loaded descriptor.
234- loaded : Option < Box < ExtendedDescriptor > > ,
235- /// The expected descriptor.
236- expected : Option < Box < ExtendedDescriptor > > ,
237- } ,
238- }
239-
240- impl fmt:: Display for LoadMismatch {
241- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
242- match self {
243- LoadMismatch :: Network { loaded, expected } => {
244- write ! ( f, "Network mismatch: loaded {loaded}, expected {expected}" )
245- }
246- LoadMismatch :: Genesis { loaded, expected } => {
247- write ! (
248- f,
249- "Genesis hash mismatch: loaded {loaded}, expected {expected}"
250- )
251- }
252- LoadMismatch :: Descriptor {
253- keychain,
254- loaded,
255- expected,
256- } => {
257- write ! (
258- f,
259- "Descriptor mismatch for {} keychain: loaded {}, expected {}" ,
260- keychain,
261- loaded
262- . as_ref( )
263- . map_or( "None" . to_string( ) , |d| d. to_string( ) ) ,
264- expected
265- . as_ref( )
266- . map_or( "None" . to_string( ) , |d| d. to_string( ) )
267- )
268- }
269- }
270- }
271- }
272-
273- impl From < LoadMismatch > for LoadError {
274- fn from ( mismatch : LoadMismatch ) -> Self {
275- Self :: Mismatch ( mismatch)
276- }
277- }
278-
279- impl < E > From < LoadMismatch > for LoadWithPersistError < E > {
280- fn from ( mismatch : LoadMismatch ) -> Self {
281- Self :: InvalidChangeSet ( LoadError :: Mismatch ( mismatch) )
282- }
283- }
284-
285- /// An error that may occur when applying a block to [`Wallet`].
286- #[ derive( Debug ) ]
287- pub enum ApplyBlockError {
288- /// Occurs when the update chain cannot connect with original chain.
289- CannotConnect ( CannotConnectError ) ,
290- /// Occurs when the `connected_to` hash does not match the hash derived from `block`.
291- UnexpectedConnectedToHash {
292- /// Block hash of `connected_to`.
293- connected_to_hash : BlockHash ,
294- /// Expected block hash of `connected_to`, as derived from `block`.
295- expected_hash : BlockHash ,
296- } ,
297- }
298-
299- impl fmt:: Display for ApplyBlockError {
300- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
301- match self {
302- ApplyBlockError :: CannotConnect ( err) => err. fmt ( f) ,
303- ApplyBlockError :: UnexpectedConnectedToHash {
304- expected_hash : block_hash,
305- connected_to_hash : checkpoint_hash,
306- } => write ! (
307- f,
308- "`connected_to` hash {checkpoint_hash} differs from the expected hash {block_hash} (which is derived from `block`)"
309- ) ,
310- }
311- }
312- }
313-
314- #[ cfg( feature = "std" ) ]
315- impl std:: error:: Error for ApplyBlockError { }
316-
317181/// A `CanonicalTx` managed by a `Wallet`.
318182pub type WalletTx < ' a > = CanonicalTx < ' a , Arc < Transaction > , ConfirmationBlockTime > ;
319183
0 commit comments