types

package
v5.0.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ZeroInt     = sdk.ZeroInt()
	ZeroDec     = sdk.ZeroDec()
	OneInt      = sdk.OneInt()
	OneDec      = sdk.OneDec()
	SmallestDec = sdk.SmallestDec()
)

Functions

func BigEndianToUint32

func BigEndianToUint32(bz []byte) uint32

func DateRangeIncludes

func DateRangeIncludes(startTime, endTime, targetTime time.Time) bool

DateRangeIncludes returns true if the target date included on the start, end time range. End time is exclusive and start time is inclusive.

func DateRangesOverlap

func DateRangesOverlap(startTimeA, endTimeA, startTimeB, endTimeB time.Time) bool

DateRangesOverlap returns true if two date ranges overlap each other. End time is exclusive and start time is inclusive.

func DecApproxEqual

func DecApproxEqual(a, b sdk.Dec) bool

DecApproxEqual returns true if a and b are approximately equal, which means the diff ratio is equal or less than 0.1%.

func DecApproxSqrt

func DecApproxSqrt(x sdk.Dec) sdk.Dec

DecApproxSqrt returns an approximate estimation of x's square root.

func DivMod

func DivMod[T constraints.Integer](x, y T) (q, r T)

func Filter

func Filter[E any](s []E, f func(E) bool) []E

func GenAndDeliverTx

GenAndDeliverTx generates a transactions and delivers it.

func GenAndDeliverTxWithFees

func GenAndDeliverTxWithFees(txCtx simulation.OperationInput, gas uint64, fees sdk.Coins) (simtypes.OperationMsg, []simtypes.FutureOperation, error)

GenAndDeliverTxWithFees generates a transaction with given fee and delivers it.

func GetShareValue

func GetShareValue(amount sdk.Int, ratio sdk.Dec) sdk.Int

GetShareValue multiplies with truncation by receiving int amount and decimal ratio and returns int result.

func IsOverflow

func IsOverflow(r interface{}) bool

IsOverflow returns true if the panic value can be interpreted as an overflow.

func Key

func Key(comps ...[]byte) []byte

func LengthPrefixString

func LengthPrefixString(s string) []byte

LengthPrefixString returns length-prefixed bytes representation of a string.

func MinInt

func MinInt(a, b sdk.Int) sdk.Int

MinInt works like sdk.MinInt, but without allocations.

func PP

func PP(data interface{})

func ParseCoin

func ParseCoin(s string) sdk.Coin

ParseCoin parses and returns sdk.Coin.

func ParseCoins

func ParseCoins(s string) sdk.Coins

ParseCoins parses and returns sdk.Coins.

func ParseDec

func ParseDec(s string) sdk.Dec

ParseDec is a shortcut for sdk.MustNewDecFromStr.

func ParseDecCoin

func ParseDecCoin(s string) sdk.DecCoin

ParseDecCoin parses and returns sdk.DecCoin.

func ParseDecCoins

func ParseDecCoins(s string) sdk.DecCoins

ParseDecCoins parses and returns sdk.DecCoins.

func ParseDecP

func ParseDecP(s string) *sdk.Dec

ParseDecP is like ParseDec, but it returns a pointer to sdk.Dec.

func ParseInt

func ParseInt(s string) sdk.Int

ParseInt parses and returns sdk.Int from string.

func ParseTime

func ParseTime(s string) time.Time

ParseTime parses and returns time.Time in time.RFC3339 format.

func RandomDec

func RandomDec(r *rand.Rand, min, max sdk.Dec) sdk.Dec

RandomDec returns a random decimal in the half-open interval [min, max).

func RandomInt

func RandomInt(r *rand.Rand, min, max sdk.Int) sdk.Int

RandomInt returns a random integer in the half-open interval [min, max).

func SafeMath

func SafeMath(f, onOverflow func())

SafeMath runs f in safe mode, which means that any panics occurred inside f gets caught by recover() and if the panic was an overflow, onOverflow is run. Otherwise, if the panic was not an overflow, then SafeMath will re-throw the panic.

func Shuffle

func Shuffle[E any](r *rand.Rand, s []E)

func ShuffleSimAccounts

func ShuffleSimAccounts(r *rand.Rand, accs []simtypes.Account) []simtypes.Account

ShuffleSimAccounts returns randomly shuffled simulation accounts.

func TestAddress

func TestAddress(addrNum int) sdk.AccAddress

TestAddress returns an address for testing purpose. TestAddress returns same address when addrNum is same.

func Uint32ToBigEndian

func Uint32ToBigEndian(i uint32) []byte

Types

type StrIntMap

type StrIntMap map[string]sdk.Int

func (StrIntMap) AddOrSet

func (m StrIntMap) AddOrSet(key string, value sdk.Int)

AddOrSet Set when the key not existed on the map or add existed value of the key.

Jump to

Keyboard shortcuts

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