github.com/decred/dcrlnd@v0.7.6/feature/required.go (about)

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