@@ -1835,17 +1835,42 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1835
1835
Vec :: new ( )
1836
1836
}
1837
1837
1838
+ /// Checks if a given transaction matches the funding transaction or spends any watched outputs.
1839
+ fn does_tx_match ( & self , tx : & Transaction ) -> bool {
1840
+ let funding_txo = self . get_funding_txo ( ) ;
1841
+ if tx. txid ( ) == funding_txo. 0 . txid {
1842
+ for output in tx. output . iter ( ) {
1843
+ if output. script_pubkey == funding_txo. 1 {
1844
+ return true ;
1845
+ }
1846
+ }
1847
+ }
1848
+
1849
+ for input in tx. input . iter ( ) {
1850
+ for ( txid, outputs) in self . get_outputs_to_watch ( ) . iter ( ) {
1851
+ for ( idx, _script_pubkey) in outputs. iter ( ) . enumerate ( ) {
1852
+ if txid == & input. previous_output . txid && idx == input. previous_output . vout as usize {
1853
+ return true ;
1854
+ }
1855
+ }
1856
+ }
1857
+ }
1858
+
1859
+ false
1860
+ }
1861
+
1838
1862
/// Determines if any HTLCs have been resolved on chain in the connected block.
1839
1863
///
1840
- /// Returns any transaction outputs from `txn_matched` that spends of should be watched for.
1841
- /// After called these are also available via [`get_outputs_to_watch`].
1864
+ /// Returns any new outputs to watch from `txdata`. After called, these are also included in
1865
+ /// [`get_outputs_to_watch`].
1842
1866
///
1843
1867
/// [`get_outputs_to_watch`]: #method.get_outputs_to_watch
1844
- pub fn block_connected < B : Deref , F : Deref , L : Deref > ( & mut self , header : & BlockHeader , txn_matched : & [ ( usize , & Transaction ) ] , height : u32 , broadcaster : B , fee_estimator : F , logger : L ) -> Vec < ( Txid , Vec < TxOut > ) >
1868
+ pub fn block_connected < B : Deref , F : Deref , L : Deref > ( & mut self , header : & BlockHeader , txdata : & [ ( usize , & Transaction ) ] , height : u32 , broadcaster : B , fee_estimator : F , logger : L ) -> Vec < ( Txid , Vec < TxOut > ) >
1845
1869
where B :: Target : BroadcasterInterface ,
1846
1870
F :: Target : FeeEstimator ,
1847
1871
L :: Target : Logger ,
1848
1872
{
1873
+ let txn_matched = & txdata. iter ( ) . filter ( |& & ( _, tx) | self . does_tx_match ( tx) ) . map ( |e| * e) . collect :: < Vec < _ > > ( ) ;
1849
1874
for & ( _, tx) in txn_matched {
1850
1875
let mut output_val = 0 ;
1851
1876
for out in tx. output . iter ( ) {
0 commit comments