use crate::error::BDKCliError as Error;
#[cfg(any(feature = "sqlite", feature = "redb"))]
use crate::persister::Persister;
+#[cfg(feature = "cbf")]
+use crate::utils::BlockchainClient::KyotoClient;
use crate::utils::*;
#[cfg(feature = "redb")]
use bdk_redb::Store as RedbStore;
};
use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
use serde_json::json;
-#[cfg(feature = "cbf")]
-use {crate::utils::BlockchainClient::KyotoClient, bdk_kyoto::LightClient, tokio::select};
#[cfg(feature = "electrum")]
use crate::utils::BlockchainClient::Electrum;
))]
pub(crate) async fn handle_online_wallet_subcommand(
wallet: &mut Wallet,
- client: BlockchainClient,
+ client: &BlockchainClient,
online_subcommand: OnlineWalletSubCommand,
) -> Result<String, Error> {
match online_subcommand {
client
.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
- let update = client.full_scan(request, _stop_gap, batch_size, false)?;
+ let update = client.full_scan(request, _stop_gap, *batch_size, false)?;
wallet.apply_update(update)?;
}
#[cfg(feature = "esplora")]
parallel_requests,
} => {
let update = client
- .full_scan(request, _stop_gap, parallel_requests)
+ .full_scan(request, _stop_gap, *parallel_requests)
.await
.map_err(|e| *e)?;
wallet.apply_update(update)?;
hash: genesis_block.block_hash(),
});
let mut emitter = Emitter::new(
- &*client,
+ client.as_ref(),
genesis_cp.clone(),
genesis_cp.height(),
NO_EXPECTED_MEMPOOL_TXS,
let result = handle_online_wallet_subcommand(
&mut wallet,
- blockchain_client,
+ &blockchain_client,
online_subcommand,
)
.await?;
let mut wallet = new_wallet(network, wallet_opts)?;
let blockchain_client =
crate::utils::new_blockchain_client(wallet_opts, &wallet, database_path)?;
- handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
+ handle_online_wallet_subcommand(&mut wallet, &blockchain_client, online_subcommand)
.await?
};
Ok(result)
} => {
let blockchain =
new_blockchain_client(wallet_opts, wallet, _datadir).map_err(|e| e.to_string())?;
- let value = handle_online_wallet_subcommand(wallet, blockchain, online_subcommand)
+ let value = handle_online_wallet_subcommand(wallet, &blockchain, online_subcommand)
.await
.map_err(|e| e.to_string())?;
Some(value)
feature = "rpc"
))]
/// Syncs a given wallet using the blockchain client.
-pub async fn sync_wallet(client: BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
+pub async fn sync_wallet(client: &BlockchainClient, wallet: &mut Wallet) -> Result<(), Error> {
#[cfg(any(feature = "electrum", feature = "esplora"))]
let request = wallet
.start_sync_with_revealed_spks()
// already have.
client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));
- let update = client.sync(request, batch_size, false)?;
+ let update = client.sync(request, *batch_size, false)?;
wallet
.apply_update(update)
.map_err(|e| Error::Generic(e.to_string()))
parallel_requests,
} => {
let update = client
- .sync(request, parallel_requests)
+ .sync(request, *parallel_requests)
.await
.map_err(|e| *e)?;
wallet
// reload the last 200 blocks in case of a reorg
let emitter_height = wallet_cp.height().saturating_sub(200);
let mut emitter = Emitter::new(
- &*client,
+ client.as_ref(),
wallet_cp,
emitter_height,
wallet
))]
/// Broadcasts a given transaction using the blockchain client.
pub async fn broadcast_transaction(
- client: BlockchainClient,
+ client: &BlockchainClient,
tx: Transaction,
) -> Result<Txid, Error> {
match client {
#[cfg(feature = "cbf")]
KyotoClient { client } => {
- let LightClient {
- requester,
- mut info_subscriber,
- mut warning_subscriber,
- update_subscriber: _,
- node,
- } = *client;
-
- let subscriber = tracing_subscriber::FmtSubscriber::new();
- tracing::subscriber::set_global_default(subscriber)
- .map_err(|e| Error::Generic(format!("SetGlobalDefault error: {e}")))?;
-
- tokio::task::spawn(async move { node.run().await });
- tokio::task::spawn(async move {
- select! {
- info = info_subscriber.recv() => {
- if let Some(info) = info {
- tracing::info!("{info}");
- }
- },
- warn = warning_subscriber.recv() => {
- if let Some(warn) = warn {
- tracing::warn!("{warn}");
- }
- }
- }
- });
let txid = tx.compute_txid();
- let wtxid = requester.broadcast_random(tx.clone()).await.map_err(|_| {
- tracing::warn!("Broadcast was unsuccessful");
- Error::Generic("Transaction broadcast timed out after 30 seconds".into())
- })?;
+ let wtxid = client
+ .requester
+ .broadcast_random(tx.clone())
+ .await
+ .map_err(|_| {
+ tracing::warn!("Broadcast was unsuccessful");
+ Error::Generic("Transaction broadcast timed out after 30 seconds".into())
+ })?;
tracing::info!("Successfully broadcast WTXID: {wtxid}");
Ok(txid)
}
directory: String,
max_fee_rate: Option<u64>,
ohttp_relays: Vec<String>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<String, Error> {
let address = self
.wallet
uri: String,
fee_rate: u64,
ohttp_relays: Vec<String>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<String, Error> {
let uri = payjoin::Uri::try_from(uri)
.map_err(|e| Error::Generic(format!("Failed parsing to Payjoin URI: {}", e)))?;
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
relay: impl payjoin::IntoUrl,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
match session {
ReceiveSession::Initialized(proposal) => {
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
relay: impl payjoin::IntoUrl,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let mut current_receiver_typestate = receiver;
let next_receiver_typestate = loop {
receiver: Receiver<UncheckedOriginalPayload>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let next_receiver_typestate = receiver
.assume_interactive_receiver()
receiver: Receiver<MaybeInputsOwned>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let next_receiver_typestate = receiver
.check_inputs_not_owned(&mut |input| {
receiver: Receiver<MaybeInputsSeen>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
// This is not supported as there is no persistence of previous Payjoin attempts in BDK CLI
// yet. If there is support either in the BDK persister or Payjoin persister, this can be
receiver: Receiver<OutputsUnknown>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let next_receiver_typestate = receiver.identify_receiver_outputs(&mut |output_script| {
Ok(self.wallet.is_mine(output_script.to_owned()))
receiver: Receiver<WantsOutputs>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
// This is a typestate to modify existing receiver-owned outputs in case the receiver wants
// to do that. This is a very simple implementation of Payjoin so we are just going
receiver: Receiver<WantsInputs>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let candidate_inputs: Vec<InputPair> = self
.wallet
receiver: Receiver<WantsFeeRange>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
max_fee_rate: FeeRate,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let next_receiver_typestate = receiver.apply_fee_range(None, Some(max_fee_rate)).save(persister).map_err(|e| {
Error::Generic(format!("Error occurred when saving after applying the receiver fee range to the transaction: {e}"))
&mut self,
receiver: Receiver<ProvisionalProposal>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let next_receiver_typestate = receiver
.finalize_proposal(|psbt| {
&mut self,
receiver: Receiver<PayjoinProposal>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let (req, ctx) = receiver.create_post_request(
self.relay_manager
&mut self,
receiver: Receiver<Monitor>,
persister: &impl SessionPersister<SessionEvent = ReceiverSessionEvent>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<(), Error> {
let wait_time_for_sync = 3;
let poll_internal = tokio::time::Duration::from_secs(wait_time_for_sync);
session: SendSession,
persister: &impl SessionPersister<SessionEvent = SenderSessionEvent>,
relay: impl payjoin::IntoUrl,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<Txid, Error> {
match session {
SendSession::WithReplyKey(context) => {
sender: Sender<WithReplyKey>,
relay: impl payjoin::IntoUrl,
persister: &impl SessionPersister<SessionEvent = SenderSessionEvent>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<Txid, Error> {
let (req, ctx) = sender.create_v2_post_request(relay.as_str()).map_err(|e| {
Error::Generic(format!(
sender: Sender<PollingForProposal>,
relay: impl payjoin::IntoUrl,
persister: &impl SessionPersister<SessionEvent = SenderSessionEvent>,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<Txid, Error> {
let mut sender = sender.clone();
loop {
async fn process_payjoin_proposal(
&self,
mut psbt: Psbt,
- blockchain_client: BlockchainClient,
+ blockchain_client: &BlockchainClient,
) -> Result<Txid, Error> {
if !self.wallet.sign(&mut psbt, SignOptions::default())? {
return Err(Error::Generic(