From 0477c80732c8b6c66fa471ec1bbc8b561603d630 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 15 Sep 2020 12:43:20 -0400 Subject: [PATCH] watchtower/blob/type: add new FlagAnchorChannel --- watchtower/blob/type.go | 18 ++++++++++++++++++ watchtower/blob/type_test.go | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/watchtower/blob/type.go b/watchtower/blob/type.go index da83472c..f24b41f3 100644 --- a/watchtower/blob/type.go +++ b/watchtower/blob/type.go @@ -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. diff --git a/watchtower/blob/type_test.go b/watchtower/blob/type_test.go index 95b01c01..a88965b2 100644 --- a/watchtower/blob/type_test.go +++ b/watchtower/blob/type_test.go @@ -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]", }, }