sequence

package
v0.2.3-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSequenceUniqueConstraint = errors.Register("sequence_u256", 1, "sequence already initialized")
)

Functions

func DecodeSequence

func DecodeSequence(bz []byte) math.Uint

func EncodeSequence

func EncodeSequence(u math.Uint) []byte

Types

type U256

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

U256 is a persistent unique key generator based on a counter.

func NewSequence256

func NewSequence256(prefix []byte) U256

func (U256) CurVal

func (s U256) CurVal(store storetypes.KVStore) math.Uint

CurVal returns the last value used. 0 if none.

func (U256) InitVal

func (s U256) InitVal(store storetypes.KVStore, seq math.Uint) error

InitVal this function sets the starting value for a sequence and can only be called once on an empty database. If the key already exists, an error will be returned. The provided start value will be stored as the current value. It is advised to use this function only when the sequence start value is not '1', as calling it unnecessarily will consume unnecessary gas. An example scenario would be importing from genesis.

func (U256) NextVal

func (s U256) NextVal(store storetypes.KVStore) math.Uint

NextVal increments and persists the counter by one and returns the value.

func (U256) PeekNextVal

func (s U256) PeekNextVal(store storetypes.KVStore) math.Uint

PeekNextVal returns the CurVal + increment step. Not persistent.

Jump to

Keyboard shortcuts

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