sfcapi

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DelegationIDSize is size of DelegationID serialized object
	DelegationIDSize = 20 + 4
)

Variables

View Source
var (
	// ForkBit is set if staker has a confirmed pair of fork events
	ForkBit = uint64(1)
	// OfflineBit is set if staker has didn't have confirmed events for a long time
	OfflineBit = uint64(1 << 8)
	// CheaterMask is a combination of severe misbehavings
	CheaterMask = ForkBit
)
View Source
var (
	// Topics of SFC contract logs
	Topics = struct {
		ClaimedRewards          common.Hash
		RestakedRewards         common.Hash
		ClaimedDelegationReward common.Hash
		ClaimedValidatorReward  common.Hash
		CreatedValidator        common.Hash
		DeactivatedValidator    common.Hash
		ChangedValidatorStatus  common.Hash
		Delegated               common.Hash
		Undelegated             common.Hash
	}{
		ClaimedRewards:          crypto.Keccak256Hash([]byte("ClaimedRewards(address,uint256,uint256,uint256,uint256)")),
		RestakedRewards:         crypto.Keccak256Hash([]byte("RestakedRewards(address,uint256,uint256,uint256,uint256)")),
		ClaimedDelegationReward: crypto.Keccak256Hash([]byte("ClaimedDelegationReward(address,uint256,uint256,uint256,uint256)")),
		ClaimedValidatorReward:  crypto.Keccak256Hash([]byte("ClaimedValidatorReward(uint256,uint256,uint256,uint256)")),
		CreatedValidator:        crypto.Keccak256Hash([]byte("CreatedValidator(uint256,address,uint256,uint256)")),
		DeactivatedValidator:    crypto.Keccak256Hash([]byte("DeactivatedValidator(uint256,uint256,uint256)")),
		ChangedValidatorStatus:  crypto.Keccak256Hash([]byte("ChangedValidatorStatus(uint256,uint256)")),
		Delegated:               crypto.Keccak256Hash([]byte("Delegated(address,uint256,uint256)")),
		Undelegated:             crypto.Keccak256Hash([]byte("Undelegated(address,uint256,uint256,uint256)")),
	}
)

Functions

func ApplyGenesis

func ApplyGenesis(s *Store, index *topicsdb.Index)

func OnNewLog

func OnNewLog(s *Store, l *types.Log)

Types

type DelegationID

type DelegationID struct {
	Delegator common.Address
	StakerID  idx.ValidatorID
}

DelegationID is a pair of delegator address and staker ID to which delegation is applied

func BytesToDelegationID

func BytesToDelegationID(bb []byte) DelegationID

func (*DelegationID) Bytes

func (id *DelegationID) Bytes() []byte

type EpochStats

type EpochStats struct {
	Start    inter.Timestamp
	End      inter.Timestamp
	TotalFee *big.Int

	Epoch                 idx.Epoch `rlp:"-"` // API-only field
	TotalBaseRewardWeight *big.Int  `rlp:"-"` // API-only field
	TotalTxRewardWeight   *big.Int  `rlp:"-"` // API-only field
}

EpochStats stores general statistics for an epoch

func (*EpochStats) Duration

func (s *EpochStats) Duration() inter.Timestamp

Duration returns epoch duration

type SfcDelegation

type SfcDelegation struct {
	Amount *big.Int

	// API-only fields
	CreatedEpoch     idx.Epoch       `rlp:"-"`
	CreatedTime      inter.Timestamp `rlp:"-"`
	DeactivatedEpoch idx.Epoch       `rlp:"-"`
	DeactivatedTime  inter.Timestamp `rlp:"-"`
}

SfcDelegation is the node-side representation of SFC delegation

type SfcDelegationAndID

type SfcDelegationAndID struct {
	Delegation *SfcDelegation
	ID         DelegationID
}

SfcDelegationAndID is pair SfcDelegation + address

type SfcStaker

type SfcStaker struct {
	CreatedEpoch idx.Epoch
	CreatedTime  inter.Timestamp

	DeactivatedEpoch idx.Epoch
	DeactivatedTime  inter.Timestamp

	Address common.Address

	Status uint64

	// API-only fields
	StakeAmount *big.Int `rlp:"-"`
	DelegatedMe *big.Int `rlp:"-"`
	IsValidator bool     `rlp:"-"`
}

SfcStaker is the node-side representation of SFC staker

func (*SfcStaker) CalcTotalStake

func (s *SfcStaker) CalcTotalStake() *big.Int

CalcTotalStake returns sum of staker's stake and delegated to staker stake

func (*SfcStaker) HasFork

func (s *SfcStaker) HasFork() bool

HasFork returns true if staker has a confirmed fork

func (*SfcStaker) IsCheater

func (s *SfcStaker) IsCheater() bool

IsCheater returns true if staker is cheater

