types

package
v0.0.0-...-7657fe4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Stos = "stos"
	Gwei = "gwei"
	Wei  = "wei"
	// WeiDenomUnit defines the base denomination unit for stos.
	// 1 stos = 1x10^{WeiDenomUnit} wei
	WeiDenomUnit  = 18
	GweiDenomUnit = 9
)
View Source
const (
	SignatureSecp256k1 = 0
	SignatureEd25519   = 1
)

Variables

This section is empty.

Functions

func DefaultCoinDenomRegex

func DefaultCoinDenomRegex() string

DefaultCoinDenomRegex returns the default regex string

func GetBaseDenom

func GetBaseDenom() (string, error)

GetBaseDenom returns the denom of smallest unit registered

func GetDenomUnit

func GetDenomUnit(denom string) (sdkmath.LegacyDec, bool)

GetDenomUnit returns a unit for a given denomination if it exists. A boolean is returned if the denomination is registered.

func RegisterDenom

func RegisterDenom(denom string, unit sdkmath.LegacyDec) error

RegisterDenom registers a denomination with a corresponding unit. If the denomination is already registered, an error will be returned.

func SetCoinDenomRegex

func SetCoinDenomRegex(reFn func() string)

SetCoinDenomRegex allows for coin's custom validation by overriding the regular expression string used for denom validation.

func ValidateDenom

func ValidateDenom(denom string) error

ValidateDenom is the default validation function for Coin.Denom.

Types

type Coin

type Coin struct {
	Denom  string      `json:"denom,omitempty"`
	Amount sdkmath.Int `json:"amount"`
}

func ConvertCoin

func ConvertCoin(coin Coin, denom string) (Coin, error)

ConvertCoin attempts to convert a coin to a given denomination. If the given denomination is invalid or if neither denomination is registered, an error is returned.

func NewCoin

func NewCoin(denom string, amount sdkmath.Int) Coin

NewCoin returns a new coin with a denomination and amount. It will panic if the amount is negative or if the denomination is invalid.

func NewInt64Coin

func NewInt64Coin(denom string, amount int64) Coin

NewInt64Coin returns a new coin with a denomination and amount. It will panic if the amount is negative.

func NormalizeCoin

func NormalizeCoin(coin Coin) Coin

NormalizeCoin try to convert a coin to the smallest unit registered, returns original one if failed.

func ParseCoinNormalized

func ParseCoinNormalized(coinStr string) (coin Coin, err error)

ParseCoinNormalized parses and normalize a cli input for one coin type, returning errors if invalid or on an empty string as well. Expected format: "{amount}{denomination}"

func (Coin) Add

func (coin Coin) Add(coinB Coin) Coin

Add adds amounts of two coins with same denom. If the coins differ in denom then it panics.

func (Coin) AddAmount

func (coin Coin) AddAmount(amount sdkmath.Int) Coin

AddAmount adds an amount to the Coin.

func (Coin) IsEqual

func (coin Coin) IsEqual(other Coin) bool

IsEqual returns true if the two sets of Coins have the same value

func (Coin) IsGTE

func (coin Coin) IsGTE(other Coin) bool

IsGTE returns true if they are the same type and the receiver is an equal or greater value

func (Coin) IsLT

func (coin Coin) IsLT(other Coin) bool

IsLT returns true if they are the same type and the receiver is a smaller value

func (Coin) IsNegative

func (coin Coin) IsNegative() bool

IsNegative returns true if the coin amount is negative and false otherwise.

TODO: Remove once unsigned integers are used.

func (Coin) IsNil

func (coin Coin) IsNil() bool

IsNil returns true if the coin amount is nil and false otherwise.

func (Coin) IsPositive

func (coin Coin) IsPositive() bool

IsPositive returns true if coin amount is positive.

TODO: Remove once unsigned integers are used.

func (Coin) IsValid

func (coin Coin) IsValid() bool

IsValid returns true if the Coin has a non-negative amount and the denom is valid.

func (Coin) IsZero

