diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index a3c08cbd..f5479116 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -783,13 +783,13 @@ pub enum TxidParseError { } #[derive(Debug, thiserror::Error, uniffi::Error)] -pub enum LightClientBuilderError { +pub enum CbfBuilderError { #[error("the database could not be opened or created: {reason}")] DatabaseError { reason: String }, } #[derive(Debug, thiserror::Error, uniffi::Error)] -pub enum LightClientError { +pub enum CbfError { #[error("the node is no longer running")] NodeStopped, } @@ -1515,17 +1515,17 @@ impl From for SqliteError { } } -impl From for LightClientBuilderError { +impl From for CbfBuilderError { fn from(value: bdk_kyoto::builder::SqlInitializationError) -> Self { - LightClientBuilderError::DatabaseError { + CbfBuilderError::DatabaseError { reason: value.to_string(), } } } -impl From for LightClientError { +impl From for CbfError { fn from(_value: bdk_kyoto::kyoto::ClientError) -> Self { - LightClientError::NodeStopped + CbfError::NodeStopped } } diff --git a/bdk-ffi/src/kyoto.rs b/bdk-ffi/src/kyoto.rs index 0a9d4d3b..e1d240c2 100644 --- a/bdk-ffi/src/kyoto.rs +++ b/bdk-ffi/src/kyoto.rs @@ -1,4 +1,4 @@ -use bdk_kyoto::builder::LightClientBuilder as BDKLightClientBuilder; +use bdk_kyoto::builder::LightClientBuilder as BDKCbfBuilder; use bdk_kyoto::builder::ServiceFlags; use bdk_kyoto::builder::TrustedPeer; use bdk_kyoto::kyoto::tokio; @@ -24,7 +24,7 @@ use std::time::Duration; use tokio::sync::Mutex; use crate::bitcoin::Transaction; -use crate::error::{LightClientBuilderError, LightClientError}; +use crate::error::{CbfBuilderError, CbfError}; use crate::wallet::Wallet; use crate::FeeRate; use crate::Update; @@ -35,35 +35,35 @@ const TIMEOUT: u64 = 10; const DEFAULT_CONNECTIONS: u8 = 2; const CWD_PATH: &str = "."; -/// Receive a [`Client`] and [`LightNode`]. +/// Receive a [`CbfClient`] and [`CbfNode`]. #[derive(Debug, uniffi::Record)] -pub struct LightClient { +pub struct CbfComponents { /// Publish events to the node, like broadcasting transactions or adding scripts. - pub client: Arc, + pub client: Arc, /// The node to run and fetch transactions for a [`Wallet`]. - pub node: Arc, + pub node: Arc, } -/// A [`Client`] handles wallet updates from a [`LightNode`]. +/// A [`CbfClient`] handles wallet updates from a [`CbfNode`]. #[derive(Debug, uniffi::Object)] -pub struct Client { +pub struct CbfClient { sender: Arc, log_rx: Mutex>, warning_rx: Mutex>, update_rx: Mutex, } -/// A [`LightNode`] gathers transactions for a [`Wallet`]. +/// A [`CbfNode`] gathers transactions for a [`Wallet`]. /// To receive [`Update`] for [`Wallet`], refer to the -/// [`Client`]. The [`LightNode`] will run until instructed +/// [`CbfClient`]. The [`CbfNode`] will run until instructed /// to stop. #[derive(Debug, uniffi::Object)] -pub struct LightNode { +pub struct CbfNode { node: NodeDefault, } #[uniffi::export] -impl LightNode { +impl CbfNode { /// Start the node on a detached OS thread and immediately return. pub fn run(self: Arc) { std::thread::spawn(|| { @@ -92,7 +92,7 @@ impl LightNode { /// `lookahead` value will be used. To ensure all transactions are recovered, the /// `lookahead` should be roughly the number of transactions in the wallet history. #[derive(Clone, uniffi::Object)] -pub struct LightClientBuilder { +pub struct CbfBuilder { connections: u8, data_dir: Option, scan_type: ScanType, @@ -102,11 +102,11 @@ pub struct LightClientBuilder { } #[uniffi::export] -impl LightClientBuilder { - /// Start a new [`LightClientBuilder`] +impl CbfBuilder { + /// Start a new [`CbfBuilder`] #[uniffi::constructor] pub fn new() -> Self { - LightClientBuilder { + CbfBuilder { connections: DEFAULT_CONNECTIONS, data_dir: None, scan_type: ScanType::default(), @@ -118,7 +118,7 @@ impl LightClientBuilder { /// The number of connections for the light client to maintain. Default is two. pub fn connections(&self, connections: u8) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { connections, ..self.clone() }) @@ -127,7 +127,7 @@ impl LightClientBuilder { /// Directory to store block headers and peers. If none is provided, the current /// working directory will be used. pub fn data_dir(&self, data_dir: String) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { data_dir: Some(data_dir), ..self.clone() }) @@ -135,7 +135,7 @@ impl LightClientBuilder { /// Select between syncing, recovering, or scanning for new wallets. pub fn scan_type(&self, scan_type: ScanType) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { scan_type, ..self.clone() }) @@ -144,7 +144,7 @@ impl LightClientBuilder { /// Set the log level for the node. Production applications may want to omit `Debug` messages /// to avoid heap allocations. pub fn log_level(&self, log_level: LogLevel) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { log_level, ..self.clone() }) @@ -152,7 +152,7 @@ impl LightClientBuilder { /// Bitcoin full-nodes to attempt a connection with. pub fn peers(&self, peers: Vec) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { peers, ..self.clone() }) @@ -161,14 +161,14 @@ impl LightClientBuilder { /// Configure a custom DNS resolver when querying DNS seeds. Default is `1.1.1.1` managed by /// CloudFlare. pub fn dns_resolver(&self, dns_resolver: Arc) -> Arc { - Arc::new(LightClientBuilder { + Arc::new(CbfBuilder { dns_resolver: Some(dns_resolver), ..self.clone() }) } - /// Construct a [`LightClient`] for a [`Wallet`]. - pub fn build(&self, wallet: &Wallet) -> Result { + /// Construct a [`CbfComponents`] for a [`Wallet`]. + pub fn build(&self, wallet: &Wallet) -> Result { let wallet = wallet.get_wallet(); let mut trusted_peers = Vec::new(); @@ -181,7 +181,7 @@ impl LightClientBuilder { .map(|path| PathBuf::from(&path)) .unwrap_or(PathBuf::from(CWD_PATH)); - let mut builder = BDKLightClientBuilder::new() + let mut builder = BDKCbfBuilder::new() .connections(self.connections) .data_dir(path_buf) .scan_type(self.scan_type.into()) @@ -201,16 +201,16 @@ impl LightClientBuilder { node, } = builder.build(&wallet)?; - let node = LightNode { node }; + let node = CbfNode { node }; - let client = Client { + let client = CbfClient { sender: Arc::new(requester), log_rx: Mutex::new(log_subscriber), warning_rx: Mutex::new(warning_subscriber), update_rx: Mutex::new(update_subscriber), }; - Ok(LightClient { + Ok(CbfComponents { client: Arc::new(client), node: Arc::new(node), }) @@ -218,25 +218,25 @@ impl LightClientBuilder { } #[uniffi::export] -impl Client { +impl CbfClient { /// Return the next available log message from a node. If none is returned, the node has stopped. - pub async fn next_log(&self) -> Result { + pub async fn next_log(&self) -> Result { let mut log_rx = self.log_rx.lock().await; log_rx .recv() .await .map(|log| log.into()) - .ok_or(LightClientError::NodeStopped) + .ok_or(CbfError::NodeStopped) } /// Return the next available warning message from a node. If none is returned, the node has stopped. - pub async fn next_warning(&self) -> Result { + pub async fn next_warning(&self) -> Result { let mut warn_rx = self.warning_rx.lock().await; warn_rx .recv() .await .map(|warn| warn.into()) - .ok_or(LightClientError::NodeStopped) + .ok_or(CbfError::NodeStopped) } /// Return an [`Update`]. This is method returns once the node syncs to the rest of @@ -250,7 +250,7 @@ impl Client { /// a transaction or revealing a receive address. /// /// Note that only future blocks will be checked for these scripts, not past blocks. - pub async fn add_revealed_scripts(&self, wallet: &Wallet) -> Result<(), LightClientError> { + pub async fn add_revealed_scripts(&self, wallet: &Wallet) -> Result<(), CbfError> { let script_iter: Vec = { let wallet_lock = wallet.get_wallet(); wallet_lock.peek_revealed_plus_lookahead().collect() @@ -259,23 +259,23 @@ impl Client { self.sender .add_script(script) .await - .map_err(|_| LightClientError::NodeStopped)? + .map_err(|_| CbfError::NodeStopped)? } Ok(()) } /// Broadcast a transaction to the network, erroring if the node has stopped running. - pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), LightClientError> { + pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), CbfError> { let tx = transaction.into(); self.sender.broadcast_random(tx).await.map_err(From::from) } /// The minimum fee rate required to broadcast a transcation to all connected peers. - pub async fn min_broadcast_feerate(&self) -> Result, LightClientError> { + pub async fn min_broadcast_feerate(&self) -> Result, CbfError> { self.sender .broadcast_min_feerate() .await - .map_err(|_| LightClientError::NodeStopped) + .map_err(|_| CbfError::NodeStopped) .map(|fee| Arc::new(FeeRate(fee))) } @@ -284,8 +284,8 @@ impl Client { self.sender.is_running().await } - /// Stop the [`LightNode`]. Errors if the node is already stopped. - pub async fn shutdown(&self) -> Result<(), LightClientError> { + /// Stop the [`CbfNode`]. Errors if the node is already stopped. + pub async fn shutdown(&self) -> Result<(), CbfError> { self.sender.shutdown().await.map_err(From::from) } } diff --git a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveKyotoTest.kt b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveKyotoTest.kt index 47afbf9f..9df9ca6c 100644 --- a/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveKyotoTest.kt +++ b/bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/LiveKyotoTest.kt @@ -32,7 +32,7 @@ class LiveKyotoTest { val wallet: Wallet = Wallet(descriptor, changeDescriptor, Network.SIGNET, conn) val peers = listOf(peer) runBlocking { - val lightClient = LightClientBuilder() + val lightClient = CbfBuilder() .peers(peers) .connections(1u) .scanType(ScanType.New) diff --git a/bdk-python/tests/test_live_kyoto.py b/bdk-python/tests/test_live_kyoto.py index 3892c247..1fb30d76 100644 --- a/bdk-python/tests/test_live_kyoto.py +++ b/bdk-python/tests/test_live_kyoto.py @@ -1,4 +1,4 @@ -from bdkpython import Connection, Client, Network, Descriptor, KeychainKind, LightClientBuilder, LightClient, LightNode, IpAddress, ScanType, Peer, Update, Wallet +from bdkpython import Connection, Client, Network, Descriptor, KeychainKind, CbfBuilder, CbfComponents, CbfClient, CbfNode, IpAddress, ScanType, Peer, Update, Wallet import unittest import os import asyncio @@ -36,9 +36,9 @@ async def testKyoto(self) -> None: connection ) peers = [peer] - light_client: LightClient = LightClientBuilder().scan_type(ScanType.NEW()).peers(peers).connections(1).build(wallet) - client: Client = light_client.client - node: LightNode = light_client.node + light_client: CbfComponents = CbfBuilder().scan_type(ScanType.NEW()).peers(peers).connections(1).build(wallet) + client: CbfClient = light_client.client + node: CbfNode = light_client.node async def log_loop(client: Client): while True: log = await client.next_log() diff --git a/bdk-swift/Tests/BitcoinDevKitTests/LiveKyotoTests.swift b/bdk-swift/Tests/BitcoinDevKitTests/LiveKyotoTests.swift index 5b0a2b3d..376855ce 100644 --- a/bdk-swift/Tests/BitcoinDevKitTests/LiveKyotoTests.swift +++ b/bdk-swift/Tests/BitcoinDevKitTests/LiveKyotoTests.swift @@ -29,7 +29,7 @@ final class LiveKyotoTests: XCTestCase { connection: connection ) let trustedPeer = Peer(address: peer, port: nil, v2Transport: false) - let lightClient = try LightClientBuilder() + let lightClient = try CbfBuilder() .peers(peers: [trustedPeer]) .connections(connections: 1) .scanType(scanType: ScanType.new)