Skip to content

Commit

Permalink
chore: make change descriptor optional on example_wallet_rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
luisschwab committed Mar 2, 2025
1 parent b26ff89 commit ea55d4c
Showing 1 changed file with 10 additions and 5 deletions.
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 = "481824")]
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 ea55d4c

Please sign in to comment.