func (coin Coin) IsZero() bool

IsZero returns if this represents no money

func (Coin) String

func (coin Coin) String() string

String provides a human-readable representation of a coin

func (Coin) Sub

func (coin Coin) Sub(coinB Coin) Coin

Sub subtracts amounts of two coins with same denom. If the coins differ in denom then it panics.

func (Coin) SubAmount

func (coin Coin) SubAmount(amount sdkmath.Int) Coin

SubAmount subtracts an amount from the Coin.

func (Coin) Validate

func (coin Coin) Validate() error

Validate returns an error if the Coin has a negative amount or if the denom is invalid.

type Coins

type Coins []Coin

Coins is a set of Coin, one per currency

func NewCoins

func NewCoins(coins ...Coin) Coins

NewCoins constructs a new coin set. The provided coins will be sanitized by removing zero coins and sorting the coin set. A panic will occur if the coin set is not valid.

func NormalizeCoins

func NormalizeCoins(coins []DecCoin) Coins

NormalizeCoins normalize and truncate a list of decimal coins

func ParseCoinsNormalized

func ParseCoinsNormalized(coinStr string) (Coins, error)

ParseCoinsNormalized will parse out a list of coins separated by commas, and normalize them by converting to the smallest unit. If the parsing is successful, the provided coins will be sanitized by removing zero coins and sorting the coin set. Lastly a validation of the coin set is executed. If the check passes, ParseCoinsNormalized will return the sanitized coins. Otherwise, it will return an error. If an empty string is provided to ParseCoinsNormalized, it returns nil Coins. ParseCoinsNormalized supports decimal coins as inputs, and truncate them to int after converted to the smallest unit. Expected format: "{amount0}{denomination},...,{amountN}{denominationN}"

func (Coins) Add

func (coins Coins) Add(coinsB ...Coin) Coins

Add adds two sets of coins.

e.g. {2A} + {A, 2B} = {3A, 2B} {2A} + {0B} = {2A}

NOTE: Add operates under the invariant that coins are sorted by denominations.

CONTRACT: Add will never return Coins where one Coin has a non-positive amount. In otherwords, IsValid will always return true. The function panics if `coins` or `coinsB` are not sorted (ascending).

func (Coins) AmountOf

func (coins Coins) AmountOf(denom string) sdkmath.Int

AmountOf returns the amount of a denom from coins

func (Coins) AmountOfNoDenomValidation

func (coins Coins) AmountOfNoDenomValidation(denom string) sdkmath.Int

AmountOfNoDenomValidation returns the amount of a denom from coins without validating the denomination.

func (Coins) DenomsSubsetOf

func (coins Coins) DenomsSubsetOf(coinsB Coins) bool

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

func (Coins) Empty

func (coins Coins) Empty() bool

Empty returns true if there are no coins and false otherwise.

func (Coins) GetDenomByIndex

func (coins Coins) GetDenomByIndex(i int) string

GetDenomByIndex returns the Denom of the certain coin to make the findDup generic

func (Coins) IsAllGT

func (coins Coins) IsAllGT(coinsB Coins) bool

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

func (Coins) IsAllGTE

func (coins Coins) IsAllGTE(coinsB Coins) bool

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

func (Coins) IsAllLT

func (coins Coins) IsAllLT(coinsB Coins) bool

IsAllLT returns True iff for every denom in coins, the denom is present at a smaller amount in coinsB.

func (Coins) IsAllLTE

func (coins Coins) IsAllLTE(coinsB Coins) bool

IsAllLTE returns true iff for every denom in coins, the denom is present at a smaller or equal amount in coinsB.

func (Coins) IsAllPositive

func (coins Coins) IsAllPositive() bool

IsAllPositive returns true if there is at least one coin and all currencies have a positive value.

func (Coins) IsAnyGT

func (coins Coins) IsAnyGT(coinsB Coins) bool

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

e.g. {2A, 3B}.IsAnyGT{A} = true {2A, 3B}.IsAnyGT{5C} = false {}.IsAnyGT{5C} = false {2A, 3B}.IsAnyGT{} = false

