cosmos

package
v0.5.15 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: GPL-3.0 Imports: 31 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultClientTimeout used by the Client.
	DefaultClientTimeout = time.Minute
	// DefaultClientTimeoutRetry used by the Client.
	DefaultClientTimeoutRetry = time.Second
	// DefaultClientHost used by the Client. This should only be used for local
	// deployments of the multichain.
	DefaultClientHost = pack.String("http://0.0.0.0:26657")
	// DefaultBroadcastMode configures the behaviour of a cosmos client while it
	// interacts with the cosmos node. Allowed broadcast modes can be async, sync
	// and block. "async" returns immediately after broadcasting, "sync" returns
	// after the transaction has been checked and "block" waits until the
	// transaction is committed to the chain.
	DefaultBroadcastMode = pack.String("sync")
	// DefaultCoinDenom used by the Client.
	DefaultCoinDenom = pack.String("uluna")
)
View Source
const (
	// DefaultChainID used by the Client.
	DefaultChainID = pack.String("testnet")
	// DefaultSignMode used in signing the tx
	DefaultSignMode = 1
	// DefaultDecimalsDivisor is used when estimating gas prices for some Cosmos
	// chains, so that the result is an integer.
	// For example, the recommended Terra gas price is currently 0.01133 uluna.
	// To ensure we're only dealing with integers, the value can be represented
	// as 1133. When the transaction builder is calculating fees, it will divide
	// the total by the divisor (in this case 1e5), to calculate the actual
	// value.
	DefaultDecimalsDivisor = 1
)

Variables

This section is empty.

Functions

func NewGasEstimator

func NewGasEstimator(gasPerByte pack.U256) gas.Estimator

NewGasEstimator returns a simple gas estimator that always returns the same amount of gas-per-byte.

func NewTxBuilder

func NewTxBuilder(options TxBuilderOptions, client *Client) account.TxBuilder

NewTxBuilder returns an implementation of the transaction builder interface from the Cosmos Compat API, and exposes the functionality to build simple Cosmos based transactions.

Types

type Address

type Address sdk.AccAddress

An Address is a public address that can be encoded/decoded to/from strings. Addresses are usually formatted different between different network configurations.

func (Address) AccAddress

func (addr Address) AccAddress() sdk.AccAddress

AccAddress convert Address to sdk.AccAddress

func (Address) String

func (addr Address) String() string

String implements the Stringer interface

type AddressDecoder

type AddressDecoder struct {
}

AddressDecoder implements the address.Decoder interface

func NewAddressDecoder

func NewAddressDecoder() AddressDecoder

NewAddressDecoder creates a new address decoder

func (AddressDecoder) DecodeAddress

func (decoder AddressDecoder) DecodeAddress(addr address.Address) (address.RawAddress, error)

DecodeAddress consumes a human-readable representation of a cosmos compatible address and decodes it to its raw bytes representation.

type AddressEncodeDecoder

type AddressEncodeDecoder struct {
	AddressEncoder
	AddressDecoder
}

AddressEncodeDecoder encapsulates fields that implement the address.EncodeDecoder interface

func NewAddressEncodeDecoder

func NewAddressEncodeDecoder() AddressEncodeDecoder

NewAddressEncodeDecoder creates a new address encoder-decoder

type AddressEncoder

type AddressEncoder struct {
}

AddressEncoder implements the address.Encoder interface

func NewAddressEncoder

func NewAddressEncoder() AddressEncoder

NewAddressEncoder creates a new address encoder

func (AddressEncoder) EncodeAddress

func (encoder AddressEncoder) EncodeAddress(rawAddr address.RawAddress) (address.Address, error)

EncodeAddress consumes raw bytes and encodes them to a human-readable address format.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client interacts with an instance of the Cosmos based network using the REST interface exposed by a lightclient node.

func NewClient

func NewClient(opts ClientOptions, cdc codec.Codec, txConfig cosmClient.TxConfig, interfaceReg codecTypes.InterfaceRegistry, amino *codec.LegacyAmino, hrp string) *Client

NewClient returns a new Client.

func (*Client) AccountBalance added in v0.2.12

func (client *Client) AccountBalance(ctx context.Context, addr address.Address) (pack.U256, error)

AccountBalance returns the account balancee for a given address.

func (*Client) AccountNonce added in v0.2.8

func (client *Client) AccountNonce(ctx context.Context, addr address.Address) (pack.U256, error)

AccountNonce returns the current nonce of the account. This is the nonce to be used while building a new transaction.

func (*Client) AccountNumber added in v0.2.8

func (client *Client) AccountNumber(ctx context.Context, addr address.Address) (pack.U64, error)

AccountNumber returns the account number for a given address.

func (*Client) LatestBlock added in v0.2.20

func (client *Client) LatestBlock(ctx context.Context) (pack.U64, error)

LatestBlock returns the most recent block's number.

func (*Client) SubmitTx

func (client *Client) SubmitTx(ctx context.Context, tx account.Tx) error

SubmitTx to the Cosmos based network.

func (*Client) Tx

func (client *Client) Tx(ctx context.Context, txHash pack.Bytes) (account.Tx, pack.U64, error)

Tx query transaction with txHash

type ClientOptions

type ClientOptions struct {
	Timeout       time.Duration
	TimeoutRetry  time.Duration
	Host          pack.String
	BroadcastMode pack.String
	CoinDenom     pack.String
	ChainID       pack.String
}

