contractstaking

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBucketNotExist = errors.New("bucket does not exist")

ErrBucketNotExist is the error when bucket does not exist

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// Candidate is the address of the candidate that this bucket is staking for.
	Candidate address.Address
	// Owner is the address of the owner of this bucket.
	Owner address.Address
	// StakedAmount is the amount of tokens staked in this bucket.
	StakedAmount *big.Int

	// StakedDuration is the duration for which the tokens have been staked.
	StakedDuration uint64 // in seconds if timestamped, in block number if not
	// CreatedAt is the time when the bucket was created.
	CreatedAt uint64 // in unix timestamp if timestamped, in block height if not
	// UnlockedAt is the time when the bucket was unlocked.
	UnlockedAt uint64 // in unix timestamp if timestamped, in block height if not
	// UnstakedAt is the time when the bucket was unstaked.
	UnstakedAt uint64 // in unix timestamp if timestamped, in block height if not

	// IsTimestampBased indicates whether the bucket is timestamp-based
	IsTimestampBased bool
	// Muted indicates whether the bucket is vote weight muted
	Muted bool
}

Bucket is the structure that holds information about a staking bucket.

func LoadBucketFromProto

func LoadBucketFromProto(pb *stakingpb.SystemStakingBucket) (*Bucket, error)

LoadBucketFromProto converts a protobuf representation of a staking bucket to a Bucket struct.

func (*Bucket) Clone

func (b *Bucket) Clone() *Bucket

Clone creates a deep copy of the Bucket.

func (*Bucket) Decode

func (b *Bucket) Decode(gv systemcontracts.GenericValue) error

Decode decodes the bucket from a GenericValue

func (*Bucket) Deserialize

func (b *Bucket) Deserialize(data []byte) error

Deserialize deserializes the bucket from a byte slice.

func (*Bucket) Encode

func (b *Bucket) Encode() (systemcontracts.GenericValue, error)

Encode encodes the bucket into a GenericValue

func (*Bucket) Serialize

func (b *Bucket) Serialize() ([]byte, error)

Serialize serializes the bucket to a byte slice.

type BucketType

type BucketType struct {
	Amount      *big.Int
	Duration    uint64
	ActivatedAt uint64
}

BucketType defines the type of contract staking bucket

func LoadBucketTypeFromProto

func LoadBucketTypeFromProto(pb *stakingpb.BucketType) (*BucketType, error)

LoadBucketTypeFromProto converts a protobuf representation of a staking bucket type to a BucketType struct.

func (*BucketType) Clone

func (bt *BucketType) Clone() *BucketType

Clone clones the bucket type

func (*BucketType) Decode

Decode decodes the bucket type from a GenericValue

func (*BucketType) Deserialize

func (bt *BucketType) Deserialize(b []byte) error

Deserialize deserializes the bucket type

func (*BucketType) Encode

func (bt *BucketType) Encode() (systemcontracts.GenericValue, error)

Encode encodes the bucket type into a GenericValue

func (*BucketType) Serialize

func (bt *BucketType) Serialize() ([]byte, error)

Serialize serializes the bucket type

type ContractStakingStateManager

type ContractStakingStateManager struct {
	ContractStakingStateReader
	// contains filtered or unexported fields
}

ContractStakingStateManager wraps a state manager to provide staking contract-specific writes.

func NewContractStakingStateManager

func NewContractStakingStateManager(sm protocol.StateManager, opts ...protocol.StateOption) *ContractStakingStateManager

NewContractStakingStateManager creates a new ContractStakingStateManager

func (*ContractStakingStateManager) DeleteBucket

func (cs *ContractStakingStateManager) DeleteBucket(contractAddr address.Address, bucketID uint64) error

DeleteBucket removes a bucket for a given contract and bucket ID.

func (*ContractStakingStateManager) UpdateNumOfBuckets

func (cs *ContractStakingStateManager) UpdateNumOfBuckets(contractAddr address.Address, numOfBuckets uint64) error

UpdateNumOfBuckets updates the number of buckets.

func (*ContractStakingStateManager) UpsertBucket

func (cs *ContractStakingStateManager) UpsertBucket(contractAddr address.Address, bid uint64, bucket *Bucket) error

UpsertBucket inserts or updates a bucket for a given contract and bid.

func (*ContractStakingStateManager) UpsertBucketType

func (cs *ContractStakingStateManager) UpsertBucketType(contractAddr address.Address, bucketID uint64, bucketType *BucketType) error

UpsertBucketType inserts or updates a bucket type for a given contract and bucket ID.

type ContractStakingStateReader

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

ContractStakingStateReader wraps a state reader to provide staking contract-specific reads.

func NewStateReader

NewStateReader creates a new ContractStakingStateReader.

func (*ContractStakingStateReader) Bucket

func (r *ContractStakingStateReader) Bucket(contractAddr address.Address, bucketID uint64) (*Bucket, error)

Bucket returns the Bucket for a given contract and bucket id.

func (*ContractStakingStateReader) BucketType

func (r *ContractStakingStateReader) BucketType(contractAddr address.Address, tID uint64) (*BucketType, error)

BucketType returns the BucketType for a given contract and bucket id.

func (*ContractStakingStateReader) BucketTypes

func (r *ContractStakingStateReader) BucketTypes(contractAddr address.Address) ([]uint64, []*BucketType, error)

BucketTypes returns all BucketType for a given contract and bucket id.

func (*ContractStakingStateReader) Buckets

func (r *ContractStakingStateReader) Buckets(contractAddr address.Address) ([]uint64, []*Bucket, error)

Buckets returns all BucketInfo for a given contract.

func (*ContractStakingStateReader) NumOfBuckets

func (r *ContractStakingStateReader) NumOfBuckets(contractAddr address.Address) (uint64, error)

NumOfBuckets returns the total number of buckets for a contract.

type StakingContract

type StakingContract struct {
	// NumOfBuckets is the number of buckets in the staking contract
	NumOfBuckets uint64
}

StakingContract represents the staking contract in the system

func LoadStakingContractFromProto

func LoadStakingContractFromProto(pb *stakingpb.SystemStakingContract) (*StakingContract, error)

LoadStakingContractFromProto converts a protobuf representation of a staking contract to a StakingContract struct.

func (*StakingContract) Decode

Decode decodes the staking contract from a GenericValue

func (*StakingContract) Deserialize

func (sc *StakingContract) Deserialize(b []byte) error

Deserialize deserializes the staking contract

func (*StakingContract) Encode

Encode encodes the staking contract into a GenericValue

func (*StakingContract) Serialize

func (sc *StakingContract) Serialize() ([]byte, error)

Serialize serializes the staking contract

Jump to

Keyboard shortcuts

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