Skip to content

Commit fdf3f65

Browse files
committed
Convert ChannelDetails::from_channel to ChannelDetails::from_channel_context
This rename and refactor is so that we can get channel details from a `ChannelContext` which is a common object to all channels.
1 parent 42fb157 commit fdf3f65

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,54 +1466,54 @@ impl ChannelDetails {
14661466
self.short_channel_id.or(self.outbound_scid_alias)
14671467
}
14681468

1469-
fn from_channel<Signer: WriteableEcdsaChannelSigner>(channel: &Channel<Signer>,
1469+
fn from_channel_context<Signer: WriteableEcdsaChannelSigner>(context: &ChannelContext<Signer>,
14701470
best_block_height: u32, latest_features: InitFeatures) -> Self {
14711471

1472-
let balance = channel.context.get_available_balances();
1472+
let balance = context.get_available_balances();
14731473
let (to_remote_reserve_satoshis, to_self_reserve_satoshis) =
1474-
channel.context.get_holder_counterparty_selected_channel_reserve_satoshis();
1474+
context.get_holder_counterparty_selected_channel_reserve_satoshis();
14751475
ChannelDetails {
1476-
channel_id: channel.context.channel_id(),
1476+
channel_id: context.channel_id(),
14771477
counterparty: ChannelCounterparty {
1478-
node_id: channel.context.get_counterparty_node_id(),
1478+
node_id: context.get_counterparty_node_id(),
14791479
features: latest_features,
14801480
unspendable_punishment_reserve: to_remote_reserve_satoshis,
1481-
forwarding_info: channel.context.counterparty_forwarding_info(),
1481+
forwarding_info: context.counterparty_forwarding_info(),
14821482
// Ensures that we have actually received the `htlc_minimum_msat` value
14831483
// from the counterparty through the `OpenChannel` or `AcceptChannel`
14841484
// message (as they are always the first message from the counterparty).
14851485
// Else `Channel::get_counterparty_htlc_minimum_msat` could return the
14861486
// default `0` value set by `Channel::new_outbound`.
1487-
outbound_htlc_minimum_msat: if channel.context.have_received_message() {
1488-
Some(channel.context.get_counterparty_htlc_minimum_msat()) } else { None },
1489-
outbound_htlc_maximum_msat: channel.context.get_counterparty_htlc_maximum_msat(),
1487+
outbound_htlc_minimum_msat: if context.have_received_message() {
1488+
Some(context.get_counterparty_htlc_minimum_msat()) } else { None },
1489+
outbound_htlc_maximum_msat: context.get_counterparty_htlc_maximum_msat(),
14901490
},
1491-
funding_txo: channel.context.get_funding_txo(),
1491+
funding_txo: context.get_funding_txo(),
14921492
// Note that accept_channel (or open_channel) is always the first message, so
14931493
// `have_received_message` indicates that type negotiation has completed.
1494-
channel_type: if channel.context.have_received_message() { Some(channel.context.get_channel_type().clone()) } else { None },
1495-
short_channel_id: channel.context.get_short_channel_id(),
1496-
outbound_scid_alias: if channel.context.is_usable() { Some(channel.context.outbound_scid_alias()) } else { None },
1497-
inbound_scid_alias: channel.context.latest_inbound_scid_alias(),
1498-
channel_value_satoshis: channel.context.get_value_satoshis(),
1499-
feerate_sat_per_1000_weight: Some(channel.context.get_feerate_sat_per_1000_weight()),
1494+
channel_type: if context.have_received_message() { Some(context.get_channel_type().clone()) } else { None },
1495+
short_channel_id: context.get_short_channel_id(),
1496+
outbound_scid_alias: if context.is_usable() { Some(context.outbound_scid_alias()) } else { None },
1497+
inbound_scid_alias: context.latest_inbound_scid_alias(),
1498+
channel_value_satoshis: context.get_value_satoshis(),
1499+
feerate_sat_per_1000_weight: Some(context.get_feerate_sat_per_1000_weight()),
15001500
unspendable_punishment_reserve: to_self_reserve_satoshis,
15011501
balance_msat: balance.balance_msat,
15021502
inbound_capacity_msat: balance.inbound_capacity_msat,
15031503
outbound_capacity_msat: balance.outbound_capacity_msat,
15041504
next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
15051505
next_outbound_htlc_minimum_msat: balance.next_outbound_htlc_minimum_msat,
1506-
user_channel_id: channel.context.get_user_id(),
1507-
confirmations_required: channel.context.minimum_depth(),
1508-
confirmations: Some(channel.context.get_funding_tx_confirmations(best_block_height)),
1509-
force_close_spend_delay: channel.context.get_counterparty_selected_contest_delay(),
1510-
is_outbound: channel.context.is_outbound(),
1511-
is_channel_ready: channel.context.is_usable(),
1512-
is_usable: channel.context.is_live(),
1513-
is_public: channel.context.should_announce(),
1514-
inbound_htlc_minimum_msat: Some(channel.context.get_holder_htlc_minimum_msat()),
1515-
inbound_htlc_maximum_msat: channel.context.get_holder_htlc_maximum_msat(),
1516-
config: Some(channel.context.config()),
1506+
user_channel_id: context.get_user_id(),
1507+
confirmations_required: context.minimum_depth(),
1508+
confirmations: Some(context.get_funding_tx_confirmations(best_block_height)),
1509+
force_close_spend_delay: context.get_counterparty_selected_contest_delay(),
1510+
is_outbound: context.is_outbound(),
1511+
is_channel_ready: context.is_usable(),
1512+
is_usable: context.is_live(),
1513+
is_public: context.should_announce(),
1514+
inbound_htlc_minimum_msat: Some(context.get_holder_htlc_minimum_msat()),
1515+
inbound_htlc_maximum_msat: context.get_holder_htlc_maximum_msat(),
1516+
config: Some(context.config()),
15171517
}
15181518
}
15191519
}
@@ -2091,7 +2091,7 @@ where
20912091
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
20922092
let peer_state = &mut *peer_state_lock;
20932093
for (_channel_id, channel) in peer_state.channel_by_id.iter().filter(f) {
2094-
let details = ChannelDetails::from_channel(channel, best_block_height,
2094+
let details = ChannelDetails::from_channel_context(&channel.context, best_block_height,
20952095
peer_state.latest_features.clone());
20962096
res.push(details);
20972097
}
@@ -2131,7 +2131,7 @@ where
21312131
return peer_state.channel_by_id
21322132
.iter()
21332133
.map(|(_, channel)|
2134-
ChannelDetails::from_channel(channel, best_block_height, features.clone()))
2134+
ChannelDetails::from_channel_context(&channel.context, best_block_height, features.clone()))
21352135
.collect();
21362136
}
21372137
vec![]

0 commit comments

Comments
 (0)