From: Elias Rohrer Date: Sat, 18 Jun 2022 12:40:36 +0000 (+0200) Subject: Provide simple interface to query est. liquidity X-Git-Tag: v0.0.109~11^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=717365fbf94ffd03ba9c5a0b0a6dbfb1e459be0d;p=rust-lightning Provide simple interface to query est. liquidity --- diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index bfcefc96f..f7fe58638 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -434,6 +434,23 @@ impl>, L: Deref, T: Time> ProbabilisticScorerU } } } + + /// Query the estimated minimum and maximum liquidity available for sending a payment over the + /// channel with `scid` towards the given `target` node. + pub fn estimated_channel_liquidity_range(&self, scid: u64, target: &NodeId) -> Option<(u64, u64)> { + let graph = self.network_graph.read_only(); + + if let Some(chan) = graph.channels().get(&scid) { + if let Some(liq) = self.channel_liquidities.get(&scid) { + if let Some((directed_info, source)) = chan.as_directed_to(target) { + let amt = directed_info.effective_capacity().as_msat(); + let dir_liq = liq.as_directed(source, target, amt, self.params.liquidity_offset_half_life); + return Some((dir_liq.min_liquidity_msat(), dir_liq.max_liquidity_msat())); + } + } + } + None + } } impl ProbabilisticScoringParameters {