ixoutils

package
v4.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoValuesInRange = errors.New("No values in range")
)

Functions

func ApplyFuncIfNoError

func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error)

This function lets you run the function f, but if there's an error or panic drop the state machine change and log the error. If there is no error, proceeds as normal (but with some slowdown due to SDK store weirdness) Try to avoid usage of iterators in f.

If its an out of gas panic, this function will also panic like in normal tx execution flow. This is still safe for beginblock / endblock code though, as they do not have out of gas panics.

func ApplyFuncIfNoErrorLogToDebug

func ApplyFuncIfNoErrorLogToDebug(ctx sdk.Context, f func(ctx sdk.Context) error) (err error)

ApplyFuncIfNoErrorLogToDebug is the same as ApplyFuncIfNoError, but sends logs to debug instead of error if there is an error.

func ChargeMockReadGas

func ChargeMockReadGas(ctx sdk.Context, gasFlat, gasKey, gasVal uint64)

func DeleteAllKeysFromPrefix

func DeleteAllKeysFromPrefix(store storetypes.KVStore, prefixKey []byte)

DeleteAllKeysFromPrefix deletes all store records that contains the given prefixKey.

func GatherAllKeysFromStore

func GatherAllKeysFromStore(storeObj storetypes.KVStore) []string

func GatherValuesFromStore

func GatherValuesFromStore[T any](storeObj storetypes.KVStore, keyStart []byte, keyEnd []byte, parseValue func([]byte) (T, error)) ([]T, error)

func GatherValuesFromStorePrefix

func GatherValuesFromStorePrefix[T any](storeObj storetypes.KVStore, prefix []byte, parseValue func([]byte) (T, error)) ([]T, error)

GatherValuesFromStorePrefix is a decorator around GatherValuesFromStorePrefixWithKeyParser. It overwrites the parse function to disable parsing keys, only keeping values

func GatherValuesFromStorePrefixWithKeyParser

func GatherValuesFromStorePrefixWithKeyParser[T any](storeObj storetypes.KVStore, prefix []byte, parse func(key []byte, value []byte) (T, error)) ([]T, error)

GatherValuesFromStorePrefixWithKeyParser is a helper function that gathers values from a given store prefix. While iterating through the entries, it parses both key and the value using the provided parse function to return the desired type. Returns error if: - the parse function returns an error. - internal database error

func Get

func Get(store storetypes.KVStore, key []byte, result proto.Message) (found bool, err error)

Get returns a value at key by mutating the result parameter. Returns true if the value was found and the result mutated correctly. If the value is not in the store, returns false. Returns error only when database or serialization errors occur. (And when an error occurs, returns false)

func GetCoinArrayFromPrefix

func GetCoinArrayFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, storePrefix []byte) []sdk.Coin

GetCoinArrayFromPrefix returns all coins from the store that has the given prefix.

func GetCoinByDenomFromPrefix

func GetCoinByDenomFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, storePrefix []byte, denom string) (sdk.Coin, error)

GetCoinByDenomFromPrefix returns the coin from the store that has the given prefix and denom. If the denom is not found, a zero coin is returned.

func GetDec

func GetDec(store storetypes.KVStore, key []byte) (math.LegacyDec, error)

GetDec gets dec value from store at key. Returns error if: - database error occurs. - no value at given key is found.

func GetFirstValueAfterPrefixInclusive

func GetFirstValueAfterPrefixInclusive[T any](storeObj storetypes.KVStore, keyStart []byte, parseValue func([]byte) (T, error)) (T, error)

func GetFirstValueInRange

func GetFirstValueInRange[T any](storeObj storetypes.KVStore, keyStart []byte, keyEnd []byte, reverseIterate bool, parseValue func([]byte) (T, error)) (T, error)

func GetIterValuesWithStop

func GetIterValuesWithStop[T any](
	storeObj storetypes.KVStore,
	keyStart []byte,
	keyEnd []byte,
	reverse bool,
	stopFn func([]byte) bool,
	parseValue func([]byte) (T, error),
) ([]T, error)

func GetValuesUntilDerivedStop

func GetValuesUntilDerivedStop[T any](storeObj storetypes.KVStore, keyStart []byte, stopFn func([]byte) bool, parseValue func([]byte) (T, error)) ([]T, error)

func HasAnyAtPrefix

func HasAnyAtPrefix[T any](storeObj storetypes.KVStore, prefix []byte, parseValue func([]byte) (T, error)) (bool, error)

HasAnyAtPrefix returns true if there is at least one value in the given prefix.

func IncreaseCoinByDenomFromPrefix

func IncreaseCoinByDenomFromPrefix(ctx sdk.Context, storeKey storetypes.StoreKey, storePrefix []byte, denom string, increasedAmt math.Int) error

IncreaseCoinByDenomFromPrefix increases the coin from the store that has the given prefix and denom by the specified amount.

func IsOutOfGasError

func IsOutOfGasError(err any) (bool, string)

Frustratingly, this has to return the error descriptor, not an actual error itself because the SDK errors here are not actually errors. (They don't implement error interface)

func MustGet

func MustGet(store storetypes.KVStore, key []byte, result proto.Message)

MustGet gets key from store by mutating result Panics on any error.

func MustGetDec

func MustGetDec(store storetypes.KVStore, key []byte) math.LegacyDec

MustGetDec gets dec value from store at key. Panics on any error.

func MustSet

func MustSet(storeObj storetypes.KVStore, key []byte, value proto.Message)

MustSet runs store.Set(key, proto.Marshal(value)) but panics on any error.

func MustSetDec

func MustSetDec(store storetypes.KVStore, key []byte, value math.LegacyDec)

MustSetDec sets dec value to store at key. Panics on any error.

func PrintPanicRecoveryError

func PrintPanicRecoveryError(ctx sdk.Context, recoveryError interface{})

PrintPanicRecoveryError error logs the recoveryError, along with the stacktrace, if it can be parsed. If not emits them to stdout.

func TrackGasUsedInGet

func TrackGasUsedInGet(store storetypes.KVStore, key []byte, result proto.Message) (found bool, gasFlat, gasKey, gasVal uint64, err error)

Get returns a value at key by mutating the result parameter. Returns true if the value was found and the result mutated correctly. If the value is not in the store, returns false. Returns error only when database or serialization errors occur. (And when an error occurs, returns false)

This function also returns three gas numbers: Gas flat, gas for key read, gas for value read. You must charge all 3 for the gas accounting to be correct in the current SDK version. nolint

Types

type DecNotFoundError

type DecNotFoundError struct {
	Key string
}

func (DecNotFoundError) Error

func (e DecNotFoundError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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