types

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MaxNameLength            = 70
	MaxIdentityLength        = 3000
	MaxWebsiteLength         = 140
	MaxSecurityContactLength = 140
	MaxDetailsLength         = 280
	BlsVerificationStr       = "harmony-one"
)

Define validator staking related const

View Source
const (
	// LockPeriodInEpoch is the number of epochs a undelegated token needs to be before it's released to the delegator's balance
	LockPeriodInEpoch = 7
)

Variables

View Source
var (
	// ErrInvalidSig is a bad signature
	ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
View Source
var (

	// ErrInvalidStakingKind given when caller gives bad staking message kind
	ErrInvalidStakingKind = errors.New("bad staking kind")
)

Functions

func MarshalValidator added in v1.3.0

func MarshalValidator(validator Validator) ([]byte, error)

MarshalValidator marshals the validator object

func RLPDecodeStakeMsg added in v1.3.0

func RLPDecodeStakeMsg(payload []byte, d Directive) (interface{}, error)

RLPDecodeStakeMsg ..

func Sender

func Sender(signer Signer, tx *StakingTransaction) (common.Address, error)

Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.

func UpdateValidatorFromEditMsg added in v1.3.0

func UpdateValidatorFromEditMsg(validator *Validator, edit *EditValidator) error

UpdateValidatorFromEditMsg updates validator from EditValidator message TODO check the validity of the fields of edit message

Types

type CollectRewards added in v1.3.0

type CollectRewards struct {
	DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"`
}

CollectRewards - type for collecting token rewards

func (CollectRewards) Copy added in v1.3.0

func (v CollectRewards) Copy() StakeMsg

Copy deep copy of the interface

func (CollectRewards) Type added in v1.3.0

func (v CollectRewards) Type() Directive

Type of CollectRewards

type Commission

type Commission struct {
	CommissionRates
	UpdateHeight *big.Int
}

Commission defines a commission parameters for a given validator.

func (Commission) MarshalJSON added in v1.3.0

func (c Commission) MarshalJSON() ([]byte, error)

MarshalJSON ..

func (Commission) String added in v1.3.0

func (c Commission) String() string

String returns a human readable string representation of a validator.

type CommissionRates

type CommissionRates struct {
	Rate          numeric.Dec // the commission rate charged to delegators, as a fraction
	MaxRate       numeric.Dec // maximum commission rate which validator can ever charge, as a fraction
	MaxChangeRate numeric.Dec // maximum increase of the validator commission every epoch, as a fraction
}

CommissionRates defines the initial commission rates to be used for creating a validator.

func (CommissionRates) MarshalJSON added in v1.3.0

func (cr CommissionRates) MarshalJSON() ([]byte, error)

MarshalJSON ..

type CreateValidator added in v1.3.0

type CreateValidator struct {
	ValidatorAddress   common.Address `json:"validator_address" yaml:"validator_address"`
	Description        *Description   `json:"description" yaml:"description"`
	CommissionRates    `json:"commission" yaml:"commission"`
	MinSelfDelegation  *big.Int             `json:"min_self_delegation" yaml:"min_self_delegation"`
	MaxTotalDelegation *big.Int             `json:"max_total_delegation" yaml:"max_total_delegation"`
	SlotPubKeys        []shard.BlsPublicKey `json:"slot_pub_keys" yaml:"slot_pub_keys"`
	SlotKeySigs        []shard.BlsSignature `json:"slot_key_sigs" yaml:"slot_key_sigs"`
	Amount             *big.Int             `json:"amount" yaml:"amount"`
}

CreateValidator - type for creating a new validator

func (CreateValidator) Copy added in v1.3.0

func (v CreateValidator) Copy() StakeMsg

Copy deep copy of the interface

func (CreateValidator) Type added in v1.3.0

func (v CreateValidator) Type() Directive

Type of CreateValidator

type Delegate

type Delegate struct {
	DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"`
	ValidatorAddress common.Address `json:"validator_address" yaml:"validator_address"`
	Amount           *big.Int       `json:"amount" yaml:"amount" rlp:"nil"`
}

Delegate - type for delegating to a validator

func (Delegate) Copy added in v1.3.0

func (v Delegate) Copy() StakeMsg

Copy deep copy of the interface

func (Delegate) Type added in v1.3.0

func (v Delegate) Type() Directive

Type of Delegate

type Delegation

type Delegation struct {
	DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"`
	Amount           *big.Int       `json:"amount" yaml:"amount"`
	Reward           *big.Int       `json:"reward" yaml:"reward"`
	Undelegations    []Undelegation `json:"undelegations" yaml:"undelegations"`
}

Delegation represents the bond with tokens held by an account. It is owned by one delegator, and is associated with the voting power of one validator.

func NewDelegation

func NewDelegation(delegatorAddr common.Address,
	amount *big.Int) Delegation

NewDelegation creates a new delegation object

func (*Delegation) DeleteEntry added in v1.3.0

func (d *Delegation) DeleteEntry(epoch *big.Int)

DeleteEntry - delete an entry from the undelegation Opimize it

func (*Delegation) RemoveUnlockedUndelegations added in v1.3.0

func (d *Delegation) RemoveUnlockedUndelegations(curEpoch, lastEpochInCommittee *big.Int) *big.Int

RemoveUnlockedUndelegations removes all fully unlocked undelegations and returns the total sum

func (*Delegation) TotalInUndelegation added in v1.3.0

func (d *Delegation) TotalInUndelegation() *big.Int

TotalInUndelegation - return the total amount of token in undelegation (locking period)

func (*Delegation) Undelegate added in v1.3.0

func (d *Delegation) Undelegate(epoch *big.Int, amt *big.Int) error

Undelegate - append entry to the undelegation

type DelegationIndex added in v1.3.0

type DelegationIndex struct {
	ValidatorAddress common.Address
	Index            uint64
}

DelegationIndex stored the index of a delegation in the validator's delegation list

type Description

type Description struct {
	Name            string `json:"name" yaml:"name"`                         // name
	Identity        string `json:"identity" yaml:"identity"`                 // optional identity signature (ex. UPort or Keybase)
	Website         string `json:"website" yaml:"website"`                   // optional website link
	SecurityContact string `json:"security_contact" yaml:"security_contact"` // optional security contact info
	Details         string `json:"details" yaml:"details"`                   // optional details
}

Description - some possible IRL connections

func NewDescription added in v1.9.0

func NewDescription(name, identity, website, securityContact, details string) Description

NewDescription returns a new Description with the provided values.

func UpdateDescription added in v1.3.0

func UpdateDescription(d2 *Description) (Description, error)

UpdateDescription updates the fields of a given description. An error is returned if the resulting description contains an invalid length.

func (Description) EnsureLength added in v1.3.0

func (d Description) EnsureLength() (Description, error)

EnsureLength ensures the length of a validator's description.

type Directive

type Directive byte

Directive says what kind of payload follows

const (
	// DirectiveCreateValidator ...
	DirectiveCreateValidator Directive = iota
	// DirectiveEditValidator ...
	DirectiveEditValidator
	// DirectiveDelegate ...
	DirectiveDelegate
	// DirectiveUndelegate ...
	DirectiveUndelegate
	// DirectiveCollectRewards ...
	DirectiveCollectRewards
)

func (Directive) String

func (d Directive) String() string

type EIP155Signer

type EIP155Signer struct {
	// contains filtered or unexported fields
}

EIP155Signer implements Signer using the EIP155 rules.

func NewEIP155Signer

func NewEIP155Signer(chainID *big.Int) EIP155Signer

NewEIP155Signer creates a EIP155Signer given chainID.

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 Signer) bool

