watchtower/blob/type: add new FlagAnchorChannel

This commit is contained in:
Conner Fromknecht 2020-09-15 12:43:20 -04:00
parent ed67ce7678
commit 0477c80732
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 21 additions and 3 deletions

View File

@ -19,6 +19,11 @@ const (
// FlagCommitOutputs signals that the blob contains the information
// required to sweep commitment outputs.
FlagCommitOutputs Flag = 1 << 1
// FlagAnchorChannel signals that this blob is meant to spend an anchor
// channel, and therefore must expect a P2WSH-style to-remote output if
// one exists.
FlagAnchorChannel Flag = 1 << 2
)
// Type returns a Type consisting solely of this flag enabled.
@ -33,6 +38,8 @@ func (f Flag) String() string {
return "FlagReward"
case FlagCommitOutputs:
return "FlagCommitOutputs"
case FlagAnchorChannel:
return "FlagAnchorChannel"
default:
return "FlagUnknown"
}
@ -50,6 +57,11 @@ const (
// controlled by the user, and does not give the tower a reward.
TypeAltruistCommit = Type(FlagCommitOutputs)
// TypeAltruistAnchorCommit sweeps only commitment outputs from an
// anchor commitment to a sweep address controlled by the user, and does
// not give the tower a reward.
TypeAltruistAnchorCommit = Type(FlagCommitOutputs | FlagAnchorChannel)
// TypeRewardCommit sweeps only commitment outputs to a sweep address
// controlled by the user, and pays a negotiated reward to the tower.
TypeRewardCommit = Type(FlagCommitOutputs | FlagReward)
@ -70,10 +82,16 @@ func TypeFromFlags(flags ...Flag) Type {
return typ
}
// IsAnchorChannel returns true if the blob type is for an anchor channel.
func (t Type) IsAnchorChannel() bool {
return t.Has(FlagAnchorChannel)
}
// knownFlags maps the supported flags to their name.
var knownFlags = map[Flag]struct{}{
FlagReward: {},
FlagCommitOutputs: {},
FlagAnchorChannel: {},
}
// String returns a human readable description of a Type.

View File

@ -18,17 +18,17 @@ var typeStringTests = []typeStringTest{
{
name: "commit no-reward",
typ: blob.TypeAltruistCommit,
expStr: "[FlagCommitOutputs|No-FlagReward]",
expStr: "[No-FlagAnchorChannel|FlagCommitOutputs|No-FlagReward]",
},
{
name: "commit reward",
typ: blob.TypeRewardCommit,
expStr: "[FlagCommitOutputs|FlagReward]",
expStr: "[No-FlagAnchorChannel|FlagCommitOutputs|FlagReward]",
},
{
name: "unknown flag",
typ: unknownFlag.Type(),
expStr: "0000000000010000[No-FlagCommitOutputs|No-FlagReward]",
expStr: "0000000000010000[No-FlagAnchorChannel|No-FlagCommitOutputs|No-FlagReward]",
},
}