Skip to content

Commit

Permalink
Merge bitcoindevkit#1562: fix(wallet)!: make LoadParams implicitly …
Browse files Browse the repository at this point in the history
…satisfy `Send`

295b979 fix(wallet)!: make `LoadParams` implicitly satisfy `Send` (志宇)

Pull request description:

  ### Description

  Make `LoadParams` implicitly satisfy `Send`. This will hopefully make `AsyncWalletPersister` easier to implement.

  Refer to the [conversation on Discord](https://discord.com/channels/753336465005608961/753367451319926827/1273667818528964714).

  cc. @matthiasdebernardini

  ### Notes to the reviewers

  This is a breaking change, since we are tightening the bounds to some methods.

  ### Changelog notice

  * Change `LoadParams` to implicitly satisfy `Send`.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

ACKs for top commit:
  LLFourn:
    ACK 295b979
  notmandatory:
    ACK 295b979

Tree-SHA512: 952cd7fbb058166af93af0b8afa3e0f3c1afe600f5782364da8e3c74e7388ca682bab34e2c60b221055e25ade2f6ddb4a2e9451d6d181f14b0bcca053522155c
  • Loading branch information
evanlinjin committed Aug 22, 2024
2 parents 37314dc + 295b979 commit 6008897
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl Wallet {
/// [`reveal_next_address`]: Self::reveal_next_address
pub fn create_single<D>(descriptor: D) -> CreateParams
where
D: IntoWalletDescriptor + Clone + 'static,
D: IntoWalletDescriptor + Send + Clone + 'static,
{
CreateParams::new_single(descriptor)
}
Expand Down Expand Up @@ -369,7 +369,7 @@ impl Wallet {
/// ```
pub fn create<D>(descriptor: D, change_descriptor: D) -> CreateParams
where
D: IntoWalletDescriptor + Clone + 'static,
D: IntoWalletDescriptor + Send + Clone + 'static,
{
CreateParams::new(descriptor, change_descriptor)
}
Expand Down
12 changes: 8 additions & 4 deletions crates/wallet/src/wallet/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ use super::{ChangeSet, LoadError, PersistedWallet};
/// [object safety rules](https://doc.rust-lang.org/reference/items/traits.html#object-safety).
type DescriptorToExtract = Box<
dyn FnOnce(&SecpCtx, Network) -> Result<(ExtendedDescriptor, KeyMap), DescriptorError>
+ Send
+ 'static,
>;

fn make_descriptor_to_extract<D>(descriptor: D) -> DescriptorToExtract
where
D: IntoWalletDescriptor + 'static,
D: IntoWalletDescriptor + Send + 'static,
{
Box::new(|secp, network| descriptor.into_wallet_descriptor(secp, network))
}
Expand Down Expand Up @@ -51,7 +52,7 @@ impl CreateParams {
///
/// Use this method only when building a wallet with a single descriptor. See
/// also [`Wallet::create_single`].
pub fn new_single<D: IntoWalletDescriptor + 'static>(descriptor: D) -> Self {
pub fn new_single<D: IntoWalletDescriptor + Send + 'static>(descriptor: D) -> Self {
Self {
descriptor: make_descriptor_to_extract(descriptor),
descriptor_keymap: KeyMap::default(),
Expand All @@ -69,7 +70,10 @@ impl CreateParams {
/// * `network` = [`Network::Bitcoin`]
/// * `genesis_hash` = `None`
/// * `lookahead` = [`DEFAULT_LOOKAHEAD`]
pub fn new<D: IntoWalletDescriptor + 'static>(descriptor: D, change_descriptor: D) -> Self {
pub fn new<D: IntoWalletDescriptor + Send + 'static>(
descriptor: D,
change_descriptor: D,
) -> Self {
Self {
descriptor: make_descriptor_to_extract(descriptor),
descriptor_keymap: KeyMap::default(),
Expand Down Expand Up @@ -185,7 +189,7 @@ impl LoadParams {
/// for an expected descriptor containing secrets.
pub fn descriptor<D>(mut self, keychain: KeychainKind, expected_descriptor: Option<D>) -> Self
where
D: IntoWalletDescriptor + 'static,
D: IntoWalletDescriptor + Send + 'static,
{
let expected = expected_descriptor.map(|d| make_descriptor_to_extract(d));
match keychain {
Expand Down

0 comments on commit 6008897

Please sign in to comment.