-
Notifications
You must be signed in to change notification settings - Fork 0
/
required.go
37 lines (31 loc) · 999 Bytes
/
required.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package feature
import (
"fmt"
"github.com/brronsuite/broln/lnwire"
)
// ErrUnknownRequired signals that a feature vector requires certain features
// that our node is unaware of or does not implement.
type ErrUnknownRequired struct {
unknown []lnwire.FeatureBit
}
// NewErrUnknownRequired initializes an ErrUnknownRequired with the unknown
// feature bits.
func NewErrUnknownRequired(unknown []lnwire.FeatureBit) ErrUnknownRequired {
return ErrUnknownRequired{
unknown: unknown,
}
}
// Error returns a human-readable description of the error.
func (e ErrUnknownRequired) Error() string {
return fmt.Sprintf("feature vector contains unknown required "+
"features: %v", e.unknown)
}
// ValidateRequired returns an error if the feature vector contains a non-zero
// number of unknown, required feature bits.
func ValidateRequired(fv *lnwire.FeatureVector) error {
unknown := fv.UnknownRequiredFeatures()
if len(unknown) > 0 {
return NewErrUnknownRequired(unknown)
}
return nil
}