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

add electrum support #19

Merged
merged 1 commit into from
Mar 19, 2024
Merged
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
104 changes: 82 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ bp-std = "0.11.0-beta.4"
psbt = "0.11.0-beta.4"
descriptors = "0.11.0-beta.4"
bp-esplora = "0.11.0-beta.4"
bp-electrum = "0.11.0-beta.5"
serde_crate = { package = "serde", version = "1", features = ["derive"] }
serde_json = "1.0.114"
serde_with = "3.4.0"
serde_yaml = "0.9.19"
toml = "0.8.2"
Expand Down Expand Up @@ -48,17 +50,20 @@ name = "bpwallet"
amplify = { workspace = true }
bp-std = { workspace = true }
bp-esplora = { workspace = true, optional = true }
bp-electrum = { workspace = true, optional = true }
psbt = { workspace = true }
descriptors = { workspace = true }
serde_crate = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
serde_with = { workspace = true, optional = true }
serde_yaml = { workspace = true, optional = true }
toml = { workspace = true, optional = true }
cfg_eval = { workspace = true, optional = true }

[features]
default = []
all = ["esplora", "fs"]
all = ["electrum", "esplora", "fs"]
electrum = ["bp-electrum", "serde", "serde_json"]
esplora = ["bp-esplora"]
fs = ["serde"]
serde = ["cfg_eval", "serde_crate", "serde_with", "serde_yaml", "toml", "bp-std/serde"]
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ path = "src/bin/bp.rs"
[dependencies]
amplify = { workspace = true, features = ["serde"] }
strict_encoding = { workspace = true }
bp-wallet = { version = "0.11.0-beta.2", path = "..", features = ["serde", "fs", "esplora"] }
bp-wallet = { version = "0.11.0-beta.4", path = "..", features = ["all"] }
bp-std = { workspace = true, features = ["serde"] }
descriptors = { workspace = true, features = ["serde"] }
psbt = { workspace = true, features = ["serde"] }
bp-esplora = { workspace = true }
bp-electrum = { workspace = true }
base64 = "0.21.5"
log = { workspace = true }
env_logger = "0.10.0"
Expand Down
12 changes: 9 additions & 3 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use std::fmt::Debug;
use std::path::PathBuf;

use bpwallet::Runtime;
use bpwallet::{AnyIndexer, Runtime};
use clap::Subcommand;
use descriptors::Descriptor;
use strict_encoding::Ident;

use crate::opts::{DescrStdOpts, DescriptorOpts};
use crate::opts::{DescrStdOpts, DescriptorOpts, DEFAULT_ELECTRUM};
use crate::{Config, GeneralOpts, ResolverOpt, RuntimeError, WalletOpts};

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

if sync || self.wallet.descriptor_opts.is_some() {
eprint!("Syncing");
let indexer = esplora::Builder::new(&self.resolver.esplora).build_blocking()?;
let indexer = if self.resolver.electrum != DEFAULT_ELECTRUM {
AnyIndexer::Electrum(Box::new(electrum::Client::new(&self.resolver.electrum)?))
} else {
AnyIndexer::Esplora(Box::new(
esplora::Builder::new(&self.resolver.esplora).build_blocking()?,
))
};
if let Err(errors) = runtime.sync(&indexer) {
eprintln!(" partial, some requests has failed:");
for err in errors {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ pub use config::Config;
pub use loglevel::LogLevel;
pub use opts::{
DescrStdOpts, DescriptorOpts, GeneralOpts, ResolverOpt, WalletOpts, DATA_DIR, DATA_DIR_ENV,
DEFAULT_ESPLORA,
DEFAULT_ELECTRUM, DEFAULT_ESPLORA,
};
15 changes: 14 additions & 1 deletion cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,26 @@ pub const DATA_DIR: &str = "~/Documents";
#[cfg(target_os = "android")]
pub const DATA_DIR: &str = ".";

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

#[derive(Args, Clone, PartialEq, Eq, Debug)]
pub struct ResolverOpt {
/// Electrum server to use.
#[arg(
conflicts_with = "esplora",
long,
global = true,
default_value = DEFAULT_ELECTRUM,
env = "ELECRTUM_SERVER",
value_hint = ValueHint::Url,
value_name = "URL"
)]
pub electrum: String,

/// Esplora server to use.
#[arg(
short,
conflicts_with = "electrum",
long,
global = true,
default_value = DEFAULT_ESPLORA,
Expand Down
Loading
Loading