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

Descriptor support #37

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ impl App {
pub fn boot(config: Config) -> Result<Self> {
debug!("{:?}", config);

let wallets = HDWallet::from_xpubs(
let rpc = Arc::new(RpcClient::new(
config.bitcoind_url(),
config.bitcoind_auth()?,
)?);

let wallets = HDWallet::from_config(
&config.descriptors[..],
&config.xpubs[..],
&config.bare_xpubs[..],
config.network,
config.gap_limit,
config.initial_import_size,
rpc.clone(),
)?;

let watcher = HDWatcher::new(wallets);

let rpc = Arc::new(RpcClient::new(
config.bitcoind_url(),
config.bitcoind_auth()?,
)?);
let indexer = Arc::new(RwLock::new(Indexer::new(rpc.clone(), watcher)));
let query = Arc::new(Query::new(config.network, rpc.clone(), indexer.clone()));

Expand Down
22 changes: 21 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct Config {
pub bitcoind_wallet: Option<String>,

#[structopt(
short = "d",
short = "D",
long,
help = "Path to bitcoind directory (used for cookie file) [default: ~/.bitcoin]",
env,
Expand Down Expand Up @@ -96,6 +96,16 @@ pub struct Config {
)]
pub bitcoind_cookie: Option<path::PathBuf>,

#[structopt(
short = "d",
long = "descriptor",
help = "Output script descriptor to track and since when (rescans from genesis by default, use <desc>:<yyyy-mm-dd> or <desc>:<unix-epoch> to specify a timestmap, or <desc>:none to disable rescan)",
parse(try_from_str = parse_descriptor),
env, hide_env_values(true), use_delimiter(true),
display_order(20)
)]
pub descriptors: Vec<(String, RescanSince)>,

#[structopt(
short = "x",
long = "xpub",
Expand Down Expand Up @@ -346,6 +356,16 @@ fn parse_xpub(s: &str) -> Result<(XyzPubKey, RescanSince)> {
Ok((xpub, rescan))
}

fn parse_descriptor(s: &str) -> Result<(String, RescanSince)> {
let mut parts = s.splitn(2, ':');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could descriptors contains :? I can't seem to find any descriptors that do, but : appears to be included in the INPUT_CHARSET used for checksumming.

Copy link
Author

Choose a reason for hiding this comment

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

: separates the descriptor and the "rescan since" timestamp. I just copied parse_xpub (link).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I understood, I asked whether descriptors can contain : because if they do, the : separator would be ambiguous with the syntax of the descriptor itself.

But AFAICT, descriptors cannot contain :, so this shouldn't be ambiguous.

let descriptor = String::from(parts.next().unwrap());
Copy link
Collaborator

Choose a reason for hiding this comment

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

The two unwraps here should instead return an Err, similarly to how its done in parse_xpub.

let rescan = parts
.next()
.map_or(Ok(RescanSince::Timestamp(0)), parse_rescan)
.unwrap();
Ok((descriptor, rescan))
}
justinmoon marked this conversation as resolved.
Show resolved Hide resolved

fn parse_rescan(s: &str) -> Result<RescanSince> {
Ok(match s {
"none" => RescanSince::Now,
Expand Down
Loading