]> Untitled Git - bdk-cli/commitdiff
[examples] support esplora blockchain source in repl
authorRiccardo Casatta <riccardo@casatta.it>
Mon, 16 Nov 2020 11:23:02 +0000 (12:23 +0100)
committerRiccardo Casatta <riccardo@casatta.it>
Tue, 17 Nov 2020 08:39:44 +0000 (09:39 +0100)
examples/repl.rs
src/cli.rs

index dc6a688e67f1330fac064fa0c81ef48e8a110373..69eca920a7a1cf945e9600b5dfb3718bc88e0c46 100644 (file)
@@ -37,13 +37,15 @@ use log::{debug, error, info, trace, LevelFilter};
 use bitcoin::Network;
 
 use bdk::bitcoin;
-use bdk::blockchain::ConfigurableBlockchain;
-use bdk::blockchain::ElectrumBlockchain;
-use bdk::blockchain::ElectrumBlockchainConfig;
+use bdk::blockchain::{
+    AnyBlockchain, AnyBlockchainConfig, ConfigurableBlockchain, ElectrumBlockchainConfig,
+};
 use bdk::cli;
 use bdk::sled;
 use bdk::Wallet;
 
+use bdk::blockchain::esplora::EsploraBlockchainConfig;
+
 fn prepare_home_dir() -> PathBuf {
     let mut dir = PathBuf::new();
     dir.push(&dirs::home_dir().unwrap());
@@ -90,19 +92,25 @@ fn main() {
         .unwrap();
     debug!("database opened successfully");
 
-    let blockchain_config = ElectrumBlockchainConfig {
-        url: matches.value_of("server").unwrap().to_string(),
-        socks5: matches.value_of("proxy").map(ToString::to_string),
+    let config = match matches.value_of("esplora") {
+        Some(base_url) => AnyBlockchainConfig::Esplora(EsploraBlockchainConfig {
+            base_url: base_url.to_string(),
+        }),
+        None => AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
+            url: matches.value_of("server").unwrap().to_string(),
+            socks5: matches.value_of("proxy").map(ToString::to_string),
+        }),
     };
-    let wallet = Wallet::new(
-        descriptor,
-        change_descriptor,
-        network,
-        tree,
-        ElectrumBlockchain::from_config(&blockchain_config).unwrap(),
-    )
-    .unwrap();
-    let wallet = Arc::new(wallet);
+    let wallet = Arc::new(
+        Wallet::new(
+            descriptor,
+            change_descriptor,
+            network,
+            tree,
+            AnyBlockchain::from_config(&config).unwrap(),
+        )
+        .unwrap(),
+    );
 
     if let Some(_sub_matches) = matches.subcommand_matches("repl") {
         let mut rl = Editor::<()>::new();
index ada49cce2f9f57a6a5a2c118c5239c8e10f6d067..f60f7932f464f752650fe1412e17332301e17e90 100644 (file)
@@ -337,6 +337,14 @@ pub fn add_global_flags<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
             .takes_value(true)
             .default_value("ssl://electrum.blockstream.info:60002"),
     )
+    .arg(
+        Arg::with_name("esplora")
+            .short("e")
+            .long("esplora")
+            .value_name("ESPLORA")
+            .help("Use the esplora server if given as parameter")
+            .takes_value(true),
+    )
     .arg(
         Arg::with_name("proxy")
             .short("p")