cosmos

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// 0.01
	GasPriceLow = "0.01"
	// 0.025
	GasPriceAverage = "0.025"
	// 0.04
	GasPriceHigh = "0.04"

	// 100000
	GasLimitDefault = "100000"

	// 118
	CosmosCointype = 118
	// cosmos
	CosmosPrefix = "cosmos"
	// uatom
	CosmosAtomDenom = "uatom"

	// 330
	TerraCointype = 330
	// terra
	TerraPrefix = "terra"
	// uluna
	TerraLunaDenom = "uluna"
	// uusd
	TerraUSTDenom = "uusd"

	// 10
	TerraGasPrice = "10"
	// 0.25
	TerraGasPriceUST = "0.25"
	// 80000
	TerraGasLimitDefault = "80000"
)

Variables

View Source
var (
	CosmosAtom = &KnownTokenInfo{
		Cointype: 118,
		Prefix:   "cosmos",
		Denom:    "uatom",
		GasPrice: &GradedGasPrice{
			Low:     "0.01",
			Average: "0.025",
			High:    "0.04",
		},
		GasLimit: "100000",
	}
	TerraLunc = &KnownTokenInfo{
		Cointype: 330,
		Prefix:   "terra",
		Denom:    "uluna",
		GasPrice: &GradedGasPrice{"10", "10", "10"},
		GasLimit: "80000",
	}
	TerraUst = &KnownTokenInfo{
		Cointype: 330,
		Prefix:   "terra",
		Denom:    "uusd",
		GasPrice: &GradedGasPrice{"0.25", "0.25", "0.25"},
		GasLimit: "80000",
	}
)

Functions

func AccAddressFromBech32

func AccAddressFromBech32(address string, addressPrefix string) (sdk.AccAddress, error)

func Bech32FromAccAddress

func Bech32FromAccAddress(address []byte, addressPrefix string) (string, error)

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey string, addressPrefix string) (string, error)

@param publicKey can start with 0x or not.

func IsValidAddress

func IsValidAddress(address string, addressPrefix string) bool

@param chainnet chain name

Types

type Account

type Account struct {
	Cointype      int64
	AddressPrefix string
	// contains filtered or unexported fields
}

func NewAccountWithMnemonic

func NewAccountWithMnemonic(mnemonic string, cointype int64, addressPrefix string) (*Account, error)

func NewCosmosAccountWithMnemonic

func NewCosmosAccountWithMnemonic(mnemonic string) (*Account, error)

return NewAccountWithMnemonic(mnemonic, 118, "cosmos")

func NewTerraAccountWithMnemonic

func NewTerraAccountWithMnemonic(mnemonic string) (*Account, error)

return NewAccountWithMnemonic(mnemonic, 330, "terra")

func (*Account) Address

func (a *Account) Address() string

The ethereum address is same as public key in coming

func (*Account) PrivateKey

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

Is deocde from address @return publicKey data

func (*Account) PublicKeyHex

func (a *Account) PublicKeyHex() string

The ethereum public key is same as address in coming @return publicKey string that will start with 0x.

func (*Account) Sign

func (a *Account) Sign(message []byte, password string) ([]byte, error)

TODO: Need Test.

func (*Account) SignHex

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

TODO: Need Test.

type AccountInfo

type AccountInfo struct {
	AccountNumber string `json:"account_number"`
	Sequence      string `json:"sequence"`
}

func (*AccountInfo) Nonce

func (i *AccountInfo) Nonce() string

Is aslias of Sequence

type Chain

type Chain struct {
	RpcUrl  string
	RestUrl string
	// contains filtered or unexported fields
}

func NewChainWithRpc

func NewChainWithRpc(rpcUrl string, restUrl string) *Chain

func (*Chain) AccountOf

func (c *Chain) AccountOf(address string) (*AccountInfo, error)

func (*Chain) BalanceOfAccount

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)

func (*Chain) BalanceOfAddressAndDenom

func (c *Chain) BalanceOfAddressAndDenom(address, denom string) (b *base.Balance, err error)

func (*Chain) BalanceOfPublicKey

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

Warning: Unable to use public key to query balance

func (*Chain) BatchFetchTransactionStatus

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

Batch fetch the transaction status, the hash list and the return value, which can only be passed as strings separated by "," @param hashListString The hash of the transactions to be queried in batches, a string concatenated with ",": "hash1,hash2,hash3" @return Batch transaction status, its order is consistent with hashListString: "status1,status2,status3"

func (*Chain) DenomToken

func (c *Chain) DenomToken(prefix, denom string) *Token

func (*Chain) FetchTransactionDetail

func (c *Chain) FetchTransactionDetail(hash string) (detail *base.TransactionDetail, err error)

Fetch transaction details through transaction hash

func (*Chain) FetchTransactionStatus

func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus

Fetch transaction status through transaction hash

func (*Chain) GetClient

func (c *Chain) GetClient() (*tendermintHttp.HTTP, error)

func (*Chain) MainToken

func (c *Chain) MainToken() base.Token

Warning Cosmos not supported main token

func (*Chain) SendRawTransaction

func (c *Chain) SendRawTransaction(signedTx string) (string, error)

Send the raw transaction on-chain @return the hex hash string

type GradedGasPrice added in v0.2.5

type GradedGasPrice struct {
	Low     string
	Average string
	High    string
}

type KnownTokenInfo added in v0.2.5

type KnownTokenInfo struct {
	Cointype int64
	Prefix   string
	Denom    string
	GasPrice *GradedGasPrice
	GasLimit string
}

type Token

type Token struct {
	Prefix string
	Denom  string
	// contains filtered or unexported fields
}

func NewToken

func NewToken(chain *Chain, prefix, denom string) *Token

func (*Token) BalanceOfAccount

func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Token) BalanceOfAddress

func (t *Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Token) BalanceOfPublicKey

func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

Warning: Unable to use public key to query balance

func (*Token) BuildTransferTx

func (t *Token) BuildTransferTx(privateKey, receiverAddress, gasPrice, gasLimit, amount, memo string) (string, error)

func (*Token) BuildTransferTxWithAccount

func (t *Token) BuildTransferTxWithAccount(account *Account, receiverAddress, gasPrice, gasLimit, amount, memo string) (string, error)

func (*Token) Chain

func (t *Token) Chain() base.Chain

func (*Token) TokenInfo

func (t *Token) TokenInfo() (*base.TokenInfo, error)

Warning: Main token does not support

type Util

type Util struct {
	AddressPrefix string
}

func NewUtilWithPrefix

func NewUtilWithPrefix(addressPrefix string) *Util

func (*Util) DecodeAddressToPublicKey

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

@throw decode address to public key is not supported

func (*Util) EncodePublicKeyToAddress

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Util) IsValidAddress

func (u *Util) IsValidAddress(address string) bool

Jump to

Keyboard shortcuts

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