Skip to content

Commit 35573bb

Browse files
authored
Merge pull request #1034 from TheBlueMatt/2021-07-maturing-claims
Expose in-flight claim balances
2 parents bb9df69 + cae2123 commit 35573bb

File tree

6 files changed

+980
-93
lines changed

6 files changed

+980
-93
lines changed

lightning/src/chain/chainmonitor.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ use chain;
3030
use chain::{Filter, WatchedOutput};
3131
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
3232
use chain::channelmonitor;
33-
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent, Persist, TransactionOutputs};
33+
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, Balance, MonitorEvent, Persist, TransactionOutputs};
3434
use chain::transaction::{OutPoint, TransactionData};
3535
use chain::keysinterface::Sign;
3636
use util::logger::Logger;
3737
use util::events;
3838
use util::events::EventHandler;
39+
use ln::channelmanager::ChannelDetails;
3940

4041
use prelude::*;
4142
use sync::RwLock;
@@ -140,6 +141,31 @@ where C::Target: chain::Filter,
140141
}
141142
}
142143

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+
143169
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
144170
pub fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
145171
use util::events::EventsProvider;

0 commit comments

Comments
 (0)