Documentation ¶
Index ¶
- func ApplyFuncIfNoError(ctx sdk.Context, f func(ctx sdk.Context) error) (err error)
- func CanCreateModuleAccountAtAddr(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) error
- func CompositeKey(parts ...[]byte) []byte
- func ComputeTokensFromShares(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins
- func ComputeTokensFromSharesTruncated(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins
- func Contains[T comparable](slice []T, value T) bool
- func CreateModuleAccount(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) error
- func DenomsSubsetOf(coins sdk.DecCoins, coinsB sdk.DecCoins) bool
- func FilterCoinsByDenom(coins, coinsB sdk.Coins) sdk.Coins
- func FilterDecCoinsByDenom(coins, coinsB sdk.DecCoins) sdk.DecCoins
- func FilterDepositRecords(arr []recordstypes.DepositRecord, ...) (ret []recordstypes.DepositRecord)
- func FindDuplicate[T comparable](slice []T) *T
- func FindDuplicateFunc[T any](slice []T, compare func(a T, b T) bool) *T
- func FormatUint32Slice(s []uint32) string
- func GetFromBech32(bech32str, prefix string) ([]byte, error)
- func GetSharesDenomFromTokenDenom(prefix string, id uint32, tokenDenom string) string
- func GetTokenDenomFromSharesDenom(sharesDenom string) string
- func IsAllGT(coins, coinsB sdk.DecCoins) bool
- func IsAllGTE(coins, coinsB sdk.DecCoins) bool
- func IsAnyGT(coins, coinsB sdk.DecCoins) bool
- func IsAnyLT(coins, coinsB sdk.DecCoins) bool
- func IsIcs20Packet(packetData []byte) (isIcs20 bool, ics20data transfertypes.FungibleTokenPacketData)
- func IsInvalidExRate(delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) bool
- func IsOutOfGasError(err any) (bool, string)
- func IssueShares(amount sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, ...) sdk.DecCoins
- func JSONStringHasKey(data, key string) (found bool, jsonObject map[string]interface{})
- func LogHeader(s string, a ...any) string
- func LogICACallbackStatusWithHostZone(chainID string, callbackID string, status icacallbacktypes.AckResponseStatus, ...) string
- func LogICACallbackWithHostZone(chainID string, callbackID string, s string, a ...any) string
- func LogICQCallbackWithHostZone(chainID string, callbackID string, s string, a ...any) string
- func LogWithHostZone(chainID string, s string, a ...any) string
- func Map[T, U any](slice []T, f func(T) U) []U
- func MapGetOrDefault[K, V any](ctx sdk.Context, collectionMap collections.Map[K, V], key K, ...) (V, error)
- func Min(a int, b int) int
- func MustParseCoin(s string) sdk.Coin
- func MustParseCoins(s string) sdk.Coins
- func MustParseDec(s string) sdkmath.LegacyDec
- func MustParseDecCoins(s string) sdk.DecCoins
- func ParseUint32Slice(s string) ([]uint32, error)
- func PrintPanicRecoveryError(ctx sdk.Context, recoveryError interface{})
- func Remove[T comparable](slice []T, value T) (newSlice []T, removed bool)
- func RemoveDuplicates[T comparable](slice []T) []T
- func SharesFromDecCoins(tokens sdk.DecCoins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, ...) (sdk.DecCoins, error)
- func SharesFromTokens(tokens sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, ...) (sdk.DecCoins, error)
- func SharesFromTokensTruncated(tokens sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, ...) (sdk.DecCoins, error)
- func StAssetDenomFromHostZoneDenom(hostZoneDenom string) string
- func StringMapKeys[V any](m map[string]V) []string
- func Uint32ToBigEndian(i uint32) []byte
- func VerifyAddressFormat(bz []byte) error
- func VerifyTxHash(txHash string) (err error)
- type AccAddress
- type AccountKeeper
- type ShareDenomGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyFuncIfNoError ¶
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 CanCreateModuleAccountAtAddr ¶
func CanCreateModuleAccountAtAddr(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) error
CanCreateModuleAccountAtAddr tells us if we can safely make a module account at a given address. By collision resistance of the address (given API safe construction), the only way for an account to be already be at this address is if its claimed by the same pre-image from the correct module, or some SDK command breaks assumptions and creates an account at designated address. This function checks if there is an account at that address, and runs some safety checks to be extra-sure its not a user account (e.g. non-zero sequence, pubkey, of fore-seen account types). If there is no account, or if we believe its not a user-spendable account, we allow module account creation at the address. else, we do not.
func CompositeKey ¶ added in v1.2.0
func ComputeTokensFromShares ¶ added in v1.2.0
func ComputeTokensFromShares(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins
ComputeTokensFromShares calculates the token worth of provided shares.
func ComputeTokensFromSharesTruncated ¶ added in v1.2.0
func ComputeTokensFromSharesTruncated(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins
ComputeTokensFromSharesTruncated calculates the token worth of provided shares, truncated.
func Contains ¶ added in v1.3.0
func Contains[T comparable](slice []T, value T) bool
Contains returns true if the slice contains the given value.
func CreateModuleAccount ¶
func CreateModuleAccount(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) error
CreateModuleAccount creates a module account at the provided address. It overrides an account if it exists at that address, with a non-zero sequence number & pubkey Contract: addr is derived from `address.Module(ModuleName, key)`
func DenomsSubsetOf ¶ added in v1.2.0
DenomsSubsetOf returns true if receiver's denom set is subset of coinsB's denoms.
func FilterCoinsByDenom ¶ added in v1.2.0
FilterCoinsByDenom returns the intersection of two coins. e.g. FilterCoinsByDenom({2A, 3B}, {A}) = {2A} FilterCoinsByDenom({2A, 3B}, {5C}) = {} FilterCoinsByDenom({2A, 3B}, {A, B}) = {2A, 3B}
func FilterDecCoinsByDenom ¶ added in v1.2.0
FilterDecCoinsByDenom returns the intersection of two coins. e.g. FilterDecCoinsByDenom{2A, 3B}, {A}) = {2A} FilterDecCoinsByDenom({2A, 3B}, {5C}) = {} FilterDecCoinsByDenom({2A, 3B}, {A, B}) = {2A, 3B}
func FilterDepositRecords ¶
func FilterDepositRecords(arr []recordstypes.DepositRecord, condition func(recordstypes.DepositRecord) bool) (ret []recordstypes.DepositRecord)
func FindDuplicate ¶ added in v1.2.0
func FindDuplicate[T comparable](slice []T) *T
FindDuplicate returns the first duplicate element in the slice. If no duplicates are found, it returns nil instead.
func FindDuplicateFunc ¶ added in v1.2.0
FindDuplicateFunc returns the first duplicate element in the slice. If no duplicates are found, it returns nil instead.
func FormatUint32Slice ¶ added in v1.2.0
func GetFromBech32 ¶
GetFromBech32 decodes a bytestring from a Bech32 encoded string.
func GetSharesDenomFromTokenDenom ¶ added in v1.2.0
GetSharesDenomFromTokenDenom returns the shares denom from the token denom. The returned shares denom will be in the format "{prefix}/{id}/{tokenDenom}".
func GetTokenDenomFromSharesDenom ¶ added in v1.2.0
GetTokenDenomFromSharesDenom returns the token denom from the shares denom. It expects the shares denom to be in the format "{xxxxxx}/{xxxxxx}/{tokenDenom}".
func IsAllGT ¶ added in v1.2.0
IsAllGT returns true if for every denom in coinsB, the denom is present at a greater amount in coins.
func IsAllGTE ¶ added in v1.2.0
IsAllGTE returns false if for any denom in coinsB, the denom is present at a smaller amount in coins; else returns true.
func IsAnyGT ¶ added in v1.2.0
IsAnyGT returns true iff for any denom in coins, the denom is present at a greater amount in coinsB.
e.g. IsAnyGT({2A, 3B}, {A}) = true IsAnyGT({2A, 3B}, {5C}) = false IsAnyGT({}, {5C}) = false IsAnyGT({2A, 3B}, {}) = false
func IsAnyLT ¶ added in v1.2.0
IsAnyLT returns true iff for any denom in coins, the denom is present at a smaller amount in coinsB.
func IsIcs20Packet ¶ added in v1.2.0
func IsIcs20Packet(packetData []byte) (isIcs20 bool, ics20data transfertypes.FungibleTokenPacketData)
IsIcs20Packet checks if the data is a ICS20 packet.
func IsInvalidExRate ¶ added in v1.2.0
IsInvalidExRate returns true if the delegated tokens are zero and the delegators shares are positive.
func IsOutOfGasError ¶
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 IssueShares ¶ added in v1.2.0
func IssueShares(amount sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) sdk.DecCoins
IssueShares calculates the shares to issue for a delegation of the given amount.
func JSONStringHasKey ¶ added in v1.2.0
JSONStringHasKey parses the provided data as a json object and checks if it contains the provided key.
func LogHeader ¶
LogHeader returns a log header string with a dash padding on either side Ex:
------------------------------ string ------------------------------
func LogICACallbackStatusWithHostZone ¶
func LogICACallbackStatusWithHostZone(chainID string, callbackID string, status icacallbacktypes.AckResponseStatus, packet channeltypes.Packet) string
LogICACallbackStatusWithHostZone returns a log string with a chain Id and icacallback as a prefix, and status of the callback Ex:
| COSMOSHUB-4 | DELEGATE ICACALLBACK | ICA SUCCESS, Packet: ...
func LogICACallbackWithHostZone ¶
LogICACallbackWithHostZone returns a log string with a chain Id and icacallback as a prefix Ex:
| COSMOSHUB-4 | DELEGATE ICACALLBACK | string
func LogICQCallbackWithHostZone ¶
LogICQCallbackWithHostZone returns a log string with a chain Id and icqcallback as a prefix Ex:
| COSMOSHUB-4 | WITHDRAWALHOSTBALANCE ICQCALLBACK | string
func LogWithHostZone ¶
LogWithHostZone returns a log string with a chainId and tab as the prefix Ex:
| COSMOSHUB-4 | string
func Map ¶ added in v1.2.0
func Map[T, U any](slice []T, f func(T) U) []U
Map applies the given function to each element in the slice and returns a new slice with the results.
func MapGetOrDefault ¶ added in v1.3.0
func MapGetOrDefault[K, V any]( ctx sdk.Context, collectionMap collections.Map[K, V], key K, defaultValueProvider func() V, ) (V, error)
MapGetOrDefault gets a value from the map with the given key. If the key is not found within the map, the default value is returned.
func MustParseCoin ¶ added in v1.2.0
func MustParseCoins ¶ added in v1.2.0
func MustParseDec ¶ added in v1.2.0
func MustParseDecCoins ¶ added in v1.2.0
func ParseUint32Slice ¶ added in v1.2.0
func PrintPanicRecoveryError ¶
PrintPanicRecoveryError error logs the recoveryError, along with the stacktrace, if it can be parsed. If not emits them to stdout.
func Remove ¶ added in v1.3.0
func Remove[T comparable](slice []T, value T) (newSlice []T, removed bool)
Remove removes the first instance of value from the provided slice.
func RemoveDuplicates ¶ added in v1.2.0
func RemoveDuplicates[T comparable](slice []T) []T
RemoveDuplicates removes all duplicate elements from the slice.
func SharesFromDecCoins ¶ added in v1.2.0
func SharesFromDecCoins(tokens sdk.DecCoins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) (sdk.DecCoins, error)
SharesFromDecCoins returns the shares of a delegation given a bond amount.
func SharesFromTokens ¶ added in v1.2.0
func SharesFromTokens(tokens sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) (sdk.DecCoins, error)
SharesFromTokens returns the shares of a delegation given a bond amount.
func SharesFromTokensTruncated ¶ added in v1.2.0
func SharesFromTokensTruncated(tokens sdk.Coins, getShareDenom ShareDenomGetter, delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) (sdk.DecCoins, error)
SharesFromTokensTruncated returns the truncated shares of a delegation given a bond amount.
func StAssetDenomFromHostZoneDenom ¶
StAssetDenomFromHostZoneDenom returns the stDenom from a native denom by appending a st prefix
func StringMapKeys ¶
func Uint32ToBigEndian ¶ added in v1.2.0
Uint32ToBigEndian marshals uint32 to a bigendian byte slice so it can be sorted
func VerifyAddressFormat ¶
VerifyAddressFormat verifies that the provided bytes form a valid address according to the default address rules or a custom address verifier set by GetConfig().SetAddressVerifier(). TODO make an issue to get rid of global Config ref: https://github.com/cosmos/cosmos-sdk/issues/9690
func VerifyTxHash ¶
VerifyTxHash verifies a tx hash is valid
Types ¶
type AccAddress ¶
type AccAddress []byte
AccAddress a wrapper around bytes meant to represent an account address. When marshaled to a string or JSON, it uses Bech32.
func AccAddressFromBech32 ¶
func AccAddressFromBech32(address string, bech32prefix string) (addr AccAddress, err error)
AccAddressFromBech32 creates an AccAddress from a Bech32 string.
type AccountKeeper ¶
type ShareDenomGetter ¶ added in v1.2.0
ShareDenomGetter represents a function that returns the shares denom given a token denom.