Skip to content

Commit 35249ab

Browse files
committed
add electrum support
1 parent 8552e16 commit 35249ab

12 files changed

Lines changed: 594 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 82 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ bp-std = "0.11.0-beta.4"
2020
psbt = "0.11.0-beta.4"
2121
descriptors = "0.11.0-beta.4"
2222
bp-esplora = "0.11.0-beta.4"
23+
bp-electrum = "0.11.0-beta.5"
2324
serde_crate = { package = "serde", version = "1", features = ["derive"] }
25+
serde_json = "1.0.114"
2426
serde_with = "3.4.0"
2527
serde_yaml = "0.9.19"
2628
toml = "0.8.2"
@@ -48,17 +50,20 @@ name = "bpwallet"
4850
amplify = { workspace = true }
4951
bp-std = { workspace = true }
5052
bp-esplora = { workspace = true, optional = true }
53+
bp-electrum = { workspace = true, optional = true }
5154
psbt = { workspace = true }
5255
descriptors = { workspace = true }
5356
serde_crate = { workspace = true, optional = true }
57+
serde_json = { workspace = true, optional = true }
5458
serde_with = { workspace = true, optional = true }
5559
serde_yaml = { workspace = true, optional = true }
5660
toml = { workspace = true, optional = true }
5761
cfg_eval = { workspace = true, optional = true }
5862

5963
[features]
6064
default = []
61-
all = ["esplora", "fs"]
65+
all = ["electrum", "esplora", "fs"]
66+
electrum = ["bp-electrum", "serde", "serde_json"]
6267
esplora = ["bp-esplora"]
6368
fs = ["serde"]
6469
serde = ["cfg_eval", "serde_crate", "serde_with", "serde_yaml", "toml", "bp-std/serde"]

cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ path = "src/bin/bp.rs"
2121
[dependencies]
2222
amplify = { workspace = true, features = ["serde"] }
2323
strict_encoding = { workspace = true }
24-
bp-wallet = { version = "0.11.0-beta.2", path = "..", features = ["serde", "fs", "esplora"] }
24+
bp-wallet = { version = "0.11.0-beta.4", path = "..", features = ["all"] }
2525
bp-std = { workspace = true, features = ["serde"] }
2626
descriptors = { workspace = true, features = ["serde"] }
2727
psbt = { workspace = true, features = ["serde"] }
2828
bp-esplora = { workspace = true }
29+
bp-electrum = { workspace = true }
2930
base64 = "0.21.5"
3031
log = { workspace = true }
3132
env_logger = "0.10.0"

cli/src/args.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
use std::fmt::Debug;
2424
use std::path::PathBuf;
2525

26-
use bpwallet::Runtime;
26+
use bpwallet::{AnyIndexer, Runtime};
2727
use clap::Subcommand;
2828
use descriptors::Descriptor;
2929
use strict_encoding::Ident;
3030

31-
use crate::opts::{DescrStdOpts, DescriptorOpts};
31+
use crate::opts::{DescrStdOpts, DescriptorOpts, DEFAULT_ELECTRUM};
3232
use crate::{Config, GeneralOpts, ResolverOpt, RuntimeError, WalletOpts};
3333

3434
/// Command-line arguments
@@ -118,7 +118,13 @@ impl<C: Clone + Eq + Debug + Subcommand, O: DescriptorOpts> Args<C, O> {
118118

119119
if sync || self.wallet.descriptor_opts.is_some() {
120120
eprint!("Syncing");
121-
let indexer = esplora::Builder::new(&self.resolver.esplora).build_blocking()?;
121+
let indexer = if self.resolver.electrum != DEFAULT_ELECTRUM {
122+
AnyIndexer::Electrum(Box::new(electrum::Client::new(&self.resolver.electrum)?))
123+
} else {
124+
AnyIndexer::Esplora(Box::new(
125+
esplora::Builder::new(&self.resolver.esplora).build_blocking()?,
126+
))
127+
};
122128
if let Err(errors) = runtime.sync(&indexer) {
123129
eprintln!(" partial, some requests has failed:");
124130
for err in errors {

cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ pub use config::Config;
4242
pub use loglevel::LogLevel;
4343
pub use opts::{
4444
DescrStdOpts, DescriptorOpts, GeneralOpts, ResolverOpt, WalletOpts, DATA_DIR, DATA_DIR_ENV,
45-
DEFAULT_ESPLORA,
45+
DEFAULT_ELECTRUM, DEFAULT_ESPLORA,
4646
};

cli/src/opts.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,26 @@ pub const DATA_DIR: &str = "~/Documents";
4242
#[cfg(target_os = "android")]
4343
pub const DATA_DIR: &str = ".";
4444

45+
pub const DEFAULT_ELECTRUM: &str = "example.com:50001";
4546
pub const DEFAULT_ESPLORA: &str = "https://blockstream.info/testnet/api";
4647

4748
#[derive(Args, Clone, PartialEq, Eq, Debug)]
4849
pub struct ResolverOpt {
50+
/// Electrum server to use.
51+
#[arg(
52+
conflicts_with = "esplora",
53+
long,
54+
global = true,
55+
default_value = DEFAULT_ELECTRUM,
56+
env = "ELECRTUM_SERVER",
57+
value_hint = ValueHint::Url,
58+
value_name = "URL"
59+
)]
60+
pub electrum: String,
61+
4962
/// Esplora server to use.
5063
#[arg(
51-
short,
64+
conflicts_with = "electrum",
5265
long,
5366
global = true,
5467
default_value = DEFAULT_ESPLORA,

0 commit comments

Comments
 (0)