MCPcopy Create free account
hub / github.com/bitcoindevkit/bdk-cli / new_blockchain_client

Function new_blockchain_client

src/utils.rs:179–256  ·  view source on GitHub ↗

Create a new blockchain from the wallet configuration options.

(
    wallet_opts: &WalletOpts,
    _wallet: &Wallet,
    _datadir: PathBuf,
)

Source from the content-addressed store, hash-verified

177))]
178/// Create a new blockchain from the wallet configuration options.
179pub(crate) fn new_blockchain_client(
180 wallet_opts: &WalletOpts,
181 _wallet: &Wallet,
182 _datadir: PathBuf,
183) -> Result<BlockchainClient, Error> {
184 #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
185 let url = &wallet_opts.url;
186 let client = match wallet_opts.client_type {
187 #[cfg(feature = "electrum")]
188 ClientType::Electrum => {
189 let client = bdk_electrum::electrum_client::Client::new(url)
190 .map(bdk_electrum::BdkElectrumClient::new)?;
191 BlockchainClient::Electrum {
192 client: Box::new(client),
193 batch_size: wallet_opts.batch_size,
194 }
195 }
196 #[cfg(feature = "esplora")]
197 ClientType::Esplora => {
198 let client = bdk_esplora::esplora_client::Builder::new(url).build_async()?;
199 BlockchainClient::Esplora {
200 client: Box::new(client),
201 parallel_requests: wallet_opts.parallel_requests,
202 }
203 }
204
205 #[cfg(feature = "rpc")]
206 ClientType::Rpc => {
207 let auth = match &wallet_opts.cookie {
208 Some(cookie) => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::CookieFile(cookie.into()),
209 None => bdk_bitcoind_rpc::bitcoincore_rpc::Auth::UserPass(
210 wallet_opts.basic_auth.0.clone(),
211 wallet_opts.basic_auth.1.clone(),
212 ),
213 };
214 let client = bdk_bitcoind_rpc::bitcoincore_rpc::Client::new(url, auth)
215 .map_err(|e| Error::Generic(e.to_string()))?;
216 BlockchainClient::RpcClient {
217 client: Box::new(client),
218 }
219 }
220
221 #[cfg(feature = "cbf")]
222 ClientType::Cbf => {
223 let scan_type = Sync;
224 let builder = Builder::new(_wallet.network());
225
226 let light_client = builder
227 .required_peers(wallet_opts.compactfilter_opts.conn_count)
228 .data_dir(&_datadir)
229 .build_with_wallet(_wallet, scan_type)?;
230
231 let LightClient {
232 requester,
233 info_subscriber,
234 warning_subscriber,
235 update_subscriber,
236 node,

Callers 2

handle_commandFunction · 0.85
respondFunction · 0.85

Calls 1

trace_loggerFunction · 0.85

Tested by

no test coverage detected