feature = "compact_filters",
feature = "rpc"
))]
-fn new_online_wallet<D>(
- network: Network,
- wallet_opts: &WalletOpts,
- database: D,
-) -> Result<Wallet<AnyBlockchain, D>, Error>
-where
- D: BatchDatabase,
-{
+pub fn new_blockchain(_network: Network, wallet_opts: &WalletOpts) -> Result<AnyBlockchain, Error> {
#[cfg(feature = "electrum")]
let config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
url: wallet_opts.electrum_opts.server.clone(),
AnyBlockchainConfig::CompactFilters(CompactFiltersBlockchainConfig {
peers,
- network,
+ network: _network,
storage_dir: prepare_home_dir()?
.into_os_string()
.into_string()
let wallet_name = wallet_name_from_descriptor(
&wallet_opts.descriptor[..],
wallet_opts.change_descriptor.as_deref(),
- network,
+ _network,
&Secp256k1::new(),
)?;
let rpc_config = RpcConfig {
url: rpc_url,
auth,
- network,
+ network: _network,
wallet_name,
skip_blocks: wallet_opts.rpc_opts.skip_blocks,
};
AnyBlockchainConfig::Rpc(rpc_config)
};
- let descriptor = wallet_opts.descriptor.as_str();
- let change_descriptor = wallet_opts.change_descriptor.as_deref();
- let wallet = Wallet::new(
- descriptor,
- change_descriptor,
- network,
- database,
- AnyBlockchain::from_config(&config)?,
- )?;
- Ok(wallet)
+ Ok(AnyBlockchain::from_config(&config)?)
}
-fn new_offline_wallet<D>(
+pub fn new_wallet<D>(
network: Network,
wallet_opts: &WalletOpts,
database: D,
-) -> Result<Wallet<(), D>, Error>
+) -> Result<Wallet<D>, Error>
where
D: BatchDatabase,
{
let descriptor = wallet_opts.descriptor.as_str();
let change_descriptor = wallet_opts.change_descriptor.as_deref();
- let wallet = Wallet::new_offline(descriptor, change_descriptor, network, database)?;
+ let wallet = Wallet::new(descriptor, change_descriptor, network, database)?;
Ok(wallet)
}
} => {
let wallet_opts = maybe_descriptor_wallet_name(wallet_opts, network)?;
let database = open_database(&wallet_opts)?;
- let wallet = new_online_wallet(network, &wallet_opts, database)?;
- let result = bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand)?;
+ let blockchain = new_blockchain(network, &wallet_opts)?;
+ let wallet = new_wallet(network, &wallet_opts, database)?;
+ let result =
+ bdk_cli::handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand)?;
serde_json::to_string_pretty(&result)?
}
CliSubCommand::Wallet {
} => {
let wallet_opts = maybe_descriptor_wallet_name(wallet_opts, network)?;
let database = open_database(&wallet_opts)?;
- let wallet = new_offline_wallet(network, &wallet_opts, database)?;
+ let wallet = new_wallet(network, &wallet_opts, database)?;
let result = bdk_cli::handle_offline_wallet_subcommand(
&wallet,
&wallet_opts,
feature = "compact_filters",
feature = "rpc"
))]
- let wallet = new_online_wallet(network, &wallet_opts, database)?;
+ let wallet = new_wallet(network, &wallet_opts, database)?;
#[cfg(not(any(
feature = "electrum",
feature = "compact_filters",
feature = "rpc"
)))]
- let wallet = new_offline_wallet(network, &wallet_opts, database)?;
+ let wallet = new_wallet(network, &wallet_opts, database)?;
let mut rl = Editor::<()>::new();
feature = "rpc"
))]
ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => {
- bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand)
+ let blockchain = new_blockchain(network, &wallet_opts)?;
+ bdk_cli::handle_online_wallet_subcommand(
+ &wallet,
+ &blockchain,
+ online_subcommand,
+ )
}
ReplSubCommand::OfflineWalletSubCommand(offline_subcommand) => {
bdk_cli::handle_offline_wallet_subcommand(
//!
//! let database = MemoryDatabase::new();
//!
-//! let config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
-//! url: wallet_opts.electrum_opts.server,
-//! socks5: wallet_opts.proxy_opts.proxy,
-//! retry: wallet_opts.proxy_opts.retries,
-//! timeout: None,
-//! stop_gap: 10
-//! });
+//! let blockchain_config = AnyBlockchainConfig::Electrum(ElectrumBlockchainConfig {
+//! url: wallet_opts.electrum_opts.server.clone(),
+//! socks5: wallet_opts.proxy_opts.proxy.clone(),
+//! retry: wallet_opts.proxy_opts.retries,
+//! timeout: wallet_opts.electrum_opts.timeout,
+//! stop_gap: wallet_opts.electrum_opts.stop_gap,
+//! });
+//! let blockchain = AnyBlockchain::from_config(&blockchain_config).expect("blockchain");
//!
//! let wallet = Wallet::new(
//! descriptor,
//! change_descriptor,
//! network,
//! database,
-//! AnyBlockchain::from_config(&config).unwrap(),
-//! ).unwrap();
+//! ).expect("wallet");
//!
-//! let result = bdk_cli::handle_online_wallet_subcommand(&wallet, online_subcommand).unwrap();
+//! let result = bdk_cli::handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand).expect("result");
//! println!("{}", serde_json::to_string_pretty(&result).unwrap());
//! }
//! # }
/// Execute an offline wallet sub-command
///
/// Offline wallet sub-commands are described in [`OfflineWalletSubCommand`].
-pub fn handle_offline_wallet_subcommand<T, D>(
- wallet: &Wallet<T, D>,
+pub fn handle_offline_wallet_subcommand<D>(
+ wallet: &Wallet<D>,
wallet_opts: &WalletOpts,
offline_subcommand: OfflineWalletSubCommand,
) -> Result<serde_json::Value, Error>
feature = "rpc"
))]
#[maybe_async]
-pub fn handle_online_wallet_subcommand<C, D>(
- wallet: &Wallet<C, D>,
+pub fn handle_online_wallet_subcommand<B, D>(
+ wallet: &Wallet<D>,
+ blockchain: &B,
online_subcommand: OnlineWalletSubCommand,
) -> Result<serde_json::Value, Error>
where
- C: Blockchain,
+ B: Blockchain,
D: BatchDatabase,
{
+ use bdk::SyncOptions;
+
match online_subcommand {
Sync { max_addresses } => {
- maybe_await!(wallet.sync(log_progress(), max_addresses))?;
+ maybe_await!(wallet.sync(
+ blockchain,
+ SyncOptions {
+ progress: Some(Box::new(log_progress())),
+ max_addresses,
+ }
+ ))?;
Ok(json!({}))
}
Broadcast { psbt, tx } => {
(Some(_), Some(_)) => panic!("Both `psbt` and `tx` options not allowed"),
(None, None) => panic!("Missing `psbt` and `tx` option"),
};
-
- let txid = maybe_await!(wallet.broadcast(&tx))?;
+ let txid = maybe_await!(blockchain.broadcast(&tx))?;
Ok(json!({ "txid": txid }))
}
#[cfg(feature = "reserves")]