sequence

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

sequenceKey a fix key to read/ write data on the storage layer

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
}

SequenceU256 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 sdk.KVStore) math.Uint

CurVal returns the last value used. 0 if none.

func (U256) InitVal

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

InitVal sets the start value for the sequence. It must be called only once on an empty DB. Otherwise an error is returned when the key exists. The given start value is stored as current value.

It is recommended to call this method only for a sequence start value other than `1` as the method consumes unnecessary gas otherwise. A scenario would be an import from genesis.

func (U256) NextVal

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

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

func (U256) PeekNextVal

func (s U256) PeekNextVal(store sdk.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