Skip to content

Commit 8edfcb7

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 7c28c5f commit 8edfcb7

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

@@ -604,8 +604,8 @@ impl Wallet {
604604
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
605605
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
606606
keychain: KeychainKind::External,
607-
loaded: Some(descriptor),
608-
expected: Some(exp_desc),
607+
loaded: Some(Box::new(descriptor)),
608+
expected: Some(Box::new(exp_desc)),
609609
}));
610610
}
611611
if params.extract_keys {
@@ -614,7 +614,7 @@ impl Wallet {
614614
} else {
615615
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
616616
keychain: KeychainKind::External,
617-
loaded: Some(descriptor),
617+
loaded: Some(Box::new(descriptor)),
618618
expected: None,
619619
}));
620620
}
@@ -635,7 +635,7 @@ impl Wallet {
635635
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
636636
keychain: KeychainKind::Internal,
637637
loaded: None,
638-
expected: Some(exp_desc),
638+
expected: Some(Box::new(exp_desc)),
639639
}));
640640
}
641641
}
@@ -649,7 +649,7 @@ impl Wallet {
649649
None => {
650650
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
651651
keychain: KeychainKind::Internal,
652-
loaded: Some(desc),
652+
loaded: Some(Box::new(desc)),
653653
expected: None,
654654
}))
655655
}
@@ -661,8 +661,8 @@ impl Wallet {
661661
if desc.descriptor_id() != exp_desc.descriptor_id() {
662662
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
663663
keychain: KeychainKind::Internal,
664-
loaded: Some(desc),
665-
expected: Some(exp_desc),
664+
loaded: Some(Box::new(desc)),
665+
expected: Some(Box::new(exp_desc)),
666666
}));
667667
}
668668
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
@@ -422,7 +422,7 @@ fn single_descriptor_wallet_persist_and_recover() {
422422
assert_matches!(
423423
err,
424424
Err(LoadWithPersistError::InvalidChangeSet(LoadError::Mismatch(LoadMismatch::Descriptor { keychain, loaded, expected })))
425-
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(exp_desc),
425+
if keychain == KeychainKind::Internal && loaded.is_none() && expected == Some(Box::new(exp_desc)),
426426
"single descriptor wallet should refuse change descriptor param"
427427
);
428428
}

0 commit comments

Comments
 (0)