store

package
v4.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package store implements KVStore getters and setters for various types.

The methods in this package are made to be resistant to bugs introduced through the following pathways:

  • Manually edited genesis state (bad input will appear in SetX during ImportGenesis)
  • Bug in code (bad input could appear in SetX at any time)
  • Incomplete migration (bad data will be unmarshaled by GetX after the migration)
  • Incorrect binary swap (same vectors as incomplete migration)

Setters return errors on bad input. For getters (which should only see bad data in exotic cases) panics are used instead for simpler function signatures.

Numerical getters and setters have a minimum value of zero, which will be interpreted as follows:

  • Setters reject negative input, and clear a KVStore entry when setting to exactly zero.
  • Getters panic on unmarshaling a negative value, and interpret empty data as zero.

All functions require an errField parameter which is used when creating error messages. For example, the errField "balance" could appear in errors like "-12: cannot set negative balance". These errFields are cosmetic and do not affect the stored data (key or value) in any way.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAddress

func GetAddress(store sdk.KVStore, key []byte, errField string) sdk.AccAddress

GetAddress retrieves an sdk.AccAddress from a KVStore, or an empty address if no value is stored. Panics if a non-empty address fails sdk.VerifyAddressFormat, so non-empty returns are always valid. Accepts an additional string which should describe the field being retrieved in custom error messages.

func GetDec

func GetDec(store sdk.KVStore, key []byte, errField string) sdk.Dec

GetDec retrieves an sdk.Dec from a KVStore, or returns zero if no value is stored. It panics if a stored value fails to unmarshal or is negative. Accepts an additional string which should describe the field being retrieved in custom error messages.

func GetInt

func GetInt(store sdk.KVStore, key []byte, errField string) sdkmath.Int

GetInt retrieves an sdkmath.Int from a KVStore, or returns zero if no value is stored. It panics if a stored value fails to unmarshal or is negative. Accepts an additional string which should describe the field being retrieved in custom error messages.

func GetUint32

func GetUint32(store sdk.KVStore, key []byte, errField string) uint32

GetUint32 retrieves a uint32 from a KVStore, or returns zero if no value is stored. Uses gogoproto Uint32Value for unmarshaling, and panics if a stored value fails to unmarshal. Accepts an additional string which should describe the field being retrieved in custom error messages.

func GetUint64

func GetUint64(store sdk.KVStore, key []byte, errField string) uint64

GetUint64 retrieves a uint64 from a KVStore, or returns zero if no value is stored. Uses gogoproto Uint64Value for unmarshaling, and panics if a stored value fails to unmarshal. Accepts an additional string which should describe the field being retrieved in custom error messages.

func Iterate added in v4.3.0

func Iterate(store sdk.KVStore, prefix []byte, cb func(key, val []byte) error) error

Iterate through all keys in a kvStore that start with a given prefix using a provided function. If the provided function returns an error, iteration stops and the error is returned.

func IteratePaginated added in v4.3.0

func IteratePaginated(store sdk.KVStore, prefix []byte, page, limit uint, cb func(key, val []byte) error) error

IteratePaginated through keys in a kvStore that start with a given prefix using a provided function. If the provided function returns an error, iteration stops and the error is returned. Accepts pagination parameters: limit defines a number of keys per page, and page indicates what page to skip to when iterating. For example, page = 3 and limit = 10 will iterate over the 21st - 30th keys that would be found by a non-paginated iterator.

func SetAddress

func SetAddress(store sdk.KVStore, key []byte, val sdk.AccAddress, errField string) error

SetAddress stores an sdk.AccAddress in a KVStore, or clears if setting to an empty or nil address. Returns an error on attempting to store a non-empty address that fails sdk.VerifyAddressFormat. Accepts an additional string which should describe the field being set in custom error messages.

func SetDec

func SetDec(store sdk.KVStore, key []byte, val sdk.Dec, errField string) error

SetDec stores an sdk.Dec in a KVStore, or clears if setting to zero or nil. Returns an error on attempting to store negative value or on failure to encode. Accepts an additional string which should describe the field being set in custom error messages.

func SetInt

func SetInt(store sdk.KVStore, key []byte, val sdkmath.Int, errField string) error

SetInt stores an sdkmath.Int in a KVStore, or clears if setting to zero or nil. Returns an error on attempting to store negative value or on failure to encode. Accepts an additional string which should describe the field being set in custom error messages.

func SetUint32

func SetUint32(store sdk.KVStore, key []byte, val uint32, errField string) error

SetUint32 stores a uint32 in a KVStore, or clears if setting to zero. Uses gogoproto Uint32Value for marshaling, and returns an error on failure to encode. Accepts an additional string which should describe the field being set in custom error messages.

func SetUint64

func SetUint64(store sdk.KVStore, key []byte, val uint64, errField string) error

SetUint64 stores a uint32 in a KVStore, or clears if setting to zero. Uses gogoproto Uint64Value for marshaling, and returns an error on failure to encode. Accepts an additional string which should describe the field being set in custom error messages.

Types

This section is empty.

Jump to

Keyboard shortcuts

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