types

package
v0.11.9 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
	// AddressLength
	AddressLength = 20
	// AccPublicKeyLength
	AccPublicKeyLength = 33
	// AccPrivateKeyLength
	AccPrivateKeyLength = 32
	// P2pPublicKeyLength
	P2pPublicKeyLength = 32
	// P2pPrivateKeyLength
	P2pPrivateKeyLength = 64

	P2pAddressBech32Length = 44

	P2pSignatureLength = 64
)

Lengths of hashes and addresses in bytes.

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 NetworkIDPrefix = "snode:"

Variables

This section is empty.

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func DefaultCoinDenomRegex added in v0.9.0

func DefaultCoinDenomRegex() string

DefaultCoinDenomRegex returns the default regex string

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func GetBaseDenom added in v0.9.0

func GetBaseDenom() (string, error)

GetBaseDenom returns the denom of smallest unit registered

func GetDenomUnit added in v0.9.0

func GetDenomUnit(denom string) (sdktypes.Dec, bool)

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

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func RegisterDenom added in v0.9.0

func RegisterDenom(denom string, unit sdktypes.Dec) error

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

func SetCoinDenomRegex added in v0.9.0

func SetCoinDenomRegex(reFn func() string)

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

func ValidateDenom added in v0.9.0

func ValidateDenom(denom string) error

ValidateDenom is the default validation function for Coin.Denom.

func VerifyP2pAddrBytes added in v0.9.0

func VerifyP2pAddrBytes(p2pPubkey []byte, p2pAddr string) bool

VerifyP2pAddrBytes verify whether P2P address matches public key

func VerifyP2pSignBytes added in v0.9.0

func VerifyP2pSignBytes(p2pPubkey []byte, signature []byte, message []byte) bool

VerifyP2pSignBytes verify the signature made by P2P key

func VerifyP2pSignString added in v0.10.0

func VerifyP2pSignString(p2pPubkey []byte, signature []byte, message string) bool

VerifyP2pSignString verify the signature made by P2P key

func VerifyWalletAddr added in v0.9.0

func VerifyWalletAddr(walletPubkey, walletAddr string) int

VerifyWalletAddr verify the wallet address and public key match

func VerifyWalletAddrBytes added in v0.9.0

func VerifyWalletAddrBytes(walletPubkey []byte, walletAddr string) int

VerifyWalletAddrBytes []byte version of VerifyWalletKey() for the pubkey format

func VerifyWalletSign added in v0.9.0

func VerifyWalletSign(walletPubkey, signature, message string) bool

VerifyWalletSign verify the signature by wallet key

func VerifyWalletSignBytes added in v0.9.0

func VerifyWalletSignBytes(walletPubkey []byte, signature []byte, message string) bool

VerifyWalletSignBytes []byte version of VerifyWalletKey() for pubkey and signature format

Types

type AccPrivKey added in v0.9.0

type AccPrivKey [AccPrivateKeyLength]byte

AccPrivKey account(wallet) private key

func BytesToAccPriveKey added in v0.9.0

func BytesToAccPriveKey(b []byte) AccPrivKey

BytesToAccPriveKey sets b to PrivKey. If b is larger than len(h), b will be cropped from the left.

func (AccPrivKey) Bytes added in v0.9.0

func (p AccPrivKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (AccPrivKey) PubKeyFromPrivKey added in v0.9.0

func (p AccPrivKey) PubKeyFromPrivKey() AccPubKey

PubKeyFromPrivKey generate a AccPubKey from the AccPrivKey

func (*AccPrivKey) SetBytes added in v0.9.0

func (p *AccPrivKey) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (AccPrivKey) Sign added in v0.9.0

func (p AccPrivKey) Sign(b []byte) ([]byte, error)

Sign secp256k1 sign since account(wallet) uses secp256k1 key pair

type AccPubKey added in v0.9.0

type AccPubKey [AccPublicKeyLength]byte

AccPubKey account(wallet) public key

func BytesToAccPubKey added in v0.9.0

func BytesToAccPubKey(b []byte) AccPubKey

BytesToPubKey sets b to PubKey. If b is larger than len(h), b will be cropped from the left.

func WalletPubkeyFromBech added in v0.9.0

func WalletPubkeyFromBech(str string) (AccPubKey, error)

WalletPubkeyFromBech create an AccPubKey from Bech of wallet pubkey

func (AccPubKey) Address added in v0.9.0

func (p AccPubKey) Address() Address

Address generate a wallet address from account public key

func (AccPubKey) Bytes added in v0.9.0

func (p AccPubKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*AccPubKey) SetBytes added in v0.9.0

func (p *AccPubKey) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (AccPubKey) ToBech added in v0.9.0

func (p AccPubKey) ToBech() (string, error)

type Address

type Address [AddressLength]byte

Address

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func P2pAddressFromBech added in v0.5.0

func P2pAddressFromBech(str string) (Address, error)

func WalletAddressFromBech added in v0.6.0

func WalletAddressFromBech(str string) (Address, error)

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Compare added in v0.9.0

func (a Address) Compare(b Address) int

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) P2pAddressToBech added in v0.8.0