Equal checks if the given EIP155Signer is equal to another Signer.

func (EIP155Signer) Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (EIP155Signer) Sender

Sender returns the sender address of the given signer.

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(
	tx *StakingTransaction, sig []byte,
) (R, S, V *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type EditValidator

type EditValidator struct {
	ValidatorAddress   common.Address      `json:"validator_address" yaml:"validator_address" rlp:"nil"`
	Description        *Description        `json:"description" yaml:"description" rlp:"nil"`
	CommissionRate     *numeric.Dec        `json:"commission_rate" yaml:"commission_rate" rlp:"nil"`
	MinSelfDelegation  *big.Int            `json:"min_self_delegation" yaml:"min_self_delegation" rlp:"nil"`
	MaxTotalDelegation *big.Int            `json:"max_total_delegation" yaml:"max_total_delegation" rlp:"nil"`
	SlotKeyToRemove    *shard.BlsPublicKey `json:"slot_key_to_remove" yaml:"slot_key_to_remove" rlp:"nil"`
	SlotKeyToAdd       *shard.BlsPublicKey `json:"slot_key_to_add" yaml:"slot_key_to_add" rlp:"nil"`
	SlotKeyToAddSig    shard.BlsSignature  `json:"slot_key_to_add_sig" yaml:"slot_key_to_add_sig" rlp:"nil"`
}

EditValidator - type for edit existing validator

func (EditValidator) Copy added in v1.3.0

func (v EditValidator) Copy() StakeMsg

Copy deep copy of the interface

func (EditValidator) Type added in v1.3.0

func (v EditValidator) Type() Directive

Type of EditValidator

type KeysPerShard added in v1.3.0

type KeysPerShard struct {
	ShardID uint32               `json:"shard-id"`
	Keys    []shard.BlsPublicKey `json:"bls-public-keys"`
}

KeysPerShard ..

type RPCTransactionError added in v1.3.0

type RPCTransactionError struct {
	TxHashID             string `json:"tx-hash-id"`
	StakingDirective     string `json:"directive-kind"`
	TimestampOfRejection int64  `json:"time-at-rejection"`
	ErrMessage           string `json:"error-message"`
}

RPCTransactionError ..

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *StakingTransaction) (common.Address, error)
	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *StakingTransaction, sig []byte) (r, s, v *big.Int, err error)
	// Hash returns the hash to be signed.
	Hash(tx *StakingTransaction) common.Hash
	// Equal returns true if the given signer is the same as the receiver.
	Equal(s Signer) bool
}

Signer encapsulates transaction signature handling. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.

type StakeMsg added in v1.3.0

type StakeMsg interface {
	Type() Directive
	Copy() StakeMsg
}

StakeMsg defines the interface of Stake Message

type StakeMsgFulfiller

type StakeMsgFulfiller func() (Directive, interface{})

StakeMsgFulfiller is signature of callback intended to produce the StakeMsg

type StakingTransaction

type StakingTransaction struct {
	// contains filtered or unexported fields
}

StakingTransaction is a record captuing all staking operations

func NewStakingTransaction

func NewStakingTransaction(
	nonce, gasLimit uint64, gasPrice *big.Int, f StakeMsgFulfiller,
) (*StakingTransaction, error)

NewStakingTransaction produces a new staking transaction record

func Sign

Sign signs the stake using the given signer and private key

func (*StakingTransaction) ChainID

func (tx *StakingTransaction) ChainID() *big.Int

ChainID is what chain this staking transaction for

func (*StakingTransaction) Copy added in v1.3.0

Copy returns a copy of the transaction.

func (*StakingTransaction) DecodeRLP

func (tx *StakingTransaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*StakingTransaction) EncodeRLP

func (tx *StakingTransaction) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*StakingTransaction) Gas

func (tx *StakingTransaction) Gas() uint64

Gas returns gas of StakingTransaction.

func (*StakingTransaction) Hash

func (tx *StakingTransaction) Hash() common.Hash

Hash hashes the RLP encoding of tx. It uniquely identifies the transaction.

func (*StakingTransaction) Nonce added in v1.3.0

func (tx *StakingTransaction) Nonce() uint64

Nonce returns nonce of staking tx

func (*StakingTransaction) Price added in v1.3.0

func (tx *StakingTransaction) Price() *big.Int

Price returns price of StakingTransaction.

func (*StakingTransaction) RLPEncodeStakeMsg added in v1.3.0

func (tx *StakingTransaction) RLPEncodeStakeMsg() (by []byte, err error)

RLPEncodeStakeMsg ..

func (*StakingTransaction) RawSignatureValues added in v1.3.0

func (tx *StakingTransaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)

RawSignatureValues return raw signature values.

func (*StakingTransaction) SenderAddress added in v1.3.0

func (tx *StakingTransaction) SenderAddress() (common.Address, error)

SenderAddress returns the address of staking transaction sender

func (*StakingTransaction) StakingMessage added in v1.3.0

func (tx *StakingTransaction) StakingMessage() interface{}

StakingMessage returns the stake message of staking transaction

func (*StakingTransaction) StakingType added in v1.3.0

func (tx *StakingTransaction) StakingType() Directive

StakingType returns the type of staking transaction

func (*StakingTransaction) WithSignature

func (tx *StakingTransaction) WithSignature(signer Signer, sig []byte) (*StakingTransaction, error)

WithSignature returns a new transaction with the given signature.

type StakingTransactions

type StakingTransactions []*StakingTransaction

StakingTransactions is a stake slice type for basic sorting.

func (StakingTransactions) GetRlp added in v1.3.0

func (s StakingTransactions) GetRlp(i int) []byte

GetRlp implements Rlpable and returns the i'th element of s in rlp.

func (StakingTransactions) Len added in v1.3.0

func (s StakingTransactions) Len() int

Len ..

type Undelegate

