Skip to content

Commit 31b72d1

Browse files
committed
Store ChannelWrappers in channel_by_id map
1 parent 0c31021 commit 31b72d1

File tree

4 files changed

+452
-352
lines changed

4 files changed

+452
-352
lines changed

lightning/src/ln/channel.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,45 @@ impl<'a, SP: Deref> ChannelPhase<SP> where
11601160
}
11611161
}
11621162

1163+
/// A top-level channel struct, containing a channel phase
1164+
pub(super) struct ChannelWrapper<SP: Deref> where SP::Target: SignerProvider {
1165+
phase: ChannelPhase<SP>,
1166+
}
1167+
1168+
impl<'a, SP: Deref> ChannelWrapper<SP> where SP::Target: SignerProvider {
1169+
pub fn new(phase: ChannelPhase<SP>) -> Self {
1170+
Self { phase }
1171+
}
1172+
1173+
pub fn phase(&self) -> &ChannelPhase<SP> {
1174+
&self.phase
1175+
}
1176+
1177+
pub fn phase_mut(&mut self) -> &mut ChannelPhase<SP> {
1178+
&mut self.phase
1179+
}
1180+
1181+
pub fn phase_take(self) -> ChannelPhase<SP> {
1182+
self.phase
1183+
}
1184+
1185+
pub fn get_funded_channel(&self) -> Option<&Channel<SP>> {
1186+
if let ChannelPhase::Funded(chan) = &self.phase {
1187+
Some(chan)
1188+
} else {
1189+
None
1190+
}
1191+
}
1192+
1193+
pub fn context(&'a self) -> &'a ChannelContext<SP> {
1194+
self.phase.context()
1195+
}
1196+
1197+
pub fn context_mut(&'a mut self) -> &'a mut ChannelContext<SP> {
1198+
self.phase.context_mut()
1199+
}
1200+
}
1201+
11631202
/// Contains all state common to unfunded inbound/outbound channels.
11641203
pub(super) struct UnfundedChannelContext {
11651204
/// A counter tracking how many ticks have elapsed since this unfunded channel was

0 commit comments

Comments
 (0)