mirror of
https://github.com/lightninglabs/loop
synced 2024-11-04 06:00:21 +00:00
7b56804bbe
Previously labels with reserved prefixes were added to provide us with a way to identify automatically dispatched loops. This commit moves the validation of these labels to the rpc level so that it will only apply to user-initiated swaps.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package labels
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
// MaxLength is the maximum length we allow for labels.
|
|
MaxLength = 500
|
|
|
|
// Reserved is used as a prefix to separate labels that are created by
|
|
// loopd from those created by users.
|
|
Reserved = "[reserved]"
|
|
)
|
|
|
|
var (
|
|
// ErrLabelTooLong is returned when a label exceeds our length limit.
|
|
ErrLabelTooLong = errors.New("label exceeds maximum length")
|
|
|
|
// ErrReservedPrefix is returned when a label contains the prefix
|
|
// which is reserved for internally produced labels.
|
|
ErrReservedPrefix = errors.New("label contains reserved prefix")
|
|
)
|
|
|
|
// Validate checks that a label is of appropriate length and is not in our list
|
|
// of reserved labels.
|
|
func Validate(label string) error {
|
|
if len(label) > MaxLength {
|
|
return ErrLabelTooLong
|
|
}
|
|
|
|
// Check if our label begins with our reserved prefix. We don't mind if
|
|
// it has our reserved prefix in another case, we just need to be able
|
|
// to reserve a subset of labels with this prefix.
|
|
if strings.HasPrefix(label, Reserved) {
|
|
return ErrReservedPrefix
|
|
}
|
|
|
|
return nil
|
|
}
|