From c6cc30d9d7e3e0d2b8e9066bea6eeb68c638e347 Mon Sep 17 00:00:00 2001 From: Yuntai Kyong Date: Mon, 1 Oct 2018 18:11:33 +0900 Subject: [PATCH] Add a ChannelValueStat getter to simplify tests --- src/ln/channel.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 2dc7750e4..d1cfd8b89 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -44,6 +44,17 @@ pub struct ChannelKeys { pub commitment_seed: [u8; 32], } +#[cfg(test)] +pub struct ChannelValueStat { + pub value_to_self_msat: u64, + pub channel_value_msat: u64, + pub channel_reserve_msat: u64, + pub pending_outbound_htlcs_amount_msat: u64, + pub pending_inbound_htlcs_amount_msat: u64, + pub holding_cell_outbound_amount_msat: u64, + pub their_max_htlc_value_in_flight_msat: u64, // outgoing +} + impl ChannelKeys { pub fn new_from_seed(seed: &[u8; 32]) -> Result { let mut prk = [0; 32]; @@ -2352,6 +2363,30 @@ impl Channel { &self.local_keys } + #[cfg(test)] + pub fn get_value_stat(&self) -> ChannelValueStat { + ChannelValueStat { + value_to_self_msat: self.value_to_self_msat, + channel_value_msat: self.channel_value_satoshis * 1000, + channel_reserve_msat: self.their_channel_reserve_satoshis * 1000, + pending_outbound_htlcs_amount_msat: self.pending_outbound_htlcs.iter().map(|ref h| h.amount_msat).sum::(), + pending_inbound_htlcs_amount_msat: self.pending_inbound_htlcs.iter().map(|ref h| h.amount_msat).sum::(), + holding_cell_outbound_amount_msat: { + let mut res = 0; + for h in self.holding_cell_htlc_updates.iter() { + match &h { + &HTLCUpdateAwaitingACK::AddHTLC{amount_msat, .. } => { + res += amount_msat; + } + _ => {} + } + } + res + }, + their_max_htlc_value_in_flight_msat: self.their_max_htlc_value_in_flight_msat, + } + } + /// Allowed in any state (including after shutdown) pub fn get_channel_update_count(&self) -> u32 { self.channel_update_count -- 2.39.5