@@ -30,12 +30,13 @@ use chain;
30
30
use chain:: { Filter , WatchedOutput } ;
31
31
use chain:: chaininterface:: { BroadcasterInterface , FeeEstimator } ;
32
32
use chain:: channelmonitor;
33
- use chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , ChannelMonitorUpdateErr , MonitorEvent , Persist , TransactionOutputs } ;
33
+ use chain:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdate , ChannelMonitorUpdateErr , Balance , MonitorEvent , Persist , TransactionOutputs } ;
34
34
use chain:: transaction:: { OutPoint , TransactionData } ;
35
35
use chain:: keysinterface:: Sign ;
36
36
use util:: logger:: Logger ;
37
37
use util:: events;
38
38
use util:: events:: EventHandler ;
39
+ use ln:: channelmanager:: ChannelDetails ;
39
40
40
41
use prelude:: * ;
41
42
use sync:: RwLock ;
@@ -140,6 +141,31 @@ where C::Target: chain::Filter,
140
141
}
141
142
}
142
143
144
+ /// Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
145
+ /// claims which are awaiting confirmation.
146
+ ///
147
+ /// Includes the balances from each [`ChannelMonitor`] *except* those included in
148
+ /// `ignored_channels`, allowing you to filter out balances from channels which are still open
149
+ /// (and whose balance should likely be pulled from the [`ChannelDetails`]).
150
+ ///
151
+ /// See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
152
+ /// inclusion in the return value.
153
+ pub fn get_claimable_balances ( & self , ignored_channels : & [ ChannelDetails ] ) -> Vec < Balance > {
154
+ let mut ret = Vec :: new ( ) ;
155
+ let monitors = self . monitors . read ( ) . unwrap ( ) ;
156
+ for ( _, monitor) in monitors. iter ( ) . filter ( |( funding_outpoint, _) | {
157
+ for chan in ignored_channels {
158
+ if chan. funding_txo . as_ref ( ) == Some ( funding_outpoint) {
159
+ return false ;
160
+ }
161
+ }
162
+ true
163
+ } ) {
164
+ ret. append ( & mut monitor. get_claimable_balances ( ) ) ;
165
+ }
166
+ ret
167
+ }
168
+
143
169
#[ cfg( any( test, feature = "fuzztarget" , feature = "_test_utils" ) ) ]
144
170
pub fn get_and_clear_pending_events ( & self ) -> Vec < events:: Event > {
145
171
use util:: events:: EventsProvider ;
0 commit comments