func (Coins) IsAnyGTE

func (coins Coins) IsAnyGTE(coinsB Coins) bool

IsAnyGTE returns true iff coins contains at least one denom that is present at a greater or equal amount in coinsB; it returns false otherwise.

NOTE: IsAnyGTE operates under the invariant that both coin sets are sorted by denominations and there exists no zero coins.

func (Coins) IsAnyNegative

func (coins Coins) IsAnyNegative() bool

IsAnyNegative returns true if there is at least one coin whose amount is negative; returns false otherwise. It returns false if the coin set is empty too.

TODO: Remove once unsigned integers are used.

func (Coins) IsAnyNil

func (coins Coins) IsAnyNil() bool

IsAnyNil returns true if there is at least one coin whose amount is nil; returns false otherwise. It returns false if the coin set is empty too.

func (Coins) IsEqual

func (coins Coins) IsEqual(coinsB Coins) bool

IsEqual returns true if the two sets of Coins have the same value

func (Coins) IsValid

func (coins Coins) IsValid() bool

IsValid calls Validate and returns true when the Coins are sorted, have positive amount, with a valid and unique denomination (i.e no duplicates).

func (Coins) IsZero

func (coins Coins) IsZero() bool

IsZero returns true if there are no coins or all coins are zero.

func (Coins) Len

func (coins Coins) Len() int

Len implements sort.Interface for Coins

func (Coins) Less

func (coins Coins) Less(i, j int) bool

Less implements sort.Interface for Coins

func (Coins) MarshalJSON

func (coins Coins) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom JSON marshaller for the Coins type to allow nil Coins to be encoded as an empty array.

func (Coins) Max

func (coins Coins) Max(coinsB Coins) Coins

Max takes two valid Coins inputs and returns a valid Coins result where for every denom D, AmountOf(D) of the result is the maximum of AmountOf(D) of the inputs. Note that the result might be not be equal to either input. For any valid Coins a, b, and c, the following are always true:

a.IsAllLTE(a.Max(b))
b.IsAllLTE(a.Max(b))
a.IsAllLTE(c) && b.IsAllLTE(c) == a.Max(b).IsAllLTE(c)
a.Add(b...).IsEqual(a.Min(b).Add(a.Max(b)...))

E.g. {1A, 3B, 2C}.Max({4A, 2B, 2C} == {4A, 3B, 2C}) {2A, 3B}.Max({1B, 4C}) == {2A, 3B, 4C} {1A, 2B}.Max({}) == {1A, 2B}

func (Coins) Min

func (coins Coins) Min(coinsB Coins) Coins

Min takes two valid Coins inputs and returns a valid Coins result where for every denom D, AmountOf(D) of the result is the minimum of AmountOf(D) of the inputs. Note that the result might be not be equal to either input. For any valid Coins a, b, and c, the following are always true:

a.Min(b).IsAllLTE(a)
a.Min(b).IsAllLTE(b)
c.IsAllLTE(a) && c.IsAllLTE(b) == c.IsAllLTE(a.Min(b))
a.Add(b...).IsEqual(a.Min(b).Add(a.Max(b)...))

E.g. {1A, 3B, 2C}.Min({4A, 2B, 2C} == {1A, 2B, 2C}) {2A, 3B}.Min({1B, 4C}) == {1B} {1A, 2B}.Min({3C}) == empty

See also DecCoins.Intersect().

func (Coins) SafeSub

func (coins Coins) SafeSub(coinsB Coins) (Coins, bool)

SafeSub performs the same arithmetic as Sub but returns a boolean if any negative coin amount was returned. The function panics if `coins` or `coinsB` are not sorted (ascending).

func (Coins) Sort

func (coins Coins) Sort() Coins

Sort is a helper function to sort the set of coins in-place

func (Coins) String

func (coins Coins) String() string

func (Coins) Sub

func (coins Coins) Sub(coinsB Coins) Coins

