Skip to content

Commit aec4dda

Browse files
committed
chore: Remove LoadError::MissingDescriptor
Since we will have persisted descriptors for both keychains. This also means we're guaranteed to have gotten a descriptor in the case `LoadedDescriptorDoesNotMatch`.
1 parent 6074559 commit aec4dda

2 files changed

Lines changed: 7 additions & 15 deletions

File tree

crates/wallet/src/wallet/mod.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,6 @@ pub enum LoadError {
306306
MissingNetwork,
307307
/// Data loaded from persistence is missing genesis hash.
308308
MissingGenesis,
309-
/// Data loaded from persistence is missing descriptor.
310-
MissingDescriptor,
311309
}
312310

313311
impl fmt::Display for LoadError {
@@ -320,7 +318,6 @@ impl fmt::Display for LoadError {
320318
}
321319
LoadError::MissingNetwork => write!(f, "loaded data is missing network type"),
322320
LoadError::MissingGenesis => write!(f, "loaded data is missing genesis hash"),
323-
LoadError::MissingDescriptor => write!(f, "loaded data is missing descriptor"),
324321
}
325322
}
326323
}
@@ -359,8 +356,7 @@ pub enum NewOrLoadError {
359356
/// The loaded desccriptor does not match what was provided.
360357
LoadedDescriptorDoesNotMatch {
361358
/// The descriptor loaded from persistence.
362-
// TODO: this doesn't need to be Option. both external/internal are persisted
363-
got: Option<ExtendedDescriptor>,
359+
got: ExtendedDescriptor,
364360
/// The keychain of the descriptor not matching
365361
keychain: KeychainKind,
366362
},
@@ -582,14 +578,14 @@ impl Wallet {
582578
.indexer
583579
.keychains_added
584580
.get(&KeychainKind::External)
585-
.ok_or(LoadError::MissingDescriptor)?
581+
.expect("keychain must have been added")
586582
.clone();
587583
let change_descriptor = changeset
588584
.indexed_tx_graph
589585
.indexer
590586
.keychains_added
591587
.get(&KeychainKind::Internal)
592-
.ok_or(LoadError::MissingDescriptor)?
588+
.expect("keychain must have been added")
593589
.clone();
594590

595591
let (signers, change_signers) =
@@ -661,10 +657,6 @@ impl Wallet {
661657
expected: genesis_hash,
662658
got: None,
663659
},
664-
LoadError::MissingDescriptor => NewOrLoadError::LoadedDescriptorDoesNotMatch {
665-
got: None,
666-
keychain: KeychainKind::External,
667-
},
668660
})?;
669661
if wallet.network != network {
670662
return Err(NewOrLoadError::LoadedNetworkDoesNotMatch {
@@ -685,7 +677,7 @@ impl Wallet {
685677
let wallet_descriptor = wallet.public_descriptor(KeychainKind::External);
686678
if wallet_descriptor != &expected_descriptor {
687679
return Err(NewOrLoadError::LoadedDescriptorDoesNotMatch {
688-
got: Some(wallet_descriptor.clone()),
680+
got: wallet_descriptor.clone(),
689681
keychain: KeychainKind::External,
690682
});
691683
}
@@ -712,7 +704,7 @@ impl Wallet {
712704
let wallet_change_descriptor = wallet.public_descriptor(KeychainKind::Internal);
713705
if wallet_change_descriptor != &expected_change_descriptor {
714706
return Err(NewOrLoadError::LoadedDescriptorDoesNotMatch {
715-
got: Some(wallet_change_descriptor.clone()),
707+
got: wallet_change_descriptor.clone(),
716708
keychain: KeychainKind::Internal,
717709
});
718710
}

crates/wallet/tests/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ fn new_or_load() {
191191
matches!(
192192
err,
193193
bdk_wallet::wallet::NewOrLoadError::LoadedDescriptorDoesNotMatch { ref got, keychain }
194-
if got == &Some(got_descriptor) && keychain == KeychainKind::External
194+
if got == &got_descriptor && keychain == KeychainKind::External
195195
),
196196
"err: {}",
197197
err,
@@ -214,7 +214,7 @@ fn new_or_load() {
214214
matches!(
215215
err,
216216
bdk_wallet::wallet::NewOrLoadError::LoadedDescriptorDoesNotMatch { ref got, keychain }
217-
if got == &Some(got_descriptor) && keychain == KeychainKind::Internal
217+
if got == &got_descriptor && keychain == KeychainKind::Internal
218218
),
219219
"err: {}",
220220
err,

0 commit comments

Comments
 (0)