validators

package
v0.0.0-...-76a5e14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidValidatorType   = errors.New("invalid validator type")
	ErrMismatchValidatorType  = errors.New("mismatch between validator and validators")
	ErrMismatchValidatorsType = errors.New("mismatch between two validators")
	ErrValidatorAlreadyExists = errors.New("validator already exists in validators")
	ErrValidatorNotFound      = errors.New("validator not found in validators")
	ErrInvalidValidators      = errors.New("container is not ")
)
View Source
var (
	ErrInvalidBLSValidatorFormat = errors.New("invalid validator format, expected [Validator Address]:[BLS Public Key]")
)
View Source
var (
	ErrInvalidTypeAssert = errors.New("invalid type assert")
)

Functions

This section is empty.

Types

type BLSValidator

type BLSValidator struct {
	Address      types.Address
	BLSPublicKey BLSValidatorPublicKey
}

BLSValidator is a validator using BLS signing algorithm

func NewBLSValidator

func NewBLSValidator(addr types.Address, blsPubkey []byte) *BLSValidator

NewBLSValidator is a constructor of BLSValidator

func ParseBLSValidator

func ParseBLSValidator(validator string) (*BLSValidator, error)

ParseBLSValidator parses BLSValidator represented in string

func (*BLSValidator) Addr

func (v *BLSValidator) Addr() types.Address

Addr returns the validator address

func (*BLSValidator) Bytes

func (v *BLSValidator) Bytes() []byte

Bytes returns bytes of BLSValidator in RLP encode

func (*BLSValidator) Copy

func (v *BLSValidator) Copy() Validator

Copy returns copy of BLS Validator

func (*BLSValidator) Equal

func (v *BLSValidator) Equal(vr Validator) bool

Equal checks the given validator matches with its data

func (*BLSValidator) MarshalRLPWith

func (v *BLSValidator) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith is a RLP Marshaller

func (*BLSValidator) SetFromBytes

func (v *BLSValidator) SetFromBytes(input []byte) error

SetFromBytes parses given bytes in RLP encode and map to its fields

func (*BLSValidator) String

func (v *BLSValidator) String() string

String returns string representation of BLSValidator Format => [Address]:[BLSPublicKey]

func (*BLSValidator) Type

func (v *BLSValidator) Type() ValidatorType

Type returns the ValidatorType of BLSValidator

func (*BLSValidator) UnmarshalRLPFrom

func (v *BLSValidator) UnmarshalRLPFrom(p *fastrlp.Parser, val *fastrlp.Value) error

UnmarshalRLPFrom is a RLP Unmarshaller

type BLSValidatorPublicKey

type BLSValidatorPublicKey []byte

func (BLSValidatorPublicKey) MarshalText

func (k BLSValidatorPublicKey) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (BLSValidatorPublicKey) String

func (k BLSValidatorPublicKey) String() string

String returns a public key in hex

func (*BLSValidatorPublicKey) UnmarshalText

func (k *BLSValidatorPublicKey) UnmarshalText(input []byte) error

UnmarshalText parses an BLS Public Key in hex

type ECDSAValidator

type ECDSAValidator struct {
	Address types.Address
}

BLSValidator is a validator using ECDSA signing algorithm

func NewECDSAValidator

func NewECDSAValidator(addr types.Address) *ECDSAValidator

NewECDSAValidator is a constructor of ECDSAValidator

func ParseECDSAValidator

func ParseECDSAValidator(validator string) *ECDSAValidator

ParseBLSValidator parses ECDSAValidator represented in string

func (*ECDSAValidator) Addr

func (v *ECDSAValidator) Addr() types.Address

Addr returns the validator address

func (*ECDSAValidator) Bytes

func (v *ECDSAValidator) Bytes() []byte

Bytes returns bytes of ECDSAValidator

func (*ECDSAValidator) Copy

func (v *ECDSAValidator) Copy() Validator

Copy returns copy of ECDSAValidator

func (*ECDSAValidator) Equal

func (v *ECDSAValidator) Equal(vr Validator) bool

Equal checks the given validator matches with its data

func (*ECDSAValidator) MarshalRLPWith

func (v *ECDSAValidator) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith is a RLP Marshaller

func (*ECDSAValidator) SetFromBytes

func (v *ECDSAValidator) SetFromBytes(input []byte) error

SetFromBytes parses given bytes

func (*ECDSAValidator) String

func (v *ECDSAValidator) String() string

String returns string representation of ECDSAValidator

func (*ECDSAValidator) Type

func (v *ECDSAValidator) Type() ValidatorType

Type returns the ValidatorType of ECDSAValidator

func (*ECDSAValidator) UnmarshalRLPFrom

func (v *ECDSAValidator) UnmarshalRLPFrom(p *fastrlp.Parser, val *fastrlp.Value) error

