cosmos

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 40 Imported by: 0

README

Cosmos ecosystem

This document use cosmos-hub as an example.

cosmosHub

1) chainId
mainnet: 1293698254146
testnet: 1293698254147

2) apiUrl
mainnet: https://cosmos-mainnet-rpc.allthatnode.com:1317
testnet: https://cosmos-testnet-rpc.allthatnode.com:1317

3) explorer:
https://atomscan.com/

4) faucet:
https://www.allthatnode.com/faucet/cosmos.dsrv

tools

1) getChainId
go run ./tokens/cosmos/tools/getStubChainID/main.go -n COSMOSHUB -p testnet

testnet: 1293698254147

2) publicKeyToAddress
go run ./tokens/cosmos/tools/publicKeyToAddress/main.go -p 0x0468438a94627b0de2b6a7c9af99136ef7e607f7944b749c3534bb27a89e742d583b1c8b3aecfae45dea2ac58730aa6ba654c73c435d44755e5cd1500c8f4d036b -prefix cosmos

addr: cosmos10yyn2er9k5cs9qn55l7t23yxxk7egecpw9lw90

config setting

1) chainConfig

routerContract: mpc address
extra: format is `prefix:Denom`

for example,

    # cosmosHub
    cosmos:uatom

    # sei
    sei:usei

    # coreum
    devcore:ducore

    # osmosis
    osmo:uosmo

2) tokenConfig

for meta coin,

	tokenAddress: usei
	decimals: 6

for other tokens,

	tokenAddress: factory/{creator}/{subdenom}
	decimals: 6


3) example

https://rinkeby.etherscan.io/address/0x4342F2b5224a43541BE7C8F39B92D7fEaA74d038

router mechanism

  1. Swapout from cosmos to other chain

    user send asset to mpc address with memo of the following format

    bindAddress:toChainID
    

    to specify route asset to which address (bindAddress) and to which destination blockchain (toChainID)

  2. Swapin from other chain to cosmos

    function anySwapOut(address token, string memory to, uint amount, uint toChainID)
    

    to is the receiver address on cosmos.

Documentation

Index

Constants

View Source
const (
	LatestBlock = "/cosmos/base/tendermint/v1beta1/blocks/latest"
	TxByHash    = "/cosmos/tx/v1beta1/txs/"
	AccountInfo = "/cosmos/auth/v1beta1/accounts/"
	Balances    = "/cosmos/bank/v1beta1/balances/"
	SimulateTx  = "/cosmos/tx/v1beta1/simulate"
	BroadTx     = "/cosmos/tx/v1beta1/txs"
)
View Source
const (
	TransferType = "transfer"
)

Variables

View Source
var (
	DefaultGasLimit uint64 = 150000
	DefaultFee             = "500"
)
View Source
var (
	ChainsList = []string{"COSMOSHUB", "OSMOSIS", "COREUM", "SEI"}
)

Functions

func BuildSendMsg

func BuildSendMsg(from, to, unit string, amount *big.Int) *bankTypes.MsgSend

func BuildSignatures

func BuildSignatures(publicKey cryptoTypes.PubKey, sequence uint64, signature []byte) signingTypes.SignatureV2

func BuildSignerData

func BuildSignerData(chainID string, accountNumber, sequence uint64) signing.SignerData

func GetStubChainID

func GetStubChainID(chainName, network string) *big.Int

GetStubChainID get stub chainID

func IsSupportedCosmosSubChain

func IsSupportedCosmosSubChain(chainName string) bool

IsSupportedCosmosSubChain is supported

func IsValidAddress

func IsValidAddress(prefix, address string) bool

func NewClientContext

func NewClientContext() cosmosClient.Context

func ParseCoinsFee

func ParseCoinsFee(amount string) (sdk.Coins, error)

func ParseCoinsNormalized

func ParseCoinsNormalized(coinStr string) (sdk.Coins, error)

func ParseMemo

func ParseMemo(swapInfo *tokens.SwapTxInfo, memo string) error

func PubKeyFromBytes

func PubKeyFromBytes(pubKeyBytes []byte) (cryptoTypes.PubKey, error)

PubKeyFromBytes get public key from bytes

func PubKeyFromStr

func PubKeyFromStr(pubKeyHex string) (cryptoTypes.PubKey, error)

PubKeyFromStr get public key from hex string

func PublicKeyToAddress

func PublicKeyToAddress(prefix, pubKeyHex string) (string, error)

func Sha256Sum

func Sha256Sum(data []byte) []byte

Sha256Sum returns the SHA256 of the data.

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

func VerifyPubKey

func VerifyPubKey(address, prefix, pubkey string) error