Sub subtracts a set of coins from another.

e.g. {2A, 3B} - {A} = {A, 3B} {2A} - {0B} = {2A} {A, B} - {A} = {B}

CONTRACT: Sub will never return Coins where one Coin has a non-positive amount. In otherwords, IsValid will always return true.

func (Coins) Swap

func (coins Coins) Swap(i, j int)

Swap implements sort.Interface for Coins

func (Coins) Validate

func (coins Coins) Validate() error

Validate checks that the Coins are sorted, have positive amount, with a valid and unique denomination (i.e no duplicates). Otherwise, it returns an error.

type DecCoin

type DecCoin struct {
	Denom  string            `json:"denom,omitempty"`
	Amount sdkmath.LegacyDec `json:"amount"`
}

func ConvertDecCoin

func ConvertDecCoin(coin DecCoin, denom string) (DecCoin, error)

ConvertDecCoin attempts to convert a decimal coin to a given denomination. If the given denomination is invalid or if neither denomination is registered, an error is returned.

func NewDecCoin

func NewDecCoin(denom string, amount sdkmath.Int) DecCoin

NewDecCoin creates a new DecCoin instance from an Int.

func NewDecCoinFromCoin

func NewDecCoinFromCoin(coin Coin) DecCoin

NewDecCoinFromCoin creates a new DecCoin from a Coin.

func NewDecCoinFromDec

func NewDecCoinFromDec(denom string, amount sdkmath.LegacyDec) DecCoin

NewDecCoinFromDec creates a new DecCoin instance from a Dec.

func NewInt64DecCoin

func NewInt64DecCoin(denom string, amount int64) DecCoin

NewInt64DecCoin returns a new DecCoin with a denomination and amount. It will panic if the amount is negative or denom is invalid.

func NormalizeDecCoin

func NormalizeDecCoin(coin DecCoin) DecCoin

NormalizeDecCoin try to convert a decimal coin to the smallest unit registered, returns original one if failed.

func ParseDecCoin

func ParseDecCoin(coinStr string) (coin DecCoin, err error)

ParseDecCoin parses a decimal coin from a string, returning an error if invalid. An empty string is considered invalid.

func (DecCoin) Add

func (coin DecCoin) Add(coinB DecCoin) DecCoin

Add adds amounts of two decimal coins with same denom.

func (DecCoin) IsEqual

func (coin DecCoin) IsEqual(other DecCoin) bool

IsEqual returns true if the two sets of Coins have the same value.

func (DecCoin) IsGTE

func (coin DecCoin) IsGTE(other DecCoin) bool

IsGTE returns true if they are the same type and the receiver is an equal or greater value.

func (DecCoin) IsLT

func (coin DecCoin) IsLT(other DecCoin) bool

IsLT returns true if they are the same type and the receiver is a smaller value.

func (DecCoin) IsNegative

func (coin DecCoin) IsNegative() bool

IsNegative returns true if the coin amount is negative and false otherwise.

TODO: Remove once unsigned integers are used.

func (DecCoin) IsPositive

func (coin DecCoin) IsPositive() bool

IsPositive returns true if coin amount is positive.

TODO: Remove once unsigned integers are used.

func (DecCoin) IsValid

func (coin DecCoin) IsValid() bool

IsValid returns true if the DecCoin has a non-negative amount and the denom is valid.

func (DecCoin) IsZero

func (coin DecCoin) IsZero() bool

IsZero returns if the DecCoin amount is zero.

func (DecCoin) String

func (coin DecCoin) String() string

String implements the Stringer interface for DecCoin. It returns a human-readable representation of a decimal coin.

func (DecCoin) Sub

func (coin DecCoin) Sub(coinB DecCoin) DecCoin

Sub subtracts amounts of two decimal coins with same denom.

func (DecCoin) TruncateDecimal

func (coin DecCoin) TruncateDecimal() (Coin, DecCoin)

TruncateDecimal returns a Coin with a truncated decimal and a DecCoin for the change. Note, the change may be zero.