func (*SfcStaker) Offline

func (s *SfcStaker) Offline() bool

Offline returns true if staker was offline for long time

func (*SfcStaker) Ok

func (s *SfcStaker) Ok() bool

Ok returns true if not deactivated and not pruned

type SfcStakerAndID

type SfcStakerAndID struct {
	StakerID idx.ValidatorID
	Staker   *SfcStaker
}

SfcStakerAndID is pair SfcStaker + StakerID

type Store

type Store struct {
	logger.Instance
	// contains filtered or unexported fields
}

Store is a node persistent storage working over physical key-value database.

func NewStore

func NewStore(mainDB kvdb.Store) *Store

NewStore creates store over key-value db.

func (*Store) Close

func (s *Store) Close()

Close closes underlying database.

func (*Store) DelSfcDelegation

func (s *Store) DelSfcDelegation(id DelegationID)

DelSfcDelegation deletes SfcDelegation

func (*Store) DelSfcStaker

func (s *Store) DelSfcStaker(stakerID idx.ValidatorID)

DelSfcStaker deletes SfcStaker

func (*Store) ForEachSfcDelegation

func (s *Store) ForEachSfcDelegation(do func(SfcDelegationAndID))

ForEachSfcDelegation iterates all stored SfcDelegations

func (*Store) ForEachSfcStaker

func (s *Store) ForEachSfcStaker(do func(SfcStakerAndID))

ForEachSfcStaker iterates all stored SfcStakers

func (*Store) GetDelegationClaimedRewards

func (s *Store) GetDelegationClaimedRewards(id DelegationID) *big.Int

GetDelegationClaimedRewards returns sum of claimed rewards in past, by this delegation

func (*Store) GetEpochValidators

func (s *Store) GetEpochValidators(epoch idx.Epoch) []SfcStakerAndID

GetEpochValidators returns all stored EpochValidators on the epoch

func (*Store) GetSfcDelegation

func (s *Store) GetSfcDelegation(id DelegationID) *SfcDelegation

GetSfcDelegation returns stored SfcDelegation

func (*Store) GetSfcDelegationsByAddr

func (s *Store) GetSfcDelegationsByAddr(addr common.Address, limit int) []SfcDelegationAndID

GetSfcDelegationsByAddr returns a lsit of delegations by address

func (*Store) GetSfcStaker

func (s *Store) GetSfcStaker(stakerID idx.ValidatorID) *SfcStaker

GetSfcStaker returns stored SfcStaker

func (*Store) GetSfcStakers

func (s *Store) GetSfcStakers() []SfcStakerAndID

GetSfcStakers returns all stored SfcStakers

func (*Store) GetStakerDelegationsClaimedRewards

func (s *Store) GetStakerDelegationsClaimedRewards(stakerID idx.ValidatorID) *big.Int

GetStakerDelegationsClaimedRewards returns sum of claimed rewards in past, by this delegations of this staker

func (*Store) HasEpochValidator

func (s *Store) HasEpochValidator(epoch idx.Epoch, stakerID idx.ValidatorID) bool

HasEpochValidator returns true if validator exists

func (*Store) HasSfcStaker

func (s *Store) HasSfcStaker(stakerID idx.ValidatorID) bool

HasSfcStaker returns true if staker exists

func (*Store) IncDelegationClaimedRewards

func (s *Store) IncDelegationClaimedRewards(id DelegationID, diff *big.Int)

IncDelegationClaimedRewards increments sum of claimed rewards in past

func (*Store) IncStakerDelegationsClaimedRewards

func (s *Store) IncStakerDelegationsClaimedRewards(stakerID idx.ValidatorID, diff *big.Int)

IncStakerDelegationsClaimedRewards increments sum of claimed rewards in past

func (*Store) SetDelegationClaimedRewards

func (s *Store) SetDelegationClaimedRewards(id DelegationID, amount *big.Int)

SetDelegationClaimedRewards sets sum of claimed rewards in past

func (*Store) SetEpochValidators

func (s *Store) SetEpochValidators(epoch idx.Epoch, vv []SfcStakerAndID)

SetEpochValidators stores EpochValidators

func (*Store) SetSfcDelegation

func (s *Store) SetSfcDelegation(id DelegationID, v *SfcDelegation)

SetSfcDelegation stores SfcDelegation

func (*Store) SetSfcStaker

func (s *Store) SetSfcStaker(stakerID idx.ValidatorID, v *SfcStaker)

SetSfcStaker stores SfcStaker

func (*Store) SetStakerDelegationsClaimedRewards

func (s *Store) SetStakerDelegationsClaimedRewards(stakerID idx.ValidatorID, amount *big.Int)

SetStakerDelegationsClaimedRewards sets sum of claimed rewards in past

Jump to

Keyboard shortcuts

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