Types

type BaseAccount

type BaseAccount struct {
	Address       string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
	AccountNumber string `protobuf:"varint,3,opt,name=account_number,json=accountNumber,proto3" json:"account_number,omitempty"`
	Sequence      string `protobuf:"varint,4,opt,name=sequence,proto3" json:"sequence,omitempty"`
}

BaseAccount base account

type Block

type Block struct {
	Header Header `protobuf:"bytes,1,opt,name=header,proto3" json:"header"`
}

type Bridge

type Bridge struct {
	*base.NonceSetterBase

	cosmosClient.TxConfig

	grpc.ClientContext

	Prefix string
	Denom  string
}

Bridge base bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BroadcastTx

func (b *Bridge) BroadcastTx(req *BroadcastTxRequest) (string, error)

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) BuildTx

func (b *Bridge) BuildTx(
	args *tokens.BuildTxArgs,
	to, denom, memo, publicKey string,
	amount *big.Int,
) (cosmosClient.TxBuilder, error)

func (*Bridge) GRPCBroadcastTx

func (b *Bridge) GRPCBroadcastTx(req *BroadcastTxRequest) (res *sdk.TxResponse, err error)

func (*Bridge) GRPCGetBaseAccount

func (b *Bridge) GRPCGetBaseAccount(address string) (res *QueryAccountResponse, err error)

func (*Bridge) GRPCGetChainID

func (b *Bridge) GRPCGetChainID() (res string, err error)

func (*Bridge) GRPCGetDenomBalance

func (b *Bridge) GRPCGetDenomBalance(address, denom string) (res sdk.Int, err error)

func (*Bridge) GRPCGetLatestBlockNumber

func (b *Bridge) GRPCGetLatestBlockNumber() (res uint64, err error)

func (*Bridge) GRPCGetLatestBlockNumberOf

func (b *Bridge) GRPCGetLatestBlockNumberOf(url string) (res uint64, err error)

func (*Bridge) GRPCGetTransactionByHash

func (b *Bridge) GRPCGetTransactionByHash(txHash string) (res *GetTxResponse, err error)

func (*Bridge) GRPCSimulateTx

func (b *Bridge) GRPCSimulateTx(simulateReq *SimulateRequest) (res *sdktx.SimulateResponse, err error)

func (*Bridge) GetAccountNum

func (b *Bridge) GetAccountNum(account string) (uint64, error)

GetAccountNum get account number

func (*Bridge) GetBaseAccount

func (b *Bridge) GetBaseAccount(address string) (*QueryAccountResponse, error)

func (*Bridge) GetChainID

func (b *Bridge) GetChainID() (string, error)

func (*Bridge) GetDenomBalance

func (b *Bridge) GetDenomBalance(address, denom string) (sdk.Int, error)

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (uint64, error)

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(apiAddress string) (uint64, error)

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, _height string) (uint64, error)

GetPoolNonce impl NonceSetter interface

func (*Bridge) GetSeq

func (b *Bridge) GetSeq(args *tokens.BuildTxArgs) (nonceptr *uint64, err error)

GetSeq returns account tx sequence

func (*Bridge) GetSignBytes

func (b *Bridge) GetSignBytes(tx *BuildRawTx) ([]byte, error)

func (*Bridge) GetSignTx

func (b *Bridge) GetSignTx(tx signing.Tx) (signedTx []byte, txHash string, err error)

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)

GetTransaction impl

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (*GetTxResponse, error)

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (status *tokens.TxStatus, err error)

GetTransactionStatus impl

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*Bridge) InitRouterInfo

func (b *Bridge) InitRouterInfo(routerContract, routerVersion string) (err error)

InitRouterInfo init router info

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(address string) bool

IsValidAddress check address

func (*Bridge) MPCSignTransaction

func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signedTx interface{}, txHash string, err error)

MPCSignTransaction mpc sign raw tx

func (*Bridge) NewSignModeHandler

func (b *Bridge) NewSignModeHandler() signing.SignModeHandler

func (*Bridge) ParseAmountTotal

func (b *Bridge) ParseAmountTotal(messageLog sdk.ABCIMessageLog, swapInfo *tokens.SwapTxInfo) error

func (*Bridge) ParseCoinAmount

func (b *Bridge) ParseCoinAmount(value *big.Int, swapInfo *tokens.SwapTxInfo, sender, recipient, amount sdk.Attribute, unit *string)

func (*Bridge) PublicKeyToAddress

func (b *Bridge) PublicKeyToAddress(pubKeyHex string) (string, error)

PublicKeyToAddress public key hex string (may be uncompressed) to address

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (string, error)

