Skip to content

Commit 60ac667

Browse files
committed
clippy!: fix large enum variants
..by `Box`ing the descriptor in `LoadMismatch` enum, and by boxing the ChangeSet in `DataAlreadyExists` variant of `CreateWithPersistError`. We allow the large_enum_variant lint for `FileStoreError` for now, as it is planned to be fixed in a future version of `bdk_file_store`.
1 parent 223377e commit 60ac667

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#![no_std]
99
#![warn(missing_docs)]
1010
#![allow(clippy::uninlined_format_args)]
11-
// TODO: these can be removed after <https://github.com/bitcoindevkit/bdk_wallet/issues/245>
12-
#![allow(clippy::result_large_err)]
13-
#![allow(clippy::large_enum_variant)]
1411

1512
#[cfg(feature = "std")]
1613
#[macro_use]

src/wallet/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ pub enum LoadMismatch {
229229
/// Keychain identifying the descriptor.
230230
keychain: KeychainKind,
231231
/// The loaded descriptor.
232-
loaded: Option<ExtendedDescriptor>,
232+
loaded: Option<Box<ExtendedDescriptor>>,
233233
/// The expected descriptor.
234-
expected: Option<ExtendedDescriptor>,
234+
expected: Option<Box<ExtendedDescriptor>>,
235235
},
236236
}
237237

@@ -602,8 +602,8 @@ impl Wallet {
602602
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
603603
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
604604
keychain: KeychainKind::External,
605-
loaded: Some(descriptor),
606-
expected: Some(exp_desc),
605+
loaded: Some(Box::new(descriptor)),
606+
expected: Some(Box::new(exp_desc)),
607607
}));
608608
}
609609
if params.extract_keys {
@@ -612,7 +612,7 @@ impl Wallet {
612612
} else {
613613
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
614614
keychain: KeychainKind::External,
615-
loaded: Some(descriptor),
615+
loaded: Some(Box::new(descriptor)),
616616
expected: None,
617617
}));
618618
}
@@ -632,7 +632,7 @@ impl Wallet {
632632
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
633633
keychain: KeychainKind::Internal,
634634
loaded: None,
635-
expected: Some(exp_desc),
635+
expected: Some(Box::new(exp_desc)),
636636
}));
637637
}
638638
}
@@ -646,7 +646,7 @@ impl Wallet {
646646
None => {
647647
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
648648
keychain: KeychainKind::Internal,
649-
loaded: Some(desc),
649+
loaded: Some(Box::new(desc)),
650650
expected: None,
651651
}))
652652
}
@@ -658,8 +658,8 @@ impl Wallet {
658658
if desc.descriptor_id() != exp_desc.descriptor_id() {
659659
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
660660
keychain: KeychainKind::Internal,
661-
loaded: Some(desc),
662-
expected: Some(exp_desc),
661+
loaded: Some(Box::new(desc)),
662+
expected: Some(Box::new(exp_desc)),
663663
}));
664664
}
665665
if params.extract_keys {

src/wallet/persisted.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ impl<P: WalletPersister> PersistedWallet<P> {
150150
) -> Result<Self, CreateWithPersistError<P::Error>> {
151151
let existing = P::initialize(persister).map_err(CreateWithPersistError::Persist)?;
152152
if !existing.is_empty() {
153-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
153+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
154+
existing,
155+
)));
154156
}
155157
let mut inner =
156158
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -207,7 +209,9 @@ impl<P: AsyncWalletPersister> PersistedWallet<P> {
207209
.await
208210
.map_err(CreateWithPersistError::Persist)?;
209211
if !existing.is_empty() {
210-
return Err(CreateWithPersistError::DataAlreadyExists(existing));
212+
return Err(CreateWithPersistError::DataAlreadyExists(Box::new(
213+
existing,
214+
)));
211215
}
212216
let mut inner =
213217
Wallet::create_with_params(params).map_err(CreateWithPersistError::Descriptor)?;
@@ -293,6 +297,7 @@ impl WalletPersister for bdk_chain::rusqlite::Connection {
293297
/// Error for [`bdk_file_store`]'s implementation of [`WalletPersister`].
294298
#[cfg(feature = "file_store")]
295299
#[derive(Debug)]
300+
#[allow(clippy::large_enum_variant)]
296301
pub enum FileStoreError {
297302
/// Error when loading from the store.
298303
Load(bdk_file_store::StoreErrorWithDump<ChangeSet>),
@@ -357,7 +362,7 @@ pub enum CreateWithPersistError<E> {
357362
/// Error from persistence.
358363
Persist(E),
359364
/// Persister already has wallet data.
360-
DataAlreadyExists(ChangeSet),
365+
DataAlreadyExists(Box<ChangeSet>),
361366
/// Occurs when the loaded changeset cannot construct [`Wallet`].
362367
Descriptor(DescriptorError),
363368
}

tests/persisted_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn single_descriptor_wallet_persist_and_recover() {
421421
assert_matches!(
422422
err,
423423
Err(LoadWithPersistError::InvalidChangeSet(LoadError::Mismatch(LoadMismatch::Descriptor { keychain, loaded, expected })))
424-
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(exp_desc),
424+
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(Box::new(exp_desc)),
425425
"single descriptor wallet should refuse change descriptor param"
426426
);
427427
}

0 commit comments

Comments
 (0)