diff --git a/Cargo.toml b/Cargo.toml index 8e28fbc..c46c162 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,13 @@ edition = "2021" rust-version = "1.63.0" [dependencies] -bdk_chain = { version = "0.20.0" } +bdk_chain = { version = "0.21.0" } kyoto-cbf = { version = "0.6.0", default-features = false, features = ["dns"] } tracing = { version = "0.1", optional = true } tracing-subscriber = { version = "0.3", optional = true } [dependencies.bdk_wallet] -version = "1.0.0-beta.5" +version = "1.0.0-beta.6" optional = true [features] diff --git a/examples/events.rs b/examples/events.rs index b0b5c3b..e39f257 100644 --- a/examples/events.rs +++ b/examples/events.rs @@ -1,5 +1,5 @@ -use bdk_kyoto::builder::{LightClient, LightClientBuilder}; -use bdk_kyoto::{Event, LogLevel}; +use bdk_kyoto::builder::LightClientBuilder; +use bdk_kyoto::{Event, LightClient, LogLevel}; use bdk_wallet::bitcoin::Network; use bdk_wallet::Wallet; diff --git a/examples/wallet.rs b/examples/wallet.rs index 2dcc7ca..4e8b640 100644 --- a/examples/wallet.rs +++ b/examples/wallet.rs @@ -1,7 +1,8 @@ use std::net::{IpAddr, Ipv4Addr}; -use bdk_kyoto::builder::{LightClient, LightClientBuilder, ServiceFlags, TrustedPeer}; +use bdk_kyoto::builder::{LightClientBuilder, ServiceFlags, TrustedPeer}; use bdk_kyoto::logger::TraceLogger; +use bdk_kyoto::LightClient; use bdk_wallet::bitcoin::Network; use bdk_wallet::{KeychainKind, Wallet}; diff --git a/src/builder.rs b/src/builder.rs index dcdbff9..4e859f5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -13,8 +13,9 @@ //! use std::time::Duration; //! use bdk_wallet::Wallet; //! use bdk_wallet::bitcoin::Network; -//! use bdk_kyoto::builder::{LightClientBuilder, LightClient, TrustedPeer}; +//! use bdk_kyoto::builder::{LightClientBuilder, TrustedPeer}; //! use bdk_kyoto::logger::PrintLogger; +//! use bdk_kyoto::LightClient; //! //! #[tokio::main] //! async fn main() -> anyhow::Result<()> { @@ -48,29 +49,16 @@ use std::{collections::HashSet, path::PathBuf, time::Duration}; use bdk_chain::local_chain::MissingGenesisError; use bdk_wallet::{KeychainKind, Wallet}; -use kyoto::core::builder::NodeDefault; -use kyoto::ClientSender as EventSender; use kyoto::NodeBuilder; pub use kyoto::{ db::error::SqlInitializationError, AddrV2, HeaderCheckpoint, ScriptBuf, ServiceFlags, TrustedPeer, }; -use crate::EventReceiver; +use crate::{EventReceiver, LightClient}; const RECOMMENDED_PEERS: u8 = 2; -#[derive(Debug)] -/// A node and associated structs to send and receive events to and from the node. -pub struct LightClient { - /// Send events to a running node (i.e. broadcast a transaction). - pub sender: EventSender, - /// Receive wallet updates from a node. - pub receiver: EventReceiver, - /// The underlying node that must be run to fetch blocks from peers. - pub node: NodeDefault, -} - #[derive(Debug)] /// Construct a light client from a [`Wallet`] reference. pub struct LightClientBuilder<'a> { diff --git a/src/lib.rs b/src/lib.rs index d580357..d7beb72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,8 +24,9 @@ //! # const CHANGE: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)"; //! use bdk_wallet::Wallet; //! use bdk_wallet::bitcoin::Network; -//! use bdk_kyoto::builder::{LightClientBuilder, LightClient}; +//! use bdk_kyoto::builder::LightClientBuilder; //! use bdk_kyoto::logger::PrintLogger; +//! use bdk_kyoto::LightClient; //! //! #[tokio::main] //! async fn main() -> anyhow::Result<()> { @@ -53,8 +54,8 @@ //! ```no_run //! # const RECEIVE: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)"; //! # const CHANGE: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)"; -//! # use bdk_kyoto::builder::{LightClientBuilder, LightClient}; -//! # use bdk_kyoto::{Event, LogLevel}; +//! # use bdk_kyoto::builder::LightClientBuilder; +//! # use bdk_kyoto::{Event, LogLevel, LightClient}; //! # use bdk_wallet::bitcoin::Network; //! # use bdk_wallet::Wallet; //! #[tokio::main] @@ -163,7 +164,7 @@ use std::collections::BTreeMap; use bdk_chain::{ keychain_txout::KeychainTxOutIndex, local_chain::{self, CheckPoint, LocalChain}, - spk_client::FullScanResult, + spk_client::FullScanResponse, IndexedTxGraph, }; use bdk_chain::{ConfirmationBlockTime, TxUpdate}; @@ -173,12 +174,13 @@ pub use bdk_chain::local_chain::MissingGenesisError; pub extern crate kyoto; +#[cfg(feature = "wallet")] +use bdk_wallet::KeychainKind; #[cfg(feature = "rusqlite")] pub use kyoto::core::builder::NodeDefault; #[cfg(feature = "events")] pub use kyoto::{DisconnectedHeader, FailurePayload}; -#[cfg(all(feature = "wallet", feature = "rusqlite"))] pub use kyoto::ClientSender as EventSender; use kyoto::{IndexedBlock, NodeMessage, RejectReason}; pub use kyoto::{NodeState, Receiver, SyncUpdate, TxBroadcast, TxBroadcastPolicy, Txid, Warning}; @@ -188,6 +190,18 @@ pub mod builder; #[cfg(feature = "callbacks")] pub mod logger; +#[cfg(feature = "wallet")] +#[derive(Debug)] +/// A node and associated structs to send and receive events to and from the node. +pub struct LightClient { + /// Send events to a running node (i.e. broadcast a transaction). + pub sender: EventSender, + /// Receive wallet updates from a node. + pub receiver: EventReceiver, + /// The underlying node that must be run to fetch blocks from peers. + pub node: NodeDefault, +} + /// Interpret events from a node that is running to apply /// updates to an underlying wallet. #[derive(Debug)] @@ -228,7 +242,7 @@ where /// running node. Production applications should define how the application handles /// these events and displays them to end users. #[cfg(feature = "callbacks")] - pub async fn update(&mut self, logger: &dyn NodeEventHandler) -> Option> { + pub async fn update(&mut self, logger: &dyn NodeEventHandler) -> Option> { let mut chain_changeset = BTreeMap::new(); while let Ok(message) = self.receiver.recv().await { self.log(&message, logger); @@ -307,12 +321,12 @@ where // When the client is believed to have synced to the chain tip of most work, // we can return a wallet update. - fn get_scan_response(&mut self) -> FullScanResult { + fn get_scan_response(&mut self) -> FullScanResponse { let tx_update = TxUpdate::from(self.graph.graph().clone()); let graph = core::mem::take(&mut self.graph); let last_active_indices = graph.index.last_used_indices(); self.graph = IndexedTxGraph::new(graph.index); - FullScanResult { + FullScanResponse { tx_update, last_active_indices, chain_update: Some(self.chain.tip()), @@ -451,7 +465,7 @@ pub enum Event { /// /// This event will be emitted every time a new block is found while the node /// is running and is connected to peers. - ScanResponse(FullScanResult), + ScanResponse(FullScanResponse), /// Blocks were reorganized from the chain of most work. /// /// ## Note diff --git a/tests/client.rs b/tests/client.rs index b12e4a5..615da22 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -1,5 +1,5 @@ // #![allow(unused)] -use bdk_kyoto::builder::LightClient; +use bdk_kyoto::LightClient; use std::net::IpAddr; use std::time::Duration; use tokio::task; @@ -13,7 +13,7 @@ use bdk_testenv::bitcoincore_rpc::RpcApi; use bdk_testenv::bitcoind; use bdk_testenv::TestEnv; use bdk_wallet::bitcoin::{Amount, Network}; -use bdk_wallet::chain::spk_client::FullScanResult; +use bdk_wallet::chain::spk_client::FullScanResponse; use bdk_wallet::CreateParams; use bdk_wallet::KeychainKind; @@ -93,7 +93,7 @@ async fn update_returns_blockchain_data() -> anyhow::Result<()> { let logger = PrintLogger::new(); // get update let res = receiver.update(&logger).await.expect("should have update"); - let FullScanResult { + let FullScanResponse { tx_update, chain_update, last_active_indices,