func (a Address) P2pAddressToBech() (string, error)

func (Address) P2pPublicKeyToBech added in v0.9.0

func (a Address) P2pPublicKeyToBech() (string, error)

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (Address) ToBech

func (a Address) ToBech(hrp string) (string, error)

func (Address) WalletAddressToBech added in v0.8.0

func (a Address) WalletAddressToBech() (string, error)

type Coin added in v0.9.0

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

func ConvertCoin added in v0.9.0

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 added in v0.9.0

func NewCoin(denom string, amount sdktypes.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 added in v0.9.0

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 added in v0.9.0

func NormalizeCoin(coin Coin) Coin

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

func ParseCoinNormalized added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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

AddAmount adds an amount to the Coin.

func (Coin) IsEqual added in v0.9.0

func (coin Coin) IsEqual(other Coin) bool

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

func (Coin) IsGTE added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coin Coin) IsNil() bool

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

func (Coin) IsPositive added in v0.9.0

func (coin Coin) IsPositive() bool

IsPositive returns true if coin amount is positive.

TODO: Remove once unsigned integers are used.

func (Coin) IsValid added in v0.9.0

func (coin Coin) IsValid() bool

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

func (Coin) IsZero added in v0.9.0

func (coin Coin) IsZero() bool

IsZero returns if this represents no money

func (Coin) String added in v0.9.0

func (coin Coin) String() string

String provides a human-readable representation of a coin

func (Coin) Sub added in v0.9.0

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 added in v0.9.0

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

SubAmount subtracts an amount from the Coin.

func (Coin) Validate added in v0.9.0

func (coin Coin) Validate() error

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

type Coins added in v0.9.0

type Coins []Coin

Coins is a set of Coin, one per currency

func NewCoins added in v0.9.0

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 added in v0.9.0

func NormalizeCoins(coins []DecCoin) Coins

NormalizeCoins normalize and truncate a list of decimal coins

func ParseCoinsNormalized added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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

AmountOf returns the amount of a denom from coins

func (Coins) AmountOfNoDenomValidation added in v0.9.0

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

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

func (Coins) DenomsSubsetOf added in v0.9.0

func (coins Coins) DenomsSubsetOf(coinsB Coins) bool

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

func (Coins) Empty added in v0.9.0

func (coins Coins) Empty() bool

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

func (Coins) GetDenomByIndex added in v0.9.0

func (coins Coins) GetDenomByIndex(i int) string

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

func (Coins) IsAllGT added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coins Coins) IsEqual(coinsB Coins) bool

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

func (Coins) IsValid added in v0.9.0

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 added in v0.9.0

func (coins Coins) IsZero() bool

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

func (Coins) Len added in v0.9.0

func (coins Coins) Len() int

Len implements sort.Interface for Coins

func (Coins) Less added in v0.9.0

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

Less implements sort.Interface for Coins

func (Coins) MarshalJSON added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coins Coins) Sort() Coins

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

func (Coins) String added in v0.9.0

func (coins Coins) String() string

func (Coins) Sub added in v0.9.0

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 added in v0.9.0

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

Swap implements sort.Interface for Coins

func (Coins) Validate added in v0.9.0

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 added in v0.9.0

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

func ConvertDecCoin added in v0.9.0

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 added in v0.9.0

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

NewDecCoin creates a new DecCoin instance from an Int.

func NewDecCoinFromCoin added in v0.9.0

func NewDecCoinFromCoin(coin Coin) DecCoin

NewDecCoinFromCoin creates a new DecCoin from a Coin.

func NewDecCoinFromDec added in v0.9.0

func NewDecCoinFromDec(denom string, amount sdktypes.Dec) DecCoin

NewDecCoinFromDec creates a new DecCoin instance from a Dec.

func NewInt64DecCoin added in v0.9.0

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 added in v0.9.0

func NormalizeDecCoin(coin DecCoin) DecCoin

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

func ParseDecCoin added in v0.9.0

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 added in v0.9.0

func (coin DecCoin) Add(coinB DecCoin) DecCoin

Add adds amounts of two decimal coins with same denom.

func (DecCoin) IsEqual added in v0.9.0

func (coin DecCoin) IsEqual(other DecCoin) bool

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

func (DecCoin) IsGTE added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coin DecCoin) IsPositive() bool

IsPositive returns true if coin amount is positive.

TODO: Remove once unsigned integers are used.

func (DecCoin) IsValid added in v0.9.0

func (coin DecCoin) IsValid() bool

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

func (DecCoin) IsZero added in v0.9.0

func (coin DecCoin) IsZero() bool

IsZero returns if the DecCoin amount is zero.

func (DecCoin) String added in v0.9.0

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 added in v0.9.0

func (coin DecCoin) Sub(coinB DecCoin) DecCoin

Sub subtracts amounts of two decimal coins with same denom.

func (DecCoin) TruncateDecimal added in v0.9.0

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 added in v0.9.0

