Skip to content

Commit

Permalink
cli: account for network in indexer URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 16, 2024
1 parent daf7327 commit 0274bd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,18 @@ impl<C: Clone + Eq + Debug + Subcommand, O: DescriptorOpts> Args<C, O> {
};

if sync {
let network = self.general.network.to_string();
let indexer =
match (&self.resolver.esplora, &self.resolver.electrum, &self.resolver.mempool) {
(None, Some(url), None) => {
AnyIndexer::Electrum(Box::new(electrum::Client::new(url)?))
}
(Some(url), None, None) => {
AnyIndexer::Esplora(Box::new(IndexerClient::new_esplora(url)?))
}
(None, None, Some(url)) => {
AnyIndexer::Mempool(Box::new(IndexerClient::new_mempool(url)?))
}
(None, Some(url), None) => AnyIndexer::Electrum(Box::new(
electrum::Client::new(&url.replace("{network}", &network))?,
)),
(Some(url), None, None) => AnyIndexer::Esplora(Box::new(
IndexerClient::new_esplora(&url.replace("{network}", &network))?,
)),
(None, None, Some(url)) => AnyIndexer::Mempool(Box::new(
IndexerClient::new_mempool(&url.replace("{network}", &network))?,
)),
_ => {
eprintln!(
" - error: no blockchain indexer specified; use either --esplora \
Expand Down
4 changes: 2 additions & 2 deletions src/cli/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub const DATA_DIR: &str = "~/Documents";
pub const DATA_DIR: &str = ".";

pub const DEFAULT_ELECTRUM: &str = "example.com:50001";
pub const DEFAULT_ESPLORA: &str = "https://blockstream.info/testnet/api";
pub const DEFAULT_MEMPOOL: &str = "https://mempool.space/testnet/api";
pub const DEFAULT_ESPLORA: &str = "https://blockstream.info/{network}/api";
pub const DEFAULT_MEMPOOL: &str = "https://mempool.space/{network}/api";

#[derive(Args, Clone, PartialEq, Eq, Debug)]
#[group(args = ["electrum", "esplora", "mempool"])]
Expand Down

0 comments on commit 0274bd8

Please sign in to comment.