utils

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 theres 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 ContainsDuplicate

func ContainsDuplicate[T any](arr []T) bool

ContainsDuplicate checks if there are any duplicate elements in the slice.

func CreateRandomAccounts

func CreateRandomAccounts(numAccts int) []sdk.AccAddress

CreateRandomAccounts is a function return a list of randomly generated AccAddresses

func Filter

func Filter[T interface{}](filter func(T) bool, s []T) []T

func FilteredPaginateAccountBalances

func FilteredPaginateAccountBalances(
	ctx sdk.Context,
	bankKeeper types.BankKeeper,
	address sdk.AccAddress,
	pageRequest *query.PageRequest,
	onResult func(coin sdk.Coin, accumulate bool) bool,
) (*query.PageResponse, error)

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 MakeNew

func MakeNew[T any]() T

MakeNew makes a new instance of generic T. if T is a pointer, makes a new instance of the underlying struct via reflection, and then a pointer to it.

func ParseSdkDecFromString

func ParseSdkDecFromString(s, separator string) ([]sdk.Dec, error)

func ParseSdkIntFromString

func ParseSdkIntFromString(s, separator string) ([]math.Int, error)

func ParseUint64SliceFromString

func ParseUint64SliceFromString(s, separator string) ([]uint64, 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 ReverseSlice

func ReverseSlice[T any](s []T) []T

ReverseSlice reverses the input slice in place. Does mutate argument.

func SanitizeCoins

func SanitizeCoins(coins []sdk.Coin) sdk.Coins

SanitizeCoins takes an unsorted list of coins and sorts them, removes coins with amount zero and combines duplicate coins

func SortSlice

func SortSlice[T constraints.Ordered](s []T)

SortSlice sorts a slice of type T elements that implement constraints.Ordered. Mutates input slice s

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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