watchtower/wtpolicy: add IsAnchorChannel helper

This commit is contained in:
Conner Fromknecht 2020-11-25 15:04:23 -08:00
parent dd325f04d2
commit 74416c63f8
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 24 additions and 0 deletions

@ -120,6 +120,11 @@ func (p Policy) String() string {
p.SweepFeeRate) 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 // Validate ensures that the policy satisfies some minimal correctness
// constraints. // constraints.
func (p Policy) Validate() error { func (p Policy) Validate() error {

@ -5,6 +5,7 @@ import (
"github.com/lightningnetwork/lnd/watchtower/blob" "github.com/lightningnetwork/lnd/watchtower/blob"
"github.com/lightningnetwork/lnd/watchtower/wtpolicy" "github.com/lightningnetwork/lnd/watchtower/wtpolicy"
"github.com/stretchr/testify/require"
) )
var validationTests = []struct { 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())
}