SendTransaction send signed tx

func (*Bridge) SetGatewayConfig

func (b *Bridge) SetGatewayConfig(gatewayCfg *tokens.GatewayConfig)

SetGatewayConfig set gateway config

func (*Bridge) SetPrefixAndDenom

func (b *Bridge) SetPrefixAndDenom(prefix, denom string)

func (*Bridge) SetTokenConfig

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set and verify token config

func (*Bridge) SignTransactionWithPrivateKey

func (b *Bridge) SignTransactionWithPrivateKey(buildRawTx *BuildRawTx, privKey string) (signedTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) SimulateTx

func (b *Bridge) SimulateTx(simulateReq *SimulateRequest) (string, error)

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(tx interface{}, msgHashes []string) (err error)

VerifyMsgHash verify msg hash

func (*Bridge) VerifyPubKey

func (b *Bridge) VerifyPubKey(address, pubkey string) error

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction impl

type BroadcastTxRequest

type BroadcastTxRequest struct {
	TxBytes string `json:"tx_bytes"`
	Mode    string `json:"mode"`
}

type BroadcastTxResponse

type BroadcastTxResponse struct {
	TxResponse *TxResponse `protobuf:"bytes,1,opt,name=tx_response,json=txResponse,proto3" json:"tx_response,omitempty"`
}

type BuildRawTx

type BuildRawTx struct {
	TxBuilder     cosmosClient.TxBuilder `json:"tx_builder,omitempty"`
	AccountNumber uint64                 `json:"account_number,omitempty"`
	Sequence      uint64                 `json:"sequence,omitempty"`
}

type GasInfo

type GasInfo struct {
	// GasUsed is the amount of gas actually consumed.
	GasUsed string `protobuf:"varint,2,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
}

GasInfo defines tx execution gas context.

type GetLatestBlockResponse

type GetLatestBlockResponse struct {
	// Deprecated: please use `sdk_block` instead
	Block *Block `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"`
}

GetLatestBlockResponse is the response type for the Query/GetLatestBlock RPC method.

type GetTxResponse

type GetTxResponse struct {
	// The request transaction bytes.
	Tx *Tx `protobuf:"bytes,11,opt,name=tx,proto3" json:"tx,omitempty"`
	// tx_response is the queried TxResponses.
	TxResponse *TxResponse `protobuf:"bytes,2,opt,name=tx_response,json=txResponse,proto3" json:"tx_response,omitempty"`
}
type Header struct {
	// basic block info
	ChainID string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
	Height  string `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"`
}

Header defines the structure of a Tendermint block header.

type QueryAccountResponse

type QueryAccountResponse struct {
	// account defines the account of the corresponding address.
	Account *BaseAccount `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
}

QueryAccountResponse is the response type for the Query/Account RPC method.

type QueryAllBalancesResponse

type QueryAllBalancesResponse struct {
	// balances is the balances of all the coins.
	Balances sdk.Coins `protobuf:"bytes,1,rep,name=balances,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"balances"`
}

QueryAllBalancesResponse balances

type SimulateRequest

type SimulateRequest struct {
	TxBytes string `json:"tx_bytes"`
}

SimulateRequest is the request type for the Service.Simulate RPC method.

type SimulateResponse

type SimulateResponse struct {
	// gas_info is the information about gas used in the simulation.
	GasInfo *GasInfo `protobuf:"bytes,1,opt,name=gas_info,json=gasInfo,proto3" json:"gas_info,omitempty"`
}

SimulateResponse is the response type for the Service.SimulateRPC method.

type Tx

type Tx struct {
	Body TxBody `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"`
}

Tx tx

type TxBody

type TxBody struct {
	// memo is any arbitrary note/comment to be added to the transaction.
	// WARNING: in clients, any publicly exposed text should not be called memo,
	// but should be called `note` instead (see https://github.com/cosmos/cosmos-sdk/issues/9122).
	Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"`
}

type TxResponse

type TxResponse struct {
	// The block height
	Height string `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"`
	// The transaction hash.
	TxHash string `protobuf:"bytes,2,opt,name=txhash,proto3" json:"txhash,omitempty"`
	// Response code.
	Code uint32 `protobuf:"varint,4,opt,name=code,proto3" json:"code,omitempty"`
	// The output of the application's logger (typed). May be non-deterministic.
	Logs sdk.ABCIMessageLogs `protobuf:"bytes,7,rep,name=logs,proto3,castrepeated=ABCIMessageLogs" json:"logs"`
}

TxResponse defines a structure containing relevant tx data and metadata. The tags are stringified and the log is JSON decoded.

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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