Skip to content

Commit 63e62b4

Browse files
committed
Merge #1865: chore(examples): make change descriptor optional 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 #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
2 parents e922efe + 78ca4b0 commit 63e62b4

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

example-crates/example_wallet_rpc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ $ cargo run --bin example_wallet_rpc -- --help
55
66
Bitcoind RPC example using `bdk_wallet::Wallet`
77
8-
Usage: example_wallet_rpc [OPTIONS] <DESCRIPTOR> <CHANGE_DESCRIPTOR>
8+
Usage: example_wallet_rpc [OPTIONS] <DESCRIPTOR> [CHANGE_DESCRIPTOR]
99
1010
Arguments:
1111
<DESCRIPTOR> Wallet descriptor [env: DESCRIPTOR=]
12-
<CHANGE_DESCRIPTOR> Wallet change descriptor [env: CHANGE_DESCRIPTOR=]
12+
[CHANGE_DESCRIPTOR] Wallet change descriptor [env: CHANGE_DESCRIPTOR=]
1313
1414
Options:
1515
--start-height <START_HEIGHT> Earliest block height to start sync from [env: START_HEIGHT=] [default: 0]

example-crates/example_wallet_rpc/src/main.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Args {
2525
pub descriptor: String,
2626
/// Wallet change descriptor
2727
#[clap(env = "CHANGE_DESCRIPTOR")]
28-
pub change_descriptor: String,
28+
pub change_descriptor: Option<String>,
2929
/// Earliest block height to start sync from
3030
#[clap(env = "START_HEIGHT", long, default_value = "0")]
3131
pub start_height: u32,
@@ -90,15 +90,20 @@ fn main() -> anyhow::Result<()> {
9090
Store::<bdk_wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), args.db_path)?;
9191
let wallet_opt = Wallet::load()
9292
.descriptor(KeychainKind::External, Some(args.descriptor.clone()))
93-
.descriptor(KeychainKind::Internal, Some(args.change_descriptor.clone()))
93+
.descriptor(KeychainKind::Internal, args.change_descriptor.clone())
9494
.extract_keys()
9595
.check_network(args.network)
9696
.load_wallet(&mut db)?;
9797
let mut wallet = match wallet_opt {
9898
Some(wallet) => wallet,
99-
None => Wallet::create(args.descriptor, args.change_descriptor)
100-
.network(args.network)
101-
.create_wallet(&mut db)?,
99+
None => match &args.change_descriptor {
100+
Some(change_desc) => Wallet::create(args.descriptor.clone(), change_desc.clone())
101+
.network(args.network)
102+
.create_wallet(&mut db)?,
103+
None => Wallet::create_single(args.descriptor.clone())
104+
.network(args.network)
105+
.create_wallet(&mut db)?,
106+
},
102107
};
103108
println!(
104109
"Loaded wallet in {}s",

0 commit comments

Comments
 (0)