Skip to content

Commit

Permalink
Merge bitcoindevkit#1865: chore(examples): make change descriptor opt…
Browse files Browse the repository at this point in the history
…ional on example_wallet_rpc

78ca4b0 chore: make change descriptor optional on example_wallet_rpc (Luis Schwab)

Pull request description:

  ### Description

  This PR makes passing a `CHANGE_DESCRIPTOR` optional on `example_wallet_rpc`, as per bitcoindevkit#1533.

  ### Notes to the reviewers

  Before instantiating a `Wallet` it checks if `args.change_descriptor` is Some. If true calls `Wallet::create`, else calls `Wallet::create_single`.

  #### 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:
  ValuedMammal:
    ACK 78ca4b0

Tree-SHA512: ddca4b2a9931df1a067fbe86adc43c5f62f120cf76c9a1099995fd8a063303fe8e47e7b15e186c40fc347c3ffa350a45f92e129e724e2d99e1e3732d76faa2ee
  • Loading branch information
ValuedMammal committed Mar 7, 2025
2 parents e922efe + 78ca4b0 commit 63e62b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions example-crates/example_wallet_rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ $ cargo run --bin example_wallet_rpc -- --help
Bitcoind RPC example using `bdk_wallet::Wallet`
Usage: example_wallet_rpc [OPTIONS] <DESCRIPTOR> <CHANGE_DESCRIPTOR>
Usage: example_wallet_rpc [OPTIONS] <DESCRIPTOR> [CHANGE_DESCRIPTOR]
Arguments:
<DESCRIPTOR> Wallet descriptor [env: DESCRIPTOR=]
<CHANGE_DESCRIPTOR> Wallet change descriptor [env: CHANGE_DESCRIPTOR=]
[CHANGE_DESCRIPTOR] Wallet change descriptor [env: CHANGE_DESCRIPTOR=]
Options:
--start-height <START_HEIGHT> Earliest block height to start sync from [env: START_HEIGHT=] [default: 0]
Expand Down
15 changes: 10 additions & 5 deletions example-crates/example_wallet_rpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Args {
pub descriptor: String,
/// Wallet change descriptor
#[clap(env = "CHANGE_DESCRIPTOR")]
pub change_descriptor: String,
pub change_descriptor: Option<String>,
/// Earliest block height to start sync from
#[clap(env = "START_HEIGHT", long, default_value = "0")]
pub start_height: u32,
Expand Down Expand Up @@ -90,15 +90,20 @@ fn main() -> anyhow::Result<()> {
Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), args.db_path)?;
let wallet_opt = Wallet::load()
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(args.change_descriptor.clone()))
.descriptor(KeychainKind::Internal, args.change_descriptor.clone())
.extract_keys()
.check_network(args.network)
.load_wallet(&mut db)?;
let mut wallet = match wallet_opt {
Some(wallet) => wallet,
None => Wallet::create(args.descriptor, args.change_descriptor)
.network(args.network)
.create_wallet(&mut db)?,
None => match &args.change_descriptor {
Some(change_desc) => Wallet::create(args.descriptor.clone(), change_desc.clone())
.network(args.network)
.create_wallet(&mut db)?,
None => Wallet::create_single(args.descriptor.clone())
.network(args.network)
.create_wallet(&mut db)?,
},
};
println!(
"Loaded wallet in {}s",
Expand Down

0 comments on commit 63e62b4

Please sign in to comment.