From a2b19afe597916d32486eb1eb6374551d02e7918 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Mon, 22 Jul 2024 14:44:47 -0700 Subject: [PATCH] channeldb+lnwallet: define Initiator for OpenChannel and LightningChannel This commit introduces a new API to return information on which party opened the channel using the new ChannelParty type. It does not change the underlying structure of how we store this information. --- channeldb/channel.go | 12 ++++++++++++ lnwallet/channel.go | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/channeldb/channel.go b/channeldb/channel.go index ad02084671a..ea48bcd5ba1 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -889,6 +889,18 @@ func (c *OpenChannel) String() string { ) } +// Initiator returns the ChannelParty that originally opened this channel. +func (c *OpenChannel) Initiator() lntypes.ChannelParty { + c.RLock() + defer c.RUnlock() + + if c.IsInitiator { + return lntypes.Local + } + + return lntypes.Remote +} + // ShortChanID returns the current ShortChannelID of this channel. func (c *OpenChannel) ShortChanID() lnwire.ShortChannelID { c.RLock() diff --git a/lnwallet/channel.go b/lnwallet/channel.go index afe10b950a0..21c5f897cf4 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -8709,6 +8709,14 @@ func (lc *LightningChannel) ChanType() channeldb.ChannelType { return lc.channelState.ChanType } +// Initiator returns the ChannelParty that originally opened this channel. +func (lc *LightningChannel) Initiator() lntypes.ChannelParty { + lc.RLock() + defer lc.RUnlock() + + return lc.channelState.Initiator() +} + // FundingTxOut returns the funding output of the channel. func (lc *LightningChannel) FundingTxOut() *wire.TxOut { lc.RLock()