From b57bed3852a7d005b7f8546e5f74eb7ace0a7e75 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 5 Jun 2024 14:41:03 +0000 Subject: [PATCH] Minimal updates to `lightning-transaction-sync` for bindings Bindings don't accept dyn traits, but instead map any traits to a single dynamic struct. Thus, we can always take a specific trait to accept any implementation, which we do here. --- lightning-transaction-sync/src/common.rs | 8 ++++---- lightning-transaction-sync/src/electrum.rs | 8 +++++--- lightning-transaction-sync/src/error.rs | 2 ++ lightning-transaction-sync/src/esplora.rs | 12 +++++++----- lightning-transaction-sync/src/lib.rs | 6 +++--- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lightning-transaction-sync/src/common.rs b/lightning-transaction-sync/src/common.rs index c635f7385..c8c151a15 100644 --- a/lightning-transaction-sync/src/common.rs +++ b/lightning-transaction-sync/src/common.rs @@ -33,8 +33,8 @@ impl SyncState { pending_sync: false, } } - pub fn sync_unconfirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + pub fn sync_unconfirmed_transactions( + &mut self, confirmables: &Vec, unconfirmed_txs: Vec, ) { for txid in unconfirmed_txs { @@ -57,8 +57,8 @@ impl SyncState { } } - pub fn sync_confirmed_transactions( - &mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + pub fn sync_confirmed_transactions( + &mut self, confirmables: &Vec, confirmed_txs: Vec ) { for ctx in confirmed_txs { diff --git a/lightning-transaction-sync/src/electrum.rs b/lightning-transaction-sync/src/electrum.rs index d2cb7256f..0e0806fa5 100644 --- a/lightning-transaction-sync/src/electrum.rs +++ b/lightning-transaction-sync/src/electrum.rs @@ -1,3 +1,5 @@ +//! Chain sync using the electrum protocol + use crate::common::{ConfirmedTx, SyncState, FilterQueue}; use crate::error::{TxSyncError, InternalError}; @@ -83,7 +85,7 @@ where /// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`Filter`]: lightning::chain::Filter - pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> { + pub fn sync(&self, confirmables: Vec) -> Result<(), TxSyncError> { // This lock makes sure we're syncing once at a time. let mut sync_state = self.sync_state.lock().unwrap(); @@ -378,8 +380,8 @@ where Ok(confirmed_txs) } - fn get_unconfirmed_transactions( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + fn get_unconfirmed_transactions( + &self, confirmables: &Vec, ) -> Result, InternalError> { // Query the interface for relevant txids and check whether the relevant blocks are still // in the best chain, mark them unconfirmed otherwise diff --git a/lightning-transaction-sync/src/error.rs b/lightning-transaction-sync/src/error.rs index d1f4a319e..999395009 100644 --- a/lightning-transaction-sync/src/error.rs +++ b/lightning-transaction-sync/src/error.rs @@ -1,3 +1,5 @@ +//! Common error types + use std::fmt; #[derive(Debug)] diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs index bff7c52d3..3d19c1b3b 100644 --- a/lightning-transaction-sync/src/esplora.rs +++ b/lightning-transaction-sync/src/esplora.rs @@ -1,3 +1,5 @@ +//! Chain sync using the Esplora API + use crate::error::{TxSyncError, InternalError}; use crate::common::{SyncState, FilterQueue, ConfirmedTx}; @@ -84,7 +86,7 @@ where /// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager /// [`Filter`]: lightning::chain::Filter #[maybe_async] - pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> { + pub fn sync(&self, confirmables: Vec) -> Result<(), TxSyncError> { // This lock makes sure we're syncing once at a time. #[cfg(not(feature = "async-interface"))] let mut sync_state = self.sync_state.lock().unwrap(); @@ -239,8 +241,8 @@ where } #[maybe_async] - fn sync_best_block_updated( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, sync_state: &mut SyncState, tip_hash: &BlockHash, + fn sync_best_block_updated( + &self, confirmables: &Vec, sync_state: &mut SyncState, tip_hash: &BlockHash, ) -> Result<(), InternalError> { // Inform the interface of the new block. @@ -369,8 +371,8 @@ where } #[maybe_async] - fn get_unconfirmed_transactions( - &self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, + fn get_unconfirmed_transactions( + &self, confirmables: &Vec, ) -> Result, InternalError> { // Query the interface for relevant txids and check whether the relevant blocks are still // in the best chain, mark them unconfirmed otherwise diff --git a/lightning-transaction-sync/src/lib.rs b/lightning-transaction-sync/src/lib.rs index 7bd4b4aee..ad6ff4bff 100644 --- a/lightning-transaction-sync/src/lib.rs +++ b/lightning-transaction-sync/src/lib.rs @@ -71,15 +71,15 @@ extern crate bdk_macros; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))] -mod esplora; +pub mod esplora; #[cfg(any(feature = "electrum"))] -mod electrum; +pub mod electrum; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] mod common; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] -mod error; +pub mod error; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] pub use error::TxSyncError; -- 2.39.5