Skip to content

Commit 777ce7b

Browse files
committed
Make confirmables Deref
.. the bindings branch needed a small patch as it doesn't support `dyn` traits. Here, we opt to use `Deref` in the hopes this works with bindings, rendering the patch unnecessary.
1 parent 2701bc5 commit 777ce7b

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

lightning-transaction-sync/src/common.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bitcoin::{Txid, BlockHash, Transaction, OutPoint};
44
use bitcoin::block::Header;
55

66
use std::collections::{HashSet, HashMap};
7+
use std::ops::Deref;
78

89

910
// Represents the current state.
@@ -33,10 +34,12 @@ impl SyncState {
3334
pending_sync: false,
3435
}
3536
}
36-
pub fn sync_unconfirmed_transactions(
37-
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
37+
pub fn sync_unconfirmed_transactions<C: Deref>(
38+
&mut self, confirmables: &Vec<C>,
3839
unconfirmed_txs: Vec<Txid>,
39-
) {
40+
)
41+
where C::Target: Confirm,
42+
{
4043
for txid in unconfirmed_txs {
4144
for c in confirmables {
4245
c.transaction_unconfirmed(&txid);
@@ -57,10 +60,12 @@ impl SyncState {
5760
}
5861
}
5962

60-
pub fn sync_confirmed_transactions(
61-
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
63+
pub fn sync_confirmed_transactions<C: Deref>(
64+
&mut self, confirmables: &Vec<C>,
6265
confirmed_txs: Vec<ConfirmedTx>
63-
) {
66+
)
67+
where C::Target: Confirm,
68+
{
6469
for ctx in confirmed_txs {
6570
for c in confirmables {
6671
c.transactions_confirmed(

lightning-transaction-sync/src/electrum.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ where
8383
/// [`ChainMonitor`]: lightning::chain::chainmonitor::ChainMonitor
8484
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
8585
/// [`Filter`]: lightning::chain::Filter
86-
pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> {
86+
pub fn sync<C: Deref>(&self, confirmables: Vec<C>) -> Result<(), TxSyncError>
87+
where C::Target: Confirm
88+
{
8789
// This lock makes sure we're syncing once at a time.
8890
let mut sync_state = self.sync_state.lock().unwrap();
8991

@@ -378,9 +380,11 @@ where
378380
Ok(confirmed_txs)
379381
}
380382

381-
fn get_unconfirmed_transactions(
382-
&self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
383-
) -> Result<Vec<Txid>, InternalError> {
383+
fn get_unconfirmed_transactions<C: Deref>(
384+
&self, confirmables: &Vec<C>,
385+
) -> Result<Vec<Txid>, InternalError>
386+
where C::Target: Confirm
387+
{
384388
// Query the interface for relevant txids and check whether the relevant blocks are still
385389
// in the best chain, mark them unconfirmed otherwise
386390
let relevant_txids = confirmables

lightning-transaction-sync/src/esplora.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ where
8484
/// [`ChannelManager`]: lightning::ln::channelmanager::ChannelManager
8585
/// [`Filter`]: lightning::chain::Filter
8686
#[maybe_async]
87-
pub fn sync(&self, confirmables: Vec<&(dyn Confirm + Sync + Send)>) -> Result<(), TxSyncError> {
87+
pub fn sync<C: Deref>(&self, confirmables: Vec<C>) -> Result<(), TxSyncError>
88+
where C::Target: Confirm
89+
{
8890
// This lock makes sure we're syncing once at a time.
8991
#[cfg(not(feature = "async-interface"))]
9092
let mut sync_state = self.sync_state.lock().unwrap();
@@ -239,10 +241,11 @@ where
239241
}
240242

241243
#[maybe_async]
242-
fn sync_best_block_updated(
243-
&self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, sync_state: &mut SyncState, tip_hash: &BlockHash,
244-
) -> Result<(), InternalError> {
245-
244+
fn sync_best_block_updated<C: Deref>(
245+
&self, confirmables: &Vec<C>, sync_state: &mut SyncState, tip_hash: &BlockHash,
246+
) -> Result<(), InternalError>
247+
where C::Target: Confirm
248+
{
246249
// Inform the interface of the new block.
247250
let tip_header = maybe_await!(self.client.get_header_by_hash(tip_hash))?;
248251
let tip_status = maybe_await!(self.client.get_block_status(&tip_hash))?;
@@ -369,9 +372,11 @@ where
369372
}
370373

371374
#[maybe_async]
372-
fn get_unconfirmed_transactions(
373-
&self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
374-
) -> Result<Vec<Txid>, InternalError> {
375+
fn get_unconfirmed_transactions<C: Deref>(
376+
&self, confirmables: &Vec<C>,
377+
) -> Result<Vec<Txid>, InternalError>
378+
where C::Target: Confirm
379+
{
375380
// Query the interface for relevant txids and check whether the relevant blocks are still
376381
// in the best chain, mark them unconfirmed otherwise
377382
let relevant_txids = confirmables

0 commit comments

Comments
 (0)