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 wallet option to select which blockchain client to use #37

Closed
Closed
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
48 changes: 8 additions & 40 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Project

#### Added
- `CliSubCommand::Compile` enum variant and `handle_compile_subcommand()` function

#### Changed
- Make repl and electrum default features
- Update repl feature to not include electrum
- Upgrade to `bdk` v0.7.x

### `bdk-cli` bin

#### Added
- New top level command "Compile" which compiles a miniscript policy to an output descriptor
- `CompactFilterOpts` to `WalletOpts` to enable compact-filter blockchain configuration

#### Changed
- Remove unwraps while handling CLI commands
- Add top level command "Compile" which compiles a miniscript policy to an output descriptor
- Add `CompactFilterOpts` to `WalletOpts` to enable compact-filter blockchain configuration
- Add `verbose` option to `WalletOpts` to display PSBTs also in JSON format
- Add `blockchain_client` to `WalletOpts` to select blockchain client to use

## [0.2.0]

### Project

#### Added
- Add support for `wasm`
- `CliOpts` struct and `CliSubCommand` enum representing top level cli options and commands
- `KeySubCommand` enum
- `handle_key_subcommand` function

#### Changed
- Upgrade `bdk` to `0.4.0` and `bdk-macros` to `0.3.0`
- Renamed `WalletOpt` struct to `WalletOpts`
- `WalletSubCommand` enum split into `OfflineWalletSubCommand` and `OnlineWalletSubCommand`
- Split `handle_wallet_subcommand` into two functions, `handle_offline_wallet_subcommand` and `handle_online_wallet_subcommand`
- A wallet without a `Blockchain` is used when handling offline wallet sub-commands

### `bdk-cli` bin

#### Added
- Top level commands "wallet", "key", and "repl"
- "key" sub-commands to "generate" and "restore" a master private key
- "key" sub-command to "derive" an extended public key from a master private key
- Add top level commands "wallet", "key", and "repl"
- Add "key" sub-commands to "generate" and "restore" a master private key
- Add "key" sub-command to "derive" an extended public key from a master private key
- "repl" command now has an "exit" sub-command

#### Changed
- "wallet" sub-commands and options must be proceeded by "wallet" command
- "repl" command loop now includes both "wallet" and "key" sub-commands

## [0.1.0]

### Project
#### Added
- Add CONTRIBUTING.md
- Add CI and code coverage Discord badges to the README
- Add CI and code coverage github actions workflows
- Add scheduled audit check in CI
- Add CHANGELOG.md

#### Changed
- If an invalid network name return an error instead of defaulting to `testnet`

## [0.1.0-beta.1]
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ structopt = "^0.3"
serde_json = { version = "^1.0" }
log = "^0.4"
base64 = "^0.11"
zeroize = { version = "<1.4.0" }

# Optional dependencies
rustyline = { version = "6.0", optional = true }
Expand Down
74 changes: 29 additions & 45 deletions src/bdk_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use bdk::sled;
use bdk::sled::Tree;
use bdk::Wallet;
use bdk::{bitcoin, Error};
use bdk_cli::WalletSubCommand;
use bdk_cli::{BlockchainClient, WalletSubCommand};
use bdk_cli::{
CliOpts, CliSubCommand, KeySubCommand, OfflineWalletSubCommand, OnlineWalletSubCommand,
WalletOpts,
Expand Down Expand Up @@ -104,58 +104,42 @@ fn new_online_wallet<D>(
where
D: BatchDatabase,
{
// Try to use Esplora config if "esplora" feature is enabled
#[cfg(feature = "esplora")]
let config_esplora: Option<AnyBlockchainConfig> = {
let esplora_concurrency = wallet_opts.esplora_opts.esplora_concurrency;
wallet_opts.esplora_opts.esplora.clone().map(|base_url| {
AnyBlockchainConfig::Esplora(EsploraBlockchainConfig {
base_url,
concurrency: Some(esplora_concurrency),
})
})
};
#[cfg(not(feature = "esplora"))]
let config_esplora = None;

let config_electrum = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
url: wallet_opts.electrum_opts.electrum.clone(),
socks5: wallet_opts.proxy_opts.proxy.clone(),
retry: wallet_opts.proxy_opts.retries,
timeout: wallet_opts.electrum_opts.timeout,
});

#[cfg(feature = "compact_filters")]
let config_compact_filters: Option<AnyBlockchainConfig> = {
let mut peers = vec![];
for addrs in wallet_opts.compactfilter_opts.address.clone() {
for _ in 0..wallet_opts.compactfilter_opts.conn_count {
peers.push(BitcoinPeerConfig {
address: addrs.clone(),
socks5: wallet_opts.proxy_opts.proxy.clone(),
socks5_credentials: wallet_opts.proxy_opts.proxy_auth.clone(),
})
// Create requested blockchain client config
let config = match wallet_opts.blockchain_client {
#[cfg(feature = "electrum")]
BlockchainClient::Electrum => AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
url: wallet_opts.electrum_opts.electrum.clone(),
socks5: wallet_opts.proxy_opts.proxy.clone(),
retry: wallet_opts.proxy_opts.retries,
timeout: wallet_opts.electrum_opts.timeout,
}),
#[cfg(feature = "esplora")]
BlockchainClient::Esplora => AnyBlockchainConfig::Esplora(EsploraBlockchainConfig {
base_url: wallet_opts.esplora_opts.esplora.clone(),
concurrency: Some(wallet_opts.esplora_opts.esplora_concurrency),
}),
#[cfg(feature = "compact_filters")]
BlockchainClient::CompactFilters => {
let mut peers = vec![];
for addrs in wallet_opts.compactfilter_opts.address.clone() {
for _ in 0..wallet_opts.compactfilter_opts.conn_count {
peers.push(BitcoinPeerConfig {
address: addrs.clone(),
socks5: wallet_opts.proxy_opts.proxy.clone(),
socks5_credentials: wallet_opts.proxy_opts.proxy_auth.clone(),
})
}
}
}

Some(AnyBlockchainConfig::CompactFilters(
CompactFiltersBlockchainConfig {
AnyBlockchainConfig::CompactFilters(CompactFiltersBlockchainConfig {
peers,
network,
storage_dir: prepare_home_dir().into_os_string().into_string().unwrap(),
skip_blocks: Some(wallet_opts.compactfilter_opts.skip_blocks),
},
))
})
}
};

#[cfg(not(feature = "compact_filters"))]
let config_compact_filters = None;

// Fall back to Electrum config if Esplora or Compact Filter config isn't provided
let config = config_esplora
.or(config_compact_filters)
.unwrap_or(config_electrum);

let descriptor = wallet_opts.descriptor.as_str();
let change_descriptor = wallet_opts.change_descriptor.as_deref();
let wallet = Wallet::new(
Expand Down
Loading