Skip to content

Commit

Permalink
Merge pull request #1034 from TheBlueMatt/2021-07-maturing-claims
Browse files Browse the repository at this point in the history
Expose in-flight claim balances
  • Loading branch information
TheBlueMatt committed Sep 15, 2021
2 parents bb9df69 + cae2123 commit 35573bb
Show file tree
Hide file tree
Showing 6 changed files with 980 additions and 93 deletions.
28 changes: 27 additions & 1 deletion lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ use chain;
use chain::{Filter, WatchedOutput};
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
use chain::channelmonitor;
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent, Persist, TransactionOutputs};
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, Balance, MonitorEvent, Persist, TransactionOutputs};
use chain::transaction::{OutPoint, TransactionData};
use chain::keysinterface::Sign;
use util::logger::Logger;
use util::events;
use util::events::EventHandler;
use ln::channelmanager::ChannelDetails;

use prelude::*;
use sync::RwLock;
Expand Down Expand Up @@ -140,6 +141,31 @@ where C::Target: chain::Filter,
}
}

/// Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
/// claims which are awaiting confirmation.
///
/// Includes the balances from each [`ChannelMonitor`] *except* those included in
/// `ignored_channels`, allowing you to filter out balances from channels which are still open
/// (and whose balance should likely be pulled from the [`ChannelDetails`]).
///
/// See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
/// inclusion in the return value.
pub fn get_claimable_balances(&self, ignored_channels: &[ChannelDetails]) -> Vec<Balance> {
let mut ret = Vec::new();
let monitors = self.monitors.read().unwrap();
for (_, monitor) in monitors.iter().filter(|(funding_outpoint, _)| {
for chan in ignored_channels {
if chan.funding_txo.as_ref() == Some(funding_outpoint) {
return false;
}
}
true
}) {
ret.append(&mut monitor.get_claimable_balances());
}
ret
}

#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))]
pub fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
use util::events::EventsProvider;
Expand Down
Loading

0 comments on commit 35573bb

Please sign in to comment.