func (DecCoin) Validate

func (coin DecCoin) Validate() error

Validate returns an error if the DecCoin has a negative amount or if the denom is invalid.

type DecCoins

type DecCoins []DecCoin

DecCoins defines a slice of coins with decimal values

func NewDecCoins

func NewDecCoins(decCoins ...DecCoin) DecCoins

NewDecCoins constructs a new coin set with with decimal values from DecCoins. The provided coins will be sanitized by removing zero coins and sorting the coin set. A panic will occur if the coin set is not valid.

func NewDecCoinsFromCoins

func NewDecCoinsFromCoins(coins ...Coin) DecCoins

NewDecCoinsFromCoins constructs a new coin set with decimal values from regular Coins.

func ParseDecCoins

func ParseDecCoins(coinsStr string) (DecCoins, error)

ParseDecCoins will parse out a list of decimal coins separated by commas. If the parsing is successuful, the provided coins will be sanitized by removing zero coins and sorting the coin set. Lastly a validation of the coin set is executed. If the check passes, ParseDecCoins will return the sanitized coins. Otherwise it will return an error. If an empty string is provided to ParseDecCoins, it returns nil Coins. Expected format: "{amount0}{denomination},...,{amountN}{denominationN}"

func (DecCoins) Add

func (coins DecCoins) Add(coinsB ...DecCoin) DecCoins

Add adds two sets of DecCoins.

NOTE: Add operates under the invariant that coins are sorted by denominations.

CONTRACT: Add will never return Coins where one Coin has a non-positive amount. In otherwords, IsValid will always return true.

func (DecCoins) AmountOf

func (coins DecCoins) AmountOf(denom string) sdkmath.LegacyDec

AmountOf returns the amount of a denom from deccoins

func (DecCoins) Empty

func (coins DecCoins) Empty() bool

Empty returns true if there are no coins and false otherwise.

func (DecCoins) GetDenomByIndex

func (coins DecCoins) GetDenomByIndex(i int) string

GetDenomByIndex returns the Denom to make the findDup generic

func (DecCoins) Intersect

func (coins DecCoins) Intersect(coinsB DecCoins) DecCoins

Intersect will return a new set of coins which contains the minimum DecCoin for common denoms found in both `coins` and `coinsB`. For denoms not common to both `coins` and `coinsB` the minimum is considered to be 0, thus they are not added to the final set. In other words, trim any denom amount from coin which exceeds that of coinB, such that (coin.Intersect(coinB)).IsLTE(coinB). See also Coins.Min().

func (DecCoins) IsAllPositive

func (coins DecCoins) IsAllPositive() bool

IsAllPositive returns true if there is at least one coin and all currencies have a positive value.

TODO: Remove once unsigned integers are used.

func (DecCoins) IsAnyNegative

func (coins DecCoins) IsAnyNegative() bool

IsAnyNegative returns true if there is at least one coin whose amount is negative; returns false otherwise. It returns false if the DecCoins set is empty too.

TODO: Remove once unsigned integers are used.

func (DecCoins) IsEqual

func (coins DecCoins) IsEqual(coinsB DecCoins) bool

IsEqual returns true if the two sets of DecCoins have the same value.

func (DecCoins) IsValid

func (coins DecCoins) IsValid() bool

IsValid calls Validate and returns true when the DecCoins are sorted, have positive amount, with a valid and unique denomination (i.e no duplicates).

func (DecCoins) IsZero

func (coins DecCoins) IsZero() bool

IsZero returns whether all coins are zero

func (DecCoins) Len

func (coins DecCoins) Len() int

Len implements sort.Interface for DecCoins

func (DecCoins) Less

func (coins DecCoins) Less(i, j int) bool

Less implements sort.Interface for DecCoins

func (DecCoins) MulDec

func (coins DecCoins) MulDec(d sdkmath.LegacyDec) DecCoins

MulDec multiplies all the coins by a decimal.

CONTRACT: No zero coins will be returned.

func (DecCoins) MulDecTruncate