UnmarshalRLPFrom is a RLP Unmarshaller

type Set

type Set struct {
	ValidatorType ValidatorType
	Validators    []Validator
}

func (*Set) Add

func (s *Set) Add(val Validator) error

Add adds a validator into the collection

func (*Set) At

func (s *Set) At(index uint64) Validator

At returns a validator at specified index in the collection

func (*Set) Copy

func (s *Set) Copy() Validators

Copy returns a copy of BLSValidators

func (*Set) Del

func (s *Set) Del(val Validator) error

Del removes a validator from the collection

func (*Set) Equal

func (s *Set) Equal(ss Validators) bool

Equal checks the given validators matches with its data

func (*Set) Includes

func (s *Set) Includes(addr types.Address) bool

Includes return the bool indicating whether the validator whose address matches with the given address exists or not

func (*Set) Index

func (s *Set) Index(addr types.Address) int64

Index returns the index of the validator whose address matches with the given address

func (*Set) Len

func (s *Set) Len() int

Len returns the size of its collection

func (*Set) MarshalJSON

func (s *Set) MarshalJSON() ([]byte, error)

Marshal implements json marshal function

func (*Set) MarshalRLPWith

func (s *Set) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith is a RLP Marshaller

func (*Set) Merge

func (s *Set) Merge(ss Validators) error

Merge introduces the given collection into its collection

func (*Set) Type

func (s *Set) Type() ValidatorType

Type returns the type of validator

func (*Set) UnmarshalJSON

func (s *Set) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json unmarshal function

func (*Set) UnmarshalRLPFrom

func (s *Set) UnmarshalRLPFrom(p *fastrlp.Parser, val *fastrlp.Value) error

UnmarshalRLPFrom is a RLP Unmarshaller

type Validator

type Validator interface {
	// Return the validator type
	Type() ValidatorType
	// Return the string representation
	String() string
	// Return the address of the validator
	Addr() types.Address
	// Return of copy of the validator
	Copy() Validator
	// Check the same validator or not
	Equal(Validator) bool
	// RLP Marshaller to encode to bytes
	MarshalRLPWith(*fastrlp.Arena) *fastrlp.Value
	// RLP Unmarshaller to encode from bytes
	UnmarshalRLPFrom(*fastrlp.Parser, *fastrlp.Value) error
	// Return bytes in RLP encode
	Bytes() []byte
	// Decode bytes in RLP encode and map to the fields
	SetFromBytes([]byte) error
}

Validator defines the interface of the methods a validator implements

func NewValidatorFromType

func NewValidatorFromType(t ValidatorType) (Validator, error)

NewValidatorFromType instantiates a validator by specified type

func ParseValidator

func ParseValidator(validatorType ValidatorType, validator string) (Validator, error)

ParseValidator parses a validator represented in string

type ValidatorType

type ValidatorType string
const (
	ECDSAValidatorType ValidatorType = "ecdsa"
	BLSValidatorType   ValidatorType = "bls"
)

func ParseValidatorType

func ParseValidatorType(validatorType string) (ValidatorType, error)

ParseValidatorType converts a validatorType string representation to a ValidatorType

type Validators

type Validators interface {
	// Return the type of the validators
	Type() ValidatorType
	// Return the size of collection
	Len() int
	// Check equality of each element
	Equal(Validators) bool
	// Return of the whole collection
	Copy() Validators
	// Get validator at specified height
	At(uint64) Validator
	// Find the index of the validator that has specified address
	Index(types.Address) int64
	// Check the validator that has specified address exists in the collection
	Includes(types.Address) bool
	// Add a validator into collection
	Add(Validator) error
	// Remove a validator from collection
	Del(Validator) error
	// Merge 2 collections into one collection
	Merge(Validators) error
	// RLP Marshaller to encode to bytes
	MarshalRLPWith(*fastrlp.Arena) *fastrlp.Value
	// Decode bytes in RLP encode and map to the elements
	UnmarshalRLPFrom(*fastrlp.Parser, *fastrlp.Value) error
}

Validators defines the interface of the methods validator collection implements

func NewBLSValidatorSet

func NewBLSValidatorSet(blsValidators ...*BLSValidator) Validators

NewBLSValidatorSet creates Validator Set for BLSValidator with initialized validators

func NewECDSAValidatorSet

func NewECDSAValidatorSet(ecdsaValidators ...*ECDSAValidator) Validators

NewECDSAValidatorSet creates Validator Set for ECDSAValidator with initialized validators

func NewValidatorSetFromType

func NewValidatorSetFromType(t ValidatorType) Validators

NewValidatorSetFromType instantiates a validators by specified type

func ParseValidators

func ParseValidators(validatorType ValidatorType, rawValidators []string) (Validators, error)

ParseValidator parses an array of validator represented in string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL