From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Fri, 23 Apr 2021 19:13:23 +0000 (+0000) Subject: Merge pull request #889 from jkczyz/2021-04-electrum-trait X-Git-Tag: v0.0.14~18 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0d75a63ead0601ae36e7141834f67c881c31eb85;hp=-c;p=rust-lightning Merge pull request #889 from jkczyz/2021-04-electrum-trait Define chain::Confirm trait for use by Electrum clients --- 0d75a63ead0601ae36e7141834f67c881c31eb85 diff --combined lightning/src/chain/channelmonitor.rs index 573d19df,d6fd023b..f0b23c08 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@@ -746,7 -746,7 +746,7 @@@ pub(crate) struct ChannelMonitorImpl); +pub type TransactionOutputs = (Txid, Vec<(u32, TxOut)>); #[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] /// Used only in testing and fuzztarget to check serialization roundtrips don't change the @@@ -1311,11 -1311,9 +1311,9 @@@ impl ChannelMonitor( &self, header: &BlockHeader, @@@ -1337,11 -1335,9 +1335,9 @@@ /// Processes a transaction that was reorganized out of the chain. /// /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather - /// than blocks. May be called before or after [`update_best_block`] for transactions in the - /// corresponding block. See [`update_best_block`] for further calling expectations. + /// than blocks. See [`chain::Confirm`] for calling expectations. /// /// [`block_disconnected`]: Self::block_disconnected - /// [`update_best_block`]: Self::update_best_block pub fn transaction_unconfirmed( &self, txid: &Txid, @@@ -1361,18 -1357,10 +1357,10 @@@ /// [`block_connected`] for details. /// /// Used instead of [`block_connected`] by clients that are notified of transactions rather than - /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding - /// block. - /// - /// Must be called after new blocks become available for the most recent block. Intermediary - /// blocks, however, may be safely skipped. In the event of a chain re-organization, this only - /// needs to be called for the most recent block assuming `transaction_unconfirmed` is called - /// for any affected transactions. + /// blocks. See [`chain::Confirm`] for calling expectations. /// /// [`block_connected`]: Self::block_connected - /// [`transactions_confirmed`]: Self::transactions_confirmed - /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed - pub fn update_best_block( + pub fn best_block_updated( &self, header: &BlockHeader, height: u32, @@@ -1385,7 -1373,7 +1373,7 @@@ F::Target: FeeEstimator, L::Target: Logger, { - self.inner.lock().unwrap().update_best_block( + self.inner.lock().unwrap().best_block_updated( header, height, broadcaster, fee_estimator, logger) } @@@ -2109,7 -2097,7 +2097,7 @@@ impl ChannelMonitorImpl( + fn best_block_updated( &mut self, header: &BlockHeader, height: u32, @@@ -2727,6 -2715,29 +2715,29 @@@ wher } } + impl chain::Confirm for (ChannelMonitor, T, F, L) + where + T::Target: BroadcasterInterface, + F::Target: FeeEstimator, + L::Target: Logger, + { + fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) { + self.0.transactions_confirmed(header, txdata, height, &*self.1, &*self.2, &*self.3); + } + + fn transaction_unconfirmed(&self, txid: &Txid) { + self.0.transaction_unconfirmed(txid, &*self.1, &*self.2, &*self.3); + } + + fn best_block_updated(&self, header: &BlockHeader, height: u32) { + self.0.best_block_updated(header, height, &*self.1, &*self.2, &*self.3); + } + + fn get_relevant_txids(&self) -> Vec { + self.0.get_relevant_txids() + } + } + const MAX_ALLOC_SIZE: usize = 64*1024; impl<'a, Signer: Sign, K: KeysInterface> ReadableArgs<&'a K>