func (coins DecCoins) MulDecTruncate(d sdkmath.LegacyDec) DecCoins

MulDecTruncate multiplies all the decimal coins by a decimal, truncating. It panics if d is zero.

CONTRACT: No zero coins will be returned.

func (DecCoins) QuoDec

func (coins DecCoins) QuoDec(d sdkmath.LegacyDec) DecCoins

QuoDec divides all the decimal coins by a decimal. It panics if d is zero.

CONTRACT: No zero coins will be returned.

func (DecCoins) QuoDecTruncate

func (coins DecCoins) QuoDecTruncate(d sdkmath.LegacyDec) DecCoins

QuoDecTruncate divides all the decimal coins by a decimal, truncating. It panics if d is zero.

CONTRACT: No zero coins will be returned.

func (DecCoins) SafeSub

func (coins DecCoins) SafeSub(coinsB DecCoins) (DecCoins, bool)

SafeSub performs the same arithmetic as Sub but returns a boolean if any negative coin amount was returned.

func (DecCoins) Sort

func (coins DecCoins) Sort() DecCoins

Sort is a helper function to sort the set of decimal coins in-place.

func (DecCoins) String

func (coins DecCoins) String() string

String implements the Stringer interface for DecCoins. It returns a human-readable representation of decimal coins.

func (DecCoins) Sub

func (coins DecCoins) Sub(coinsB DecCoins) DecCoins

Sub subtracts a set of DecCoins from another (adds the inverse).

func (DecCoins) Swap

func (coins DecCoins) Swap(i, j int)

Swap implements sort.Interface for DecCoins

func (DecCoins) TruncateDecimal

func (coins DecCoins) TruncateDecimal() (truncatedCoins Coins, changeCoins DecCoins)

TruncateDecimal returns the coins with truncated decimals and returns the change. Note, it will not return any zero-amount coins in either the truncated or change coins.

func (DecCoins) Validate

func (coins DecCoins) Validate() error

Validate checks that the DecCoins are sorted, have positive amount, with a valid and unique denomination (i.e no duplicates). Otherwise, it returns an error.

type ResourceNodeState

type ResourceNodeState struct {
	IsActive  uint32
	Suspended bool
	Tokens    *big.Int
}

type SignatureKey

type SignatureKey struct {
	AccountNum      uint64 `json:"account_num,omitempty"`
	AccountSequence uint64 `json:"account_sequence,omitempty"`
	Address         string `json:"address,omitempty"`
	PrivateKey      []byte `json:"private_key,omitempty"`
	Type            int    `json:"type,omitempty"`
}

SignatureKey --------------------------------------

type Traffic

type Traffic struct {
	Volume        uint64
	WalletAddress string
}

type TxFee

type TxFee struct {
	Fee      Coin
	Gas      uint64
	Simulate bool
}

type UnsignedMsg

type UnsignedMsg struct {
	Msg           *anypb.Any      `json:"msg,omitempty"`
	SignatureKeys []*SignatureKey `json:"signature_keys,omitempty"`
	Type          string          `json:"type,omitempty"`
}

UnsignedMsg ---------------------------------------

func (*UnsignedMsg) ToBytes

func (u *UnsignedMsg) ToBytes() (*UnsignedMsgBytes, error)

type UnsignedMsgBytes

type UnsignedMsgBytes struct {
	Msg           []byte          `json:"msg,omitempty"`
	SignatureKeys []*SignatureKey `json:"signature_keys,omitempty"`
	Type          string          `json:"type,omitempty"`
}

UnsignedMsgBytes ----------------------------------

func (*UnsignedMsgBytes) FromBytes

func (u *UnsignedMsgBytes) FromBytes() (*UnsignedMsg, error)

type UnsignedMsgs

type UnsignedMsgs struct {
	Msgs []*UnsignedMsgBytes `json:"msgs,omitempty"`
}

UnsignedMsgs --------------------------------------

Directories

Path Synopsis
auth
tx
tx

Jump to

Keyboard shortcuts

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