Documentation ¶
Index ¶
- Constants
- Variables
- func MarshalValidator(validator Validator) ([]byte, error)
- func RLPDecodeStakeMsg(payload []byte, d Directive) (interface{}, error)
- func Sender(signer Signer, tx *StakingTransaction) (common.Address, error)
- func UpdateValidatorFromEditMsg(validator *Validator, edit *EditValidator) error
- type CollectRewards
- type Commission
- type CommissionRates
- type CreateValidator
- type Delegate
- type Delegation
- type DelegationIndex
- type Description
- type Directive
- type EIP155Signer
- type EditValidator
- type KeysPerShard
- type RPCTransactionError
- type Signer
- type StakeMsg
- type StakeMsgFulfiller
- type StakingTransaction
- func (tx *StakingTransaction) ChainID() *big.Int
- func (tx *StakingTransaction) Copy() *StakingTransaction
- func (tx *StakingTransaction) DecodeRLP(s *rlp.Stream) error
- func (tx *StakingTransaction) EncodeRLP(w io.Writer) error
- func (tx *StakingTransaction) Gas() uint64
- func (tx *StakingTransaction) Hash() common.Hash
- func (tx *StakingTransaction) Nonce() uint64
- func (tx *StakingTransaction) Price() *big.Int
- func (tx *StakingTransaction) RLPEncodeStakeMsg() (by []byte, err error)
- func (tx *StakingTransaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int)
- func (tx *StakingTransaction) SenderAddress() (common.Address, error)
- func (tx *StakingTransaction) StakingMessage() interface{}
- func (tx *StakingTransaction) StakingType() Directive
- func (tx *StakingTransaction) WithSignature(signer Signer, sig []byte) (*StakingTransaction, error)
- type StakingTransactions
- type Undelegate
- type Undelegation
- type Validator
- type ValidatorStats
- type ValidatorWrapper
- type VotePerShard
Constants ¶
const ( MaxNameLength = 70 MaxIdentityLength = 3000 MaxWebsiteLength = 140 MaxSecurityContactLength = 140 MaxDetailsLength = 280 BlsVerificationStr = "harmony-one" )
Define validator staking related const
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 ¶
var ( // ErrInvalidSig is a bad signature ErrInvalidSig = errors.New("invalid transaction v, r, s values") )
var ( // ErrInvalidStakingKind given when caller gives bad staking message kind ErrInvalidStakingKind = errors.New("bad staking kind") )
Functions ¶
func MarshalValidator ¶ added in v1.3.0
MarshalValidator marshals the validator object
func RLPDecodeStakeMsg ¶ added in v1.3.0
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
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
Undelegate - append entry to the undelegation
type DelegationIndex ¶ added in v1.3.0
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 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 ¶
func (s EIP155Signer) Hash(tx *StakingTransaction) common.Hash
Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.
func (EIP155Signer) Sender ¶
func (s EIP155Signer) Sender(tx *StakingTransaction) (common.Address, error)
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 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 ¶
func Sign(tx *StakingTransaction, s Signer, prv *ecdsa.PrivateKey) (*StakingTransaction, error)
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
func (tx *StakingTransaction) Copy() *StakingTransaction
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
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.
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
type Undelegation ¶ added in v1.3.0
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
UnmarshalValidator unmarshal binary into Validator object
func (*Validator) GetAddress ¶ added in v1.3.0
GetAddress returns address
func (*Validator) GetCommissionRate ¶ added in v1.3.0
GetCommissionRate returns the commission rate of the validator
func (*Validator) GetMinSelfDelegation ¶ added in v1.3.0
GetMinSelfDelegation returns the minimum amount the validator must stake
func (*Validator) GetName ¶ added in v1.3.0
GetName returns the name of validator in the description
func (*Validator) MarshalJSON ¶ added in v1.3.0
MarshalJSON ..
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 ..