Documentation
¶
Overview ¶
Package cosmosclient provides a standalone client to connect to Cosmos SDK chains.
Index ¶
- Variables
- type Client
- func (c Client) Account(nameOrAddress string) (cosmosaccount.Account, error)
- func (c Client) Address(accountName string) (string, error)
- func (c Client) BankBalances(ctx context.Context, address string, pagination *query.PageRequest) (sdk.Coins, error)
- func (c Client) BankSendTx(fromAccount cosmosaccount.Account, toAddress string, amount sdk.Coins) (TxService, error)
- func (c Client) BroadcastTx(account cosmosaccount.Account, msgs ...sdktypes.Msg) (Response, error)
- func (c Client) ConsensusInfo(ctx context.Context, height int64) (ConsensusInfo, error)
- func (c Client) Context() client.Context
- func (c Client) CreateTx(account cosmosaccount.Account, msgs ...sdktypes.Msg) (TxService, error)
- func (c Client) LatestBlockHeight(ctx context.Context) (int64, error)
- func (c Client) SetConfigAddressPrefix()
- func (c Client) Status(ctx context.Context) (*ctypes.ResultStatus, error)
- func (c Client) WaitForBlockHeight(ctx context.Context, h int64, timeout time.Duration) error
- func (c Client) WaitForNBlocks(ctx context.Context, n int64, timeout time.Duration) error
- func (c Client) WaitForNextBlock(ctx context.Context) error
- type ConsensusInfo
- type FaucetClient
- type Gasometer
- type Option
- func WithAccountRetriever(accountRetriever client.AccountRetriever) Option
- func WithAddressPrefix(prefix string) Option
- func WithBankQueryClient(bankQueryClient banktypes.QueryClient) Option
- func WithBroadcastMode(broadcastMode string) Option
- func WithFaucetClient(faucetClient FaucetClient) Option
- func WithFees(fees string) Option
- func WithGas(gas string) Option
- func WithGasPrices(gasPrices string) Option
- func WithGasometer(gasometer Gasometer) Option
- func WithGenerateOnly(generateOnly bool) Option
- func WithHome(path string) Option
- func WithKeyringBackend(backend cosmosaccount.KeyringBackend) Option
- func WithKeyringDir(keyringDir string) Option
- func WithKeyringServiceName(name string) Option
- func WithNodeAddress(addr string) Option
- func WithRPCClient(rpc rpcclient.Client) Option
- func WithUseFaucet(faucetAddress, denom string, minAmount uint64) Option
- type Response
- type TxService
Constants ¶
This section is empty.
Variables ¶
var ( // FaucetTransferEnsureDuration is the duration that BroadcastTx will wait when a faucet transfer // is triggered prior to broadcasting but transfer's tx is not committed in the state yet. FaucetTransferEnsureDuration = time.Second * 40 )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// RPC is Tendermint RPC.
RPC rpcclient.Client
// TxFactory is a Cosmos SDK tx factory.
TxFactory tx.Factory
// AccountRegistry is the retistry to access accounts.
AccountRegistry cosmosaccount.Registry
// contains filtered or unexported fields
}
Client is a client to access your chain by querying and broadcasting transactions.
func (Client) Account ¶
func (c Client) Account(nameOrAddress string) (cosmosaccount.Account, error)
Account returns the account with name or address equal to nameOrAddress.
func (Client) BankBalances ¶ added in v0.24.0
func (Client) BankSendTx ¶ added in v0.24.0
func (Client) BroadcastTx ¶
func (Client) ConsensusInfo ¶
ConsensusInfo returns the appropriate tendermint consensus state by given height and the validator set for the next height
func (Client) LatestBlockHeight ¶ added in v0.24.0
LatestBlockHeight returns the lastest block height of the app.
func (Client) SetConfigAddressPrefix ¶ added in v0.24.0
func (c Client) SetConfigAddressPrefix()
SetConfigAddressPrefix sets the account prefix in the SDK global config
func (Client) WaitForBlockHeight ¶ added in v0.24.0
WaitForBlockHeight waits until block height h is committed, or returns an error if ctx is canceled or if timeout is reached.
func (Client) WaitForNBlocks ¶ added in v0.24.0
WaitForNBlocks reads the current block height and then waits for anothers n blocks to be committed.
func (Client) WaitForNextBlock ¶ added in v0.24.0
WaitForNextBlock waits until next block is committed. It reads the current block height and then waits for another block to be committed. A timeout occurs after 10 seconds, to customize the timeout, use the WaitForNBlocks(ctx, 1, timeout) function.
type ConsensusInfo ¶
type ConsensusInfo struct {
Timestamp string `json:"Timestamp"`
Root string `json:"Root"`
NextValidatorsHash string `json:"NextValidatorsHash"`
ValidatorSet *tmproto.ValidatorSet `json:"ValidatorSet"`
}
ConsensusInfo is the validator consensus info
type FaucetClient ¶ added in v0.24.0
type FaucetClient interface {
Transfer(context.Context, cosmosfaucet.TransferRequest) (cosmosfaucet.TransferResponse, error)
}
FaucetClient allows to mock the cosmosfaucet.Client.
type Gasometer ¶ added in v0.24.0
type Gasometer interface {
CalculateGas(clientCtx gogogrpc.ClientConn, txf tx.Factory, msgs ...sdktypes.Msg) (*txtypes.SimulateResponse, uint64, error)
}
Gasometer allows to mock the tx.CalculateGas func.
type Option ¶
type Option func(*Client)
Option configures your client.
func WithAccountRetriever ¶ added in v0.24.0
func WithAccountRetriever(accountRetriever client.AccountRetriever) Option
WithAccountRetriever sets the account retriever Already set by default.
func WithAddressPrefix ¶
func WithBankQueryClient ¶ added in v0.24.0
func WithBankQueryClient(bankQueryClient banktypes.QueryClient) Option
WithBankQueryClient sets the bank query client. Already set by default.
func WithBroadcastMode ¶ added in v0.24.0
WithBroadcastMode sets the broadcast mode
func WithFaucetClient ¶ added in v0.24.0
func WithFaucetClient(faucetClient FaucetClient) Option
WithFaucetClient sets the faucet client. Already set by default.
func WithGas ¶ added in v0.24.0
WithGas sets an explicit gas-limit on transactions. Set to "auto" to calculate automatically
func WithGasPrices ¶ added in v0.24.0
WithGasPrices sets the price per gas (e.g. 0.1uatom)
func WithGasometer ¶ added in v0.24.0
WithGasometer sets the gasometer. Already set by default.
func WithGenerateOnly ¶ added in v0.24.0
WithGenerateOnly tells if txs will be generated only.
func WithHome ¶
WithHome sets the data dir of your chain. This option is used to access your chain's file based keyring which is only needed when you deal with creating and signing transactions. when it is not provided, your data dir will be assumed as `$HOME/.your-chain-id`.
func WithKeyringBackend ¶
func WithKeyringBackend(backend cosmosaccount.KeyringBackend) Option
WithKeyringBackend sets your keyring backend. By default, it is `test`.
func WithKeyringDir ¶ added in v0.24.0
WithKeyringDir sets the directory of the keyring. By default, it uses cosmosaccount.KeyringHome
func WithKeyringServiceName ¶
WithKeyringServiceName used as the keyring's name when you are using OS keyring backend. by default it is `cosmos`.
func WithNodeAddress ¶
WithNodeAddress sets the node address of your chain. When this option is not provided `http://localhost:26657` is used as default.
func WithRPCClient ¶ added in v0.24.0
WithRPCClient sets a tendermint RPC client. Already set by default.
func WithUseFaucet ¶
type Response ¶
type Response struct {
Codec codec.Codec
// TxResponse is the underlying tx response.
*sdktypes.TxResponse
}
Response of your broadcasted transaction.
func (Response) Decode ¶
Decode decodes the proto func response defined in your Msg service into your message type. message needs to be a pointer. and you need to provide the correct proto message(struct) type to the Decode func.
e.g., for the following CreateChain func the type would be: `types.MsgCreateChainResponse`.
```proto
service Msg {
rpc CreateChain(MsgCreateChain) returns (MsgCreateChainResponse);
}
```