Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce bdk::Wallet builder API #1250

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Dec 28, 2023

Description

This changes the wallet-construction API to use the builder pattern. This is a simpler API and allows us to avoid multiple constructor methods.

I.e. previously, we had Wallet::new and Wallet::new_with_genesis_hash. If in the future, we added more parameters, it will turn into an absolute mess.

Notes to the reviewers

This PR is based on #1229. Consider reviewing/merging that first!

I think it makes sense to have the lookahead configurable in bdk::Wallet and persisted. However, @LLFourn is against this idea of persisting the lookahead. This can be of discussion for a future change.

Changelog notice

  • Changed wallet-construction API to use the builder pattern.
  • Changed NewError to InitError and NewOrLoadError to InitOrLoadError.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

darosior and others added 2 commits December 28, 2023 12:51
The wallet is currently created without setting any lookahead value for
the keychain. This implicitly makes it a lookahead of 0. As this is a
high-level interface we should avoid footguns and aim for a reasonable
default.

Instead of simply patching it for wallet, we alter `KeychainTxOutIndex`
to have a default lookahead value. Additionally, instead of a
per-keychain lookahead, the constructor asks for a `lookahead` value.
This avoids the footguns of having methods which allows the caller the
decrease the `lookahead` (and therefore panicing). This also simplifies
the API.

Co-authored-by: Antoine Poisot <darosior@protonmail.com>
Co-authored-by: 志宇 <hello@evanlinjin.me>
Previously, the genesis block is not initialized properly. Thank you
@notmandatory for identifying this bug.
Wallet error types `NewError` and `NewOrLoadError` have been renamed to
`InitError` and `InitOrLoadError`.
@notmandatory
Copy link
Member

Concept ACK, this pattern should also be easier to extend to support future features like custom coin selection. But I'd like to push it to the alpha.4 release, alpha.3 is already long overdue.

@evanlinjin
Copy link
Member Author

@notmandatory if we wish to make the lookahead configurable in bdk::Wallet for alpha.3, I think it will be a good idea to include this in the release. Otherwise, I am okay with pushing this back.

@nondiremanuel nondiremanuel added this to the 1.0.0-alpha.4 milestone Jan 2, 2024
@LLFourn
Copy link
Contributor

LLFourn commented Jan 3, 2024

Concept ACK

@nondiremanuel nondiremanuel modified the milestones: 1.0.0-alpha.4, 1.0.0 Jan 6, 2024
use super::{InitError, InitOrLoadError};

/// Helper structure to initialize a fresh [`Wallet`] instance.
pub struct WalletBuilder<E> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about just calling this Builder, i.e. bdk::wallet::Builder ?

@notmandatory notmandatory added the api A breaking API change label Jan 16, 2024
@evanlinjin
Copy link
Member Author

It makes sense to complete this AFTER #1203 is merged (as that PR also touches wallet constructors).

@notmandatory
Copy link
Member

This one needs a rebase after alpha.5 release.

@notmandatory notmandatory removed this from the 1.0.0-alpha milestone Mar 18, 2024
@notmandatory notmandatory added the enhancement New feature or request label Mar 18, 2024
@LLFourn LLFourn mentioned this pull request Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change enhancement New feature or request module-wallet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

6 participants