ClientOptions are used to parameterise the behaviour of the Client.

func DefaultClientOptions

func DefaultClientOptions() ClientOptions

DefaultClientOptions returns ClientOptions with the default settings. These settings are valid for use with the default local deployment of the multichain. In production, the host, user, and password should be changed.

func (ClientOptions) WithBroadcastMode added in v0.2.12

func (opts ClientOptions) WithBroadcastMode(broadcastMode pack.String) ClientOptions

WithBroadcastMode sets the behaviour of the Client when interacting with the underlying node.

func (ClientOptions) WithChainID added in v0.4.3

func (opts ClientOptions) WithChainID(chainid pack.String) ClientOptions

WithChainID sets the chain id used by the Client.

func (ClientOptions) WithCoinDenom added in v0.2.12

func (opts ClientOptions) WithCoinDenom(coinDenom pack.String) ClientOptions

WithCoinDenom sets the coin denomination used by the Client.

func (ClientOptions) WithHost

func (opts ClientOptions) WithHost(host pack.String) ClientOptions

WithHost sets the URL of the node.

func (ClientOptions) WithTimeout added in v0.2.12

func (opts ClientOptions) WithTimeout(timeout time.Duration) ClientOptions

WithTimeout sets the timeout used by the Client.

func (ClientOptions) WithTimeoutRetry added in v0.2.12

func (opts ClientOptions) WithTimeoutRetry(timeoutRetry time.Duration) ClientOptions

WithTimeoutRetry sets the timeout retry used by the Client.

type Coin

type Coin struct {
	Denom  pack.String `json:"denom"`
	Amount pack.U64    `json:"amount"`
}

Coin copy type from types.coin

type Coins

type Coins []Coin

Coins array of Coin

func (Coins) Coins

func (coins Coins) Coins() types.Coins

Coins parse pack coins to sdk coins

type GasEstimator

type GasEstimator struct {
	// contains filtered or unexported fields
}

A GasEstimator returns the gas-per-byte that is needed in order to confirm transactions with an estimated maximum delay of one block. In distributed networks that collectively build, sign, and submit transactions, it is important that all nodes in the network have reached consensus on the gas-per-byte.

func (*GasEstimator) EstimateGas added in v0.2.9

func (gasEstimator *GasEstimator) EstimateGas(ctx context.Context) (pack.U256, pack.U256, error)

EstimateGas returns gas required per byte for Cosmos-compatible chains. This value is used for both the price and cap, because Cosmos-compatible chains do not have a distinct concept of cap.

type MsgSend

type MsgSend struct {
	FromAddress Address `json:"from_address" yaml:"from_address"`
	ToAddress   Address `json:"to_address" yaml:"to_address"`
	Amount      Coins   `json:"amount" yaml:"amount"`
}

MsgSend - high level transaction of the coin module

func (MsgSend) Msg

func (msg MsgSend) Msg() types.Msg

Msg convert MsgSend to types.Msg

type Tx added in v0.4.3

type Tx struct {
	// contains filtered or unexported fields
}

Tx is a tx.Tx wrapper

func (Tx) From added in v0.4.3

func (t Tx) From() address.Address

From returns the sender of the transaction

func (Tx) Hash added in v0.4.3

func (t Tx) Hash() pack.Bytes

Hash return txhash bytes.

func (Tx) Nonce added in v0.4.3

func (t Tx) Nonce() pack.U256

Nonce returns the transaction count of the transaction sender.

func (Tx) Payload added in v0.4.3

func (t Tx) Payload() contract.CallData

Payload returns the memo attached to the transaction.

func (Tx) Serialize added in v0.4.3

func (t Tx) Serialize() (pack.Bytes, error)

Serialize the transaction.

func (Tx) Sighashes added in v0.4.3

func (t Tx) Sighashes() ([]pack.Bytes32, error)

Sighashes that need to be signed before this transaction can be submitted.

func (*Tx) Sign added in v0.4.3

func (t *Tx) Sign(signatures []pack.Bytes65, pubKey pack.Bytes) error

Sign the transaction by injecting signatures and the serialized pubkey of the signer.

func (Tx) To added in v0.4.3

func (t Tx) To() address.Address

To returns the recipients of the transaction. For the cosmos chain, there can be multiple recipients from a single transaction.

func (Tx) Value added in v0.4.3

func (t Tx) Value() pack.U256

Value returns the values being transferred in a transaction. For the cosmos chain, there can be multiple messages (each with a different value being transferred) in a single transaction.

type TxBuilderOptions

type TxBuilderOptions struct {
	ChainID         pack.String
	DecimalsDivisor pack.U256
}

TxBuilderOptions only contains necessary options to build tx from tx builder

func DefaultTxBuilderOptions added in v0.2.12

func DefaultTxBuilderOptions() TxBuilderOptions

DefaultTxBuilderOptions returns TxBuilderOptions with the default settings.

func (TxBuilderOptions) WithChainID added in v0.2.12

func (opts TxBuilderOptions) WithChainID(chainID pack.String) TxBuilderOptions

WithChainID sets the chain ID used by the transaction builder.

func (TxBuilderOptions) WithDecimalsDivisor added in v0.5.6

func (opts TxBuilderOptions) WithDecimalsDivisor(decimalDivisor pack.U256) TxBuilderOptions

Jump to

Keyboard shortcuts

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