utils

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompositeKey

func CompositeKey(parts ...[]byte) []byte

func ComputeTokensFromShares

func ComputeTokensFromShares(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins

ComputeTokensFromShares calculates the token worth of provided shares.

func ComputeTokensFromSharesTruncated

func ComputeTokensFromSharesTruncated(shares sdk.DecCoins, delegatedTokens sdk.Coins, delegatorShares sdk.DecCoins) sdk.DecCoins

ComputeTokensFromSharesTruncated calculates the token worth of provided shares, truncated.

func DenomsSubsetOf

func DenomsSubsetOf(coins sdk.DecCoins, coinsB sdk.DecCoins) bool

DenomsSubsetOf returns true if receiver's denom set is subset of coinsB's denoms.

func DeserializeFungibleTokenPacketData

func DeserializeFungibleTokenPacketData(packetData []byte) (ics20data transfertypes.FungibleTokenPacketData, isIcs20 bool)

DeserializeFungibleTokenPacketData deserializes the packet data and returns the FungibleTokenPacketData

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

Filter returns the elements of the slice that satisfy the given predicate.

func FilterCoinsByDenom

func FilterCoinsByDenom(coins, coinsB sdk.Coins) sdk.Coins

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

func FilterDecCoinsByDenom(coins, coinsB sdk.DecCoins) sdk.DecCoins

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 Find

func Find[T any](slice []T, searchFunction func(T) bool) (*T, bool)

Find returns the first element in the slice that satisfies the given predicate, or false if none is found.

func FindDuplicate

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

func FindDuplicateFunc[T any](slice []T, compare func(a T, b T) bool) *T

FindDuplicateFunc returns the first duplicate element in the slice. If no duplicates are found, it returns nil instead.

func GetSharesDenomFromTokenDenom

func GetSharesDenomFromTokenDenom(prefix string, id uint32, tokenDenom string) string

GetSharesDenomFromTokenDenom returns the shares denom from the token denom. The returned shares denom will be in the format "{prefix}/{id}/{tokenDenom}".

func GetTokenDenomFromSharesDenom

func GetTokenDenomFromSharesDenom(sharesDenom string) string

GetTokenDenomFromSharesDenom returns the token denom from the shares denom. It expects the shares denom to be in the format "{xxxxxx}/{xxxxxx}/{tokenDenom}".

func Intersect

func Intersect[T comparable](a, b []T) []T

Intersect returns the intersection of two slices.

func IsAllGT

func IsAllGT(coins, coinsB sdk.DecCoins) bool

IsAllGT returns true if for every denom in coinsB, the denom is present at a greater amount in coins.

func IsAllGTE

func IsAllGTE(coins, coinsB sdk.DecCoins) bool

IsAllGTE returns false if for any denom in coinsB, the denom is present at a smaller amount in coins; else returns true.

func IsAnyGT

func IsAnyGT(coins, coinsB sdk.DecCoins) bool

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

func IsAnyLT(coins, coinsB sdk.DecCoins) bool

IsAnyLT returns true iff for any denom in coins, the denom is present at a smaller amount in coinsB.

func IsInvalidExRate

func IsInvalidExRate(delegatedTokens sdk.Coins, delegatorsShares sdk.DecCoins) bool

IsInvalidExRate returns true if the delegated tokens are zero and the delegators shares are positive.

func IsKeySetEmpty

func IsKeySetEmpty[K any](ctx sdk.Context, collectionMap collections.KeySet[K], ranger collections.Ranger[K]) (bool, error)

IsKeySetEmpty checks if the given key set with the given ranger is empty.

func IsMapEmpty

func IsMapEmpty[K, V any](ctx sdk.Context, collectionMap collections.Map[K, V], ranger collections.Ranger[K]) (bool, error)

IsMapEmpty checks if the given map with the given ranger is empty.

func IssueShares

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

func JSONStringHasKey(data, key string) (found bool, jsonObject map[string]interface{})

JSONStringHasKey parses the provided data as a json object and checks if it contains the provided key.

func Map

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

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

func MustParseCoin(s string) sdk.Coin

func MustParseCoins

func MustParseCoins(s string) sdk.Coins

func MustParseDec

func MustParseDec(s string) sdkmath.LegacyDec

func MustParseDecCoins

func MustParseDecCoins(s string) sdk.DecCoins

func Remove

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

func RemoveDuplicates[T comparable](slice []T) []T

RemoveDuplicates removes all duplicate elements from the slice.

func SharesFromDecCoins

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

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

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 Uint32ToBigEndian

func Uint32ToBigEndian(i uint32) []byte

Uint32ToBigEndian marshals uint32 to a bigendian byte slice so it can be sorted

Types

type ShareDenomGetter

type ShareDenomGetter func(tokenDenom string) (shareDenom string)

ShareDenomGetter represents a function that returns the shares denom given a token denom.

Jump to

Keyboard shortcuts

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