func (coin DecCoin) Validate() error

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

type DecCoins added in v0.9.0

type DecCoins []DecCoin

DecCoins defines a slice of coins with decimal values

func NewDecCoins added in v0.9.0

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 added in v0.9.0

func NewDecCoinsFromCoins(coins ...Coin) DecCoins

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

func ParseDecCoins added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coins DecCoins) AmountOf(denom string) sdktypes.Dec

AmountOf returns the amount of a denom from deccoins

func (DecCoins) Empty added in v0.9.0

func (coins DecCoins) Empty() bool

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

func (DecCoins) GetDenomByIndex added in v0.9.0

func (coins DecCoins) GetDenomByIndex(i int) string

GetDenomByIndex returns the Denom to make the findDup generic

func (DecCoins) Intersect added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

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 added in v0.9.0

func (coins DecCoins) IsEqual(coinsB DecCoins) bool

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

func (DecCoins) IsValid added in v0.9.0

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 added in v0.9.0

func (coins DecCoins) IsZero() bool

IsZero returns whether all coins are zero

func (DecCoins) Len added in v0.9.0

func (coins DecCoins) Len() int

Len implements sort.Interface for DecCoins

func (DecCoins) Less added in v0.9.0

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

Less implements sort.Interface for DecCoins

func (DecCoins) MulDec added in v0.9.0

func (coins DecCoins) MulDec(d sdktypes.Dec) DecCoins

MulDec multiplies all the coins by a decimal.

CONTRACT: No zero coins will be returned.

func (DecCoins) MulDecTruncate added in v0.9.0

func (coins DecCoins) MulDecTruncate(d sdktypes.Dec) 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 added in v0.9.0

func (coins DecCoins) QuoDec(d sdktypes.Dec) 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 added in v0.9.0

func (coins DecCoins) QuoDecTruncate(d sdktypes.Dec) 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 added in v0.9.0

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 added in v0.9.0

func (coins DecCoins) Sort() DecCoins

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

func (DecCoins) String added in v0.9.0

func (coins DecCoins) String() string

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

func (DecCoins) Sub added in v0.9.0

func (coins DecCoins) Sub(coinsB DecCoins) DecCoins

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

func (DecCoins) Swap added in v0.9.0

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

Swap implements sort.Interface for DecCoins

func (DecCoins) TruncateDecimal added in v0.9.0

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 added in v0.9.0

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 Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Float64

func (h Hash) Float64() float64

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type NetworkID

type NetworkID struct {
	P2pAddress     string
	NetworkAddress string
}

func IDFromString

func IDFromString(idString string) (*NetworkID, error)

func (NetworkID) String

func (n NetworkID) String() string

type P2pPrivKey added in v0.9.0

type P2pPrivKey [P2pPrivateKeyLength]byte

P2pPrivKey P2P address private key

func BytesToP2pPrivKey added in v0.9.0

func BytesToP2pPrivKey(b []byte) P2pPrivKey

BytesToAccPriveKey sets b to P2pPrivKey. If b is larger than len(h), b will be cropped from the left.

func (P2pPrivKey) Address added in v0.10.0

func (p P2pPrivKey) Address() Address

Address generate an Address from a P2pPrivKey

func (P2pPrivKey) Bytes added in v0.9.0

func (p P2pPrivKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (P2pPrivKey) PubKey added in v0.9.0

func (p P2pPrivKey) PubKey() P2pPubKey

PubKey generate a P2pPubKey from a P2pPrivKey

func (*P2pPrivKey) SetBytes added in v0.9.0

func (p *P2pPrivKey) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (P2pPrivKey) Sign added in v0.9.0

func (p P2pPrivKey) Sign(b []byte) []byte

Sign p2p address uses ed25519 algo

type P2pPubKey added in v0.9.0

type P2pPubKey [P2pPublicKeyLength]byte

P2pPubKey P2P address public key

func BytesToP2pPubKey added in v0.9.0

func BytesToP2pPubKey(b []byte) P2pPubKey

BytesToP2pPubKey sets b to P2pPubKey If b is larger than len(h), b will be cropped from the left.

func P2pPubKeyFromBech added in v0.10.0

func P2pPubKeyFromBech(str string) (P2pPubKey, error)

P2pPubKeyFromBech create a P2pPubKey from a Bech-encoded P2P public key

func (P2pPubKey) Address added in v0.9.0

func (p P2pPubKey) Address() Address

Address generate a P2P address from P2P public key

func (P2pPubKey) Bytes added in v0.9.0

func (p P2pPubKey) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (*P2pPubKey) SetBytes added in v0.9.0

func (p *P2pPubKey) SetBytes(b []byte)

SetBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (P2pPubKey) ToBech added in v0.9.0

func (p P2pPubKey) ToBech() (string, error)

ToBech the Bech format string

type TxFee added in v0.9.0

type TxFee struct {
	Fee      Coin
	Gas      uint64
	Simulate bool
}

Jump to

Keyboard shortcuts

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