utils

package
v0.0.0-...-4b9ad55 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AttoPowerReduction defines the power reduction for att units (1e18)
	AttoPowerReduction = math.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil))

	// MicroPowerReduction defines the power reduction for micro units (1e6)
	MicroPowerReduction = math.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(6), nil))
)

Functions

func Bech32StringFromHexAddress

func Bech32StringFromHexAddress(hexAddr string) string

Bech32StringFromHexAddress takes a given Hex string and derives a Cosmos SDK account address from it.

func Bech32ToHexAddr

func Bech32ToHexAddr(bech32Addr string) (common.Address, error)

Bech32ToHexAddr converts a given Bech32 address string and converts it to an Ethereum address.

func Bytes32ToString

func Bytes32ToString(data [32]byte) string

Bytes32ToString converts a bytes32 value to string by trimming null bytes

func CosmosToEthAddr

func CosmosToEthAddr(accAddr sdk.AccAddress) common.Address

CosmosToEthAddr converts a given SDK account address to an Ethereum address.

func CreateAccAddressFromBech32

func CreateAccAddressFromBech32(address string, bech32prefix string) (addr sdk.AccAddress, err error)

CreateAccAddressFromBech32 creates an AccAddress from a Bech32 string.

func EthHexToCosmosAddr

func EthHexToCosmosAddr(hexAddr string) sdk.AccAddress

EthHexToCosmosAddr takes a given Hex string and derives a Cosmos SDK account address from it.

func EthToCosmosAddr

func EthToCosmosAddr(addr common.Address) sdk.AccAddress

EthToCosmosAddr converts a given Ethereum style address to an SDK address.

func GetAccAddressFromBech32

func GetAccAddressFromBech32(address string) (sdk.AccAddress, error)

GetAccAddressFromBech32 returns the sdk.Account address of given address, while also changing bech32 human readable prefix (HRP) to the value set on the global sdk.Config (eg: `evmos`).

The function fails if the provided bech32 address is invalid.

func GetIBCDenomAddress

func GetIBCDenomAddress(denom string) (common.Address, error)

GetIBCDenomAddress returns the address from the hash of the ICS20's Denom Path.

func HexAddressFromBech32String

func HexAddressFromBech32String(addr string) (common.Address, error)

HexAddressFromBech32String converts a hex address to a bech32 encoded address.

func IsBech32Address

func IsBech32Address(address string) bool

IsBech32Address checks if the address is a valid bech32 address.

func IsEmptyHash

func IsEmptyHash(hash string) bool

IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash.

func IsSupportedKey

func IsSupportedKey(pubkey cryptotypes.PubKey) bool

IsSupportedKey returns true if the pubkey type is supported by the chain (i.e. eth_secp256k1, amino multisig, ed25519). NOTE: Nested multisigs are not supported.

func IsValidInt256

func IsValidInt256(i *big.Int) bool

IsValidInt256 check the bound of 256 bit number

func IsZeroAddress

func IsZeroAddress(address string) bool

IsZeroAddress returns true if the address corresponds to an empty ethereum hex address.

func SafeHexToInt64

func SafeHexToInt64(value hexutil.Uint64) (int64, error)

SafeHexToInt64 converts a hexutil.Uint64 to int64, returning an error if it exceeds the max int64 value.

func SafeInt64

func SafeInt64(value uint64) (int64, error)

SafeInt64 checks for overflows while casting a uint64 to int64 value.

func SafeNewIntFromBigInt

func SafeNewIntFromBigInt(i *big.Int) (sdkmath.Int, error)

SafeNewIntFromBigInt constructs Int from big.Int, return error if more than 256bits

func SafeUint64

func SafeUint64(value int64) (uint64, error)

SafeUint64 checks for underflows while casting an int64 to uint64 value.

func SortSlice

func SortSlice[T cmp.Ordered](slice []T)

SortSlice sorts a slice of any ordered type.

func Uint256FromBigInt

func Uint256FromBigInt(i *big.Int) (*uint256.Int, error)

func ValidateAddress

func ValidateAddress(address string) error

ValidateAddress returns an error if the provided string is either not a hex formatted string address

func ValidateNonZeroAddress

func ValidateNonZeroAddress(address string) error

ValidateNonZeroAddress returns an error if the provided string is not a hex formatted string address or is equal to zero

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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