mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 05:13:36 +01:00
lntypes: Add a ChannelParty type.
This commit introduces a ChannelParty type to LND. It is useful for consolidating all references to the duality between the local and remote nodes. This is currently handled by having named struct rows or named boolean parameters, named either "local" or "remote". This change alleviates the programmer from having to decide which node should be bound to `true` or `false`. In an upcoming commit we will change callsites to use this.
This commit is contained in:
parent
16d80f5b5b
commit
1a5b5c5f62
52
lntypes/channel_party.go
Normal file
52
lntypes/channel_party.go
Normal file
@ -0,0 +1,52 @@
|
||||
package lntypes
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ChannelParty is a type used to have an unambiguous description of which node
|
||||
// is being referred to. This eliminates the need to describe as "local" or
|
||||
// "remote" using bool.
|
||||
type ChannelParty uint8
|
||||
|
||||
const (
|
||||
// Local is a ChannelParty constructor that is used to refer to the
|
||||
// node that is running.
|
||||
Local ChannelParty = iota
|
||||
|
||||
// Remote is a ChannelParty constructor that is used to refer to the
|
||||
// node on the other end of the peer connection.
|
||||
Remote
|
||||
)
|
||||
|
||||
// String provides a string representation of ChannelParty (useful for logging).
|
||||
func (p ChannelParty) String() string {
|
||||
switch p {
|
||||
case Local:
|
||||
return "Local"
|
||||
case Remote:
|
||||
return "Remote"
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid ChannelParty value: %d", p))
|
||||
}
|
||||
}
|
||||
|
||||
// CounterParty inverts the role of the ChannelParty.
|
||||
func (p ChannelParty) CounterParty() ChannelParty {
|
||||
switch p {
|
||||
case Local:
|
||||
return Remote
|
||||
case Remote:
|
||||
return Local
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid ChannelParty value: %v", p))
|
||||
}
|
||||
}
|
||||
|
||||
// IsLocal returns true if the ChannelParty is Local.
|
||||
func (p ChannelParty) IsLocal() bool {
|
||||
return p == Local
|
||||
}
|
||||
|
||||
// IsRemote returns true if the ChannelParty is Remote.
|
||||
func (p ChannelParty) IsRemote() bool {
|
||||
return p == Remote
|
||||
}
|
Loading…
Reference in New Issue
Block a user