Skip to content

Commit d020559

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 ff74e59 commit d020559

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

wallet/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]

wallet/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

@@ -600,8 +600,8 @@ impl Wallet {
600600
if descriptor.descriptor_id() != exp_desc.descriptor_id() {
601601
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
602602
keychain: KeychainKind::External,
603-
loaded: Some(descriptor),
604-
expected: Some(exp_desc),
603+
loaded: Some(Box::new(descriptor)),
604+
expected: Some(Box::new(exp_desc)),
605605
}));
606606
}
607607
if params.extract_keys {
@@ -610,7 +610,7 @@ impl Wallet {
610610
} else {
611611
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
612612
keychain: KeychainKind::External,
613-
loaded: Some(descriptor),
613+
loaded: Some(Box::new(descriptor)),
614614
expected: None,
615615
}));
616616
}
@@ -630,7 +630,7 @@ impl Wallet {
630630
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
631631
keychain: KeychainKind::Internal,
632632
loaded: None,
633-
expected: Some(exp_desc),
633+
expected: Some(Box::new(exp_desc)),
634634
}));
635635
}
636636
}
@@ -644,7 +644,7 @@ impl Wallet {
644644
None => {
645645
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
646646
keychain: KeychainKind::Internal,
647-
loaded: Some(desc),
647+
loaded: Some(Box::new(desc)),
648648
expected: None,
649649
}))
650650
}
@@ -656,8 +656,8 @@ impl Wallet {
656656
if desc.descriptor_id() != exp_desc.descriptor_id() {
657657
return Err(LoadError::Mismatch(LoadMismatch::Descriptor {
658658
keychain: KeychainKind::Internal,
659-
loaded: Some(desc),
660-
expected: Some(exp_desc),
659+
loaded: Some(Box::new(desc)),
660+
expected: Some(Box::new(exp_desc)),
661661
}));
662662
}
663663
if params.extract_keys {

wallet/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
}

wallet/tests/persisted_wallet.rs

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

0 commit comments

Comments
 (0)