From 74416c63f829c2b53d078ff6c44d8e0be217360c Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 25 Nov 2020 15:04:23 -0800 Subject: [PATCH] watchtower/wtpolicy: add IsAnchorChannel helper --- watchtower/wtpolicy/policy.go | 5 +++++ watchtower/wtpolicy/policy_test.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/watchtower/wtpolicy/policy.go b/watchtower/wtpolicy/policy.go index 9c7f5e64..40eb001b 100644 --- a/watchtower/wtpolicy/policy.go +++ b/watchtower/wtpolicy/policy.go @@ -120,6 +120,11 @@ func (p Policy) String() string { p.SweepFeeRate) } +// IsAnchorChannel returns true if the session policy requires anchor channels. +func (p Policy) IsAnchorChannel() bool { + return p.TxPolicy.BlobType.IsAnchorChannel() +} + // Validate ensures that the policy satisfies some minimal correctness // constraints. func (p Policy) Validate() error { diff --git a/watchtower/wtpolicy/policy_test.go b/watchtower/wtpolicy/policy_test.go index 4182a0de..b73c4845 100644 --- a/watchtower/wtpolicy/policy_test.go +++ b/watchtower/wtpolicy/policy_test.go @@ -5,6 +5,7 @@ import ( "github.com/lightningnetwork/lnd/watchtower/blob" "github.com/lightningnetwork/lnd/watchtower/wtpolicy" + "github.com/stretchr/testify/require" ) var validationTests = []struct { @@ -91,3 +92,21 @@ func TestPolicyValidate(t *testing.T) { }) } } + +// TestPolicyIsAnchorChannel asserts that the IsAnchorChannel helper properly +// reflects the anchor bit of the policy's blob type. +func TestPolicyIsAnchorChannel(t *testing.T) { + policyNoAnchor := wtpolicy.Policy{ + TxPolicy: wtpolicy.TxPolicy{ + BlobType: blob.TypeAltruistCommit, + }, + } + require.Equal(t, false, policyNoAnchor.IsAnchorChannel()) + + policyAnchor := wtpolicy.Policy{ + TxPolicy: wtpolicy.TxPolicy{ + BlobType: blob.TypeAltruistAnchorCommit, + }, + } + require.Equal(t, true, policyAnchor.IsAnchorChannel()) +}