From: rajarshimaitra Date: Tue, 14 Sep 2021 10:04:43 +0000 (+0530) Subject: Add esplora-reqwest from bdk X-Git-Tag: v0.3.0~18 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/struct.CommandString.html?a=commitdiff_plain;h=07a4287d67cbadbb7d5b5c3c92aad5b0ca937769;p=bdk-cli Add esplora-reqwest from bdk Adds esplora-reqwest capability from bdk. Allows to use async https connections with esplora from bdk-cli. --- diff --git a/src/bdk_cli.rs b/src/bdk_cli.rs index dcdd2c4..d5df3ff 100644 --- a/src/bdk_cli.rs +++ b/src/bdk_cli.rs @@ -125,7 +125,7 @@ where stop_gap: wallet_opts.electrum_opts.stop_gap, }); - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] let config = AnyBlockchainConfig::Esplora(EsploraBlockchainConfig { base_url: wallet_opts.esplora_opts.server.clone(), timeout_read: wallet_opts.esplora_opts.read_timeout, @@ -133,6 +133,13 @@ where stop_gap: wallet_opts.esplora_opts.stop_gap, }); + #[cfg(feature = "esplora-reqwest")] + let config = AnyBlockchainConfig::Esplora(EsploraBlockchainConfig { + base_url: wallet_opts.esplora_opts.server.clone(), + concurrency: Some(wallet_opts.esplora_opts.conc), + stop_gap: wallet_opts.esplora_opts.stop_gap, + }); + #[cfg(feature = "compact_filters")] let config = { let mut peers = vec![]; diff --git a/src/lib.rs b/src/lib.rs index c3da236..899b517 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,13 +181,19 @@ use bdk::{FeeRate, KeychainKind, Wallet}; /// server: "ssl://electrum.blockstream.info:60002".to_string(), /// stop_gap: 10 /// }, -/// #[cfg(feature = "esplora")] +/// #[cfg(feature = "esplora-ureq")] /// esplora_opts: EsploraOpts { /// server: "https://blockstream.info/api/".to_string(), /// read_timeout: 5, /// write_timeout: 5, /// stop_gap: 10 /// }, +/// #[cfg(feature = "esplora-reqwest")] +/// esplora_opts: EsploraOpts { +/// server: "https://blockstream.info/api/".to_string(), +/// conc: 4, +/// stop_gap: 10 +/// }, /// #[cfg(feature = "compact_filters")] /// compactfilter_opts: CompactFilterOpts{ /// address: vec!["127.0.0.1:18444".to_string()], @@ -328,13 +334,19 @@ pub enum WalletSubCommand { /// server: "ssl://electrum.blockstream.info:60002".to_string(), /// stop_gap: 10 /// }, -/// #[cfg(feature = "esplora")] +/// #[cfg(feature = "esplora-ureq")] /// esplora_opts: EsploraOpts { /// server: "https://blockstream.info/api/".to_string(), /// read_timeout: 5, /// write_timeout: 5, /// stop_gap: 10 /// }, +/// #[cfg(feature = "esplora-reqwest")] +/// esplora_opts: EsploraOpts { +/// server: "https://blockstream.info/api/".to_string(), +/// conc: 4, +/// stop_gap: 10 +/// }, /// #[cfg(feature = "compact_filters")] /// compactfilter_opts: CompactFilterOpts{ /// address: vec!["127.0.0.1:18444".to_string()], @@ -468,7 +480,7 @@ pub struct ElectrumOpts { /// Esplora options /// /// Esplora blockchain client information used by [`OnlineWalletSubCommand`]s. -#[cfg(feature = "esplora")] +#[cfg(feature = "esplora-ureq")] #[derive(Debug, StructOpt, Clone, PartialEq)] pub struct EsploraOpts { /// Use the esplora server if given as parameter @@ -498,6 +510,32 @@ pub struct EsploraOpts { pub stop_gap: usize, } +#[cfg(feature = "esplora-reqwest")] +#[derive(Debug, StructOpt, Clone, PartialEq)] +pub struct EsploraOpts { + /// Use the esplora server if given as parameter + #[structopt( + name = "ESPLORA_URL", + short = "s", + long = "server", + default_value = "https://blockstream.info/api/" + )] + pub server: String, + + /// Number of parallel requests sent to the esplora service (default: 4) + #[structopt(name = "CONCURRENCY", long = "conc", short = "p", default_value = "4")] + pub conc: u8, + + /// Stop searching addresses for transactions after finding an unused gap of this length. + #[structopt( + name = "STOP_GAP", + long = "stop_gap", + short = "g", + default_value = "10" + )] + pub stop_gap: usize, +} + // This is a workaround for `structopt` issue #333, #391, #418; see https://github.com/TeXitoi/structopt/issues/333#issuecomment-712265332 #[cfg_attr(not(doc), allow(missing_docs))] #[cfg_attr( @@ -1142,13 +1180,19 @@ mod test { server: "ssl://electrum.blockstream.info:60002".to_string(), stop_gap: 10, }, - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] esplora_opts: EsploraOpts { server: "https://blockstream.info/api/".to_string(), read_timeout: 5, write_timeout: 5, stop_gap: 10, }, + #[cfg(feature = "esplora-reqwest")] + esplora_opts: EsploraOpts { + server: "https://blockstream.info/api/".to_string(), + conc: 4, + stop_gap: 10, + }, #[cfg(feature = "compact_filters")] compactfilter_opts: CompactFilterOpts{ address: vec!["127.0.0.1:18444".to_string()], @@ -1221,7 +1265,7 @@ mod test { assert_eq!(expected_cli_opts, cli_opts); } - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] #[test] fn test_parse_wallet_esplora() { let cli_args = vec!["bdk-cli", "--network", "bitcoin", "wallet", @@ -1275,6 +1319,58 @@ mod test { assert_eq!(expected_cli_opts, cli_opts); } + #[cfg(feature = "esplora-reqwest")] + #[test] + fn test_parse_wallet_esplora() { + let cli_args = vec!["bdk-cli", "--network", "bitcoin", "wallet", + "--descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)", + "--change_descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)", + "--server", "https://blockstream.info/api/", + "--conc", "10", + "--stop_gap", "20", + "get_new_address"]; + + let cli_opts = CliOpts::from_iter(&cli_args); + + let expected_cli_opts = CliOpts { + network: Network::Bitcoin, + subcommand: CliSubCommand::Wallet { + wallet_opts: WalletOpts { + wallet: "main".to_string(), + verbose: false, + descriptor: "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)".to_string(), + change_descriptor: Some("wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)".to_string()), + #[cfg(feature = "electrum")] + electrum_opts: ElectrumOpts { + timeout: None, + server: "ssl://electrum.blockstream.info:60002".to_string(), + }, + #[cfg(feature = "esplora")] + esplora_opts: EsploraOpts { + server: "https://blockstream.info/api/".to_string(), + conc: 10, + stop_gap: 20 + }, + #[cfg(feature = "compact_filters")] + compactfilter_opts: CompactFilterOpts{ + address: vec!["127.0.0.1:18444".to_string()], + skip_blocks: 0, + conn_count: 4, + }, + #[cfg(any(feature="compact_filters", feature="electrum"))] + proxy_opts: ProxyOpts{ + proxy: None, + proxy_auth: None, + retries: 5, + } + }, + subcommand: WalletSubCommand::OfflineWalletSubCommand(GetNewAddress), + }, + }; + + assert_eq!(expected_cli_opts, cli_opts); + } + #[cfg(feature = "compact_filters")] #[test] fn test_parse_wallet_compact_filters() { @@ -1351,13 +1447,19 @@ mod test { server: "ssl://electrum.blockstream.info:60002".to_string(), stop_gap: 10, }, - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] esplora_opts: EsploraOpts { server: "https://blockstream.info/api/".to_string(), read_timeout: 5, write_timeout: 5, stop_gap: 10, }, + #[cfg(feature = "esplora-reqwest")] + esplora_opts: EsploraOpts { + server: "https://blockstream.info/api/".to_string(), + conc: 4, + stop_gap: 10, + }, #[cfg(feature = "compact_filters")] compactfilter_opts: CompactFilterOpts{ address: vec!["127.0.0.1:18444".to_string()], @@ -1420,13 +1522,19 @@ mod test { server: "ssl://electrum.blockstream.info:60002".to_string(), stop_gap: 10, }, - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] esplora_opts: EsploraOpts { server: "https://blockstream.info/api/".to_string(), read_timeout: 5, write_timeout: 5, stop_gap: 10, }, + #[cfg(feature = "esplora-reqwest")] + esplora_opts: EsploraOpts { + server: "https://blockstream.info/api/".to_string(), + conc: 4, + stop_gap: 10, + }, #[cfg(feature = "compact_filters")] compactfilter_opts: CompactFilterOpts{ address: vec!["127.0.0.1:18444".to_string()], @@ -1481,13 +1589,19 @@ mod test { server: "ssl://electrum.blockstream.info:60002".to_string(), stop_gap: 10, }, - #[cfg(feature = "esplora")] + #[cfg(feature = "esplora-ureq")] esplora_opts: EsploraOpts { server: "https://blockstream.info/api/".to_string(), read_timeout: 5, write_timeout: 5, stop_gap: 10, }, + #[cfg(feature = "esplora-reqwest")] + esplora_opts: EsploraOpts { + server: "https://blockstream.info/api/".to_string(), + conc: 4, + stop_gap: 10, + }, #[cfg(feature = "compact_filters")] compactfilter_opts: CompactFilterOpts{ address: vec!["127.0.0.1:18444".to_string()],