mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 14:12:27 +02:00
watchtower: introduce CommitmentType
In this commit a new enum, CommitmentType, is introduced and initially there are 3 CommitmentTypes: Legacy, LegacyTweakless and Anchor. Then, various methods are added to `CommitmentType`. This allows us to remove a bunch of "if-else" chains from the `wtclient` and `lookout` code. This will also make things easier to extend when a new commitment type (like Taproot) is added.
This commit is contained in:
@ -3,6 +3,8 @@ package blob
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
)
|
||||
|
||||
// Flag represents a specify option that can be present in a Type.
|
||||
@ -81,6 +83,27 @@ func (t Type) Identifier() (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// CommitmentType returns the appropriate CommitmentType for the given blob Type
|
||||
// and channel type.
|
||||
func (t Type) CommitmentType(chanType *channeldb.ChannelType) (CommitmentType,
|
||||
error) {
|
||||
|
||||
switch {
|
||||
case t.Has(FlagAnchorChannel):
|
||||
return AnchorCommitment, nil
|
||||
|
||||
case t.Has(FlagCommitOutputs):
|
||||
if chanType != nil && chanType.IsTweakless() {
|
||||
return LegacyTweaklessCommitment, nil
|
||||
}
|
||||
|
||||
return LegacyCommitment, nil
|
||||
|
||||
default:
|
||||
return 0, ErrUnknownBlobType
|
||||
}
|
||||
}
|
||||
|
||||
// Has returns true if the Type has the passed flag enabled.
|
||||
func (t Type) Has(flag Flag) bool {
|
||||
return Flag(t)&flag == flag
|
||||
|
Reference in New Issue
Block a user