type Undelegate struct {
	DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address" rlp:"nil"`
	ValidatorAddress common.Address `json:"validator_address" yaml:"validator_address" rlp:"nil"`
	Amount           *big.Int       `json:"amount" yaml:"amount" rlp:"nil"`
}

Undelegate - type for removing delegation responsibility

func (Undelegate) Copy added in v1.3.0

func (v Undelegate) Copy() StakeMsg

Copy deep copy of the interface

func (Undelegate) Type added in v1.3.0

func (v Undelegate) Type() Directive

Type of Undelegate

type Undelegation added in v1.3.0

type Undelegation struct {
	Amount *big.Int
	Epoch  *big.Int
}

Undelegation represents one undelegation entry

type Validator

type Validator struct {
	// ECDSA address of the validator
	Address common.Address
	// The BLS public key of the validator for consensus
	SlotPubKeys []shard.BlsPublicKey
	// The number of the last epoch this validator is selected in committee (0 means never selected)
	LastEpochInCommittee *big.Int
	// validator's self declared minimum self delegation
	MinSelfDelegation *big.Int
	// maximum total delegation allowed
	MaxTotalDelegation *big.Int
	// Is the validator active in participating committee selection process or not
	Active bool
	// commission parameters
	Commission
	// description for the validator
	Description
	// CreationHeight is the height of creation
	CreationHeight *big.Int
}

Validator - data fields for a validator

func CreateValidatorFromNewMsg added in v1.3.0

func CreateValidatorFromNewMsg(val *CreateValidator, blockNum *big.Int) (*Validator, error)

CreateValidatorFromNewMsg creates validator from NewValidator message

func UnmarshalValidator added in v1.3.0

func UnmarshalValidator(by []byte) (*Validator, error)

UnmarshalValidator unmarshal binary into Validator object

func (*Validator) GetAddress added in v1.3.0

func (v *Validator) GetAddress() common.Address

GetAddress returns address

func (*Validator) GetCommissionRate added in v1.3.0

func (v *Validator) GetCommissionRate() numeric.Dec

GetCommissionRate returns the commission rate of the validator

func (*Validator) GetMinSelfDelegation added in v1.3.0

func (v *Validator) GetMinSelfDelegation() *big.Int

GetMinSelfDelegation returns the minimum amount the validator must stake

func (*Validator) GetName added in v1.3.0

func (v *Validator) GetName() string

GetName returns the name of validator in the description

func (*Validator) MarshalJSON added in v1.3.0

func (v *Validator) MarshalJSON() ([]byte, error)

MarshalJSON ..

func (*Validator) String added in v1.3.0

func (v *Validator) String() string

String returns a human readable string representation of a validator.

type ValidatorStats added in v1.3.0

type ValidatorStats struct {
	// The number of blocks the validator should've signed when in active mode (selected in committee)
	NumBlocksToSign *big.Int `rlp:"nil"`
	// The number of blocks the validator actually signed
	NumBlocksSigned *big.Int `rlp:"nil"`
	// The number of times they validator is jailed due to extensive downtime
	NumJailed *big.Int `rlp:"nil"`
	// TotalEffectiveStake is the total effective stake this validator has
	TotalEffectiveStake numeric.Dec `rlp:"nil"`
	// VotingPowerPerShard ..
	VotingPowerPerShard []VotePerShard
	// BLSKeyPerShard ..
	BLSKeyPerShard []KeysPerShard
}

ValidatorStats to record validator's performance and history records

func (*ValidatorStats) MarshalJSON added in v1.3.0

func (v *ValidatorStats) MarshalJSON() ([]byte, error)

MarshalJSON ..

type ValidatorWrapper added in v1.3.0

type ValidatorWrapper struct {
	Validator   `json:"validator" yaml:"validator" rlp:"nil"`
	Delegations []Delegation `json:"delegations" yaml:"delegations" rlp:"nil"`
}

ValidatorWrapper contains validator and its delegation information

func (*ValidatorWrapper) SanityCheck added in v1.3.0

func (w *ValidatorWrapper) SanityCheck() error

SanityCheck checks the basic requirements

func (*ValidatorWrapper) TotalDelegation added in v1.3.0

func (w *ValidatorWrapper) TotalDelegation() *big.Int

TotalDelegation - return the total amount of token in delegation

type VotePerShard added in v1.3.0

type VotePerShard struct {
	ShardID     uint32      `json:"shard-id"`
	VotingPower numeric.Dec `json:"voting-power"`
}

VotePerShard ..

Jump to

Keyboard shortcuts

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