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 ¶
- func GetAddress(store sdk.KVStore, key []byte, errField string) sdk.AccAddress
- func GetDec(store sdk.KVStore, key []byte, errField string) sdk.Dec
- func GetInt(store sdk.KVStore, key []byte, errField string) sdkmath.Int
- func GetUint32(store sdk.KVStore, key []byte, errField string) uint32
- func GetUint64(store sdk.KVStore, key []byte, errField string) uint64
- func Iterate(store sdk.KVStore, prefix []byte, cb func(key, val []byte) error) error
- func IteratePaginated(store sdk.KVStore, prefix []byte, page, limit uint, ...) error
- func SetAddress(store sdk.KVStore, key []byte, val sdk.AccAddress, errField string) error
- func SetDec(store sdk.KVStore, key []byte, val sdk.Dec, errField string) error
- func SetInt(store sdk.KVStore, key []byte, val sdkmath.Int, errField string) error
- func SetUint32(store sdk.KVStore, key []byte, val uint32, errField string) error
- func SetUint64(store sdk.KVStore, key []byte, val uint64, errField string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAddress ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.