Skip to content

Commit

Permalink
Merge pull request #82 from rustaceanrob/update-12-12
Browse files Browse the repository at this point in the history
Update `bdk_wallet` to `beta-6`
  • Loading branch information
rustaceanrob authored Dec 12, 2024
2 parents 952e3f9 + e52d0e4 commit 9d81919
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions examples/events.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 2 additions & 1 deletion examples/wallet.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
18 changes: 3 additions & 15 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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<KeychainKind>,
/// 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> {
Expand Down
32 changes: 23 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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};
Expand All @@ -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};
Expand All @@ -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<KeychainKind>,
/// 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)]
Expand Down Expand Up @@ -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<FullScanResult<K>> {
pub async fn update(&mut self, logger: &dyn NodeEventHandler) -> Option<FullScanResponse<K>> {
let mut chain_changeset = BTreeMap::new();
while let Ok(message) = self.receiver.recv().await {
self.log(&message, logger);
Expand Down Expand Up @@ -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<K> {
fn get_scan_response(&mut self) -> FullScanResponse<K> {
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()),
Expand Down Expand Up @@ -451,7 +465,7 @@ pub enum Event<K: fmt::Debug + Clone + Ord> {
///
/// This event will be emitted every time a new block is found while the node
/// is running and is connected to peers.
ScanResponse(FullScanResult<K>),
ScanResponse(FullScanResponse<K>),
/// Blocks were reorganized from the chain of most work.
///
/// ## Note
Expand Down
6 changes: 3 additions & 3 deletions tests/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9d81919

Please sign in to comment.