client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 81 Imported by: 36

Documentation

Index

Constants

View Source
const (
	ErrTimeoutAfterWaitingForTxBroadcast _err = "timed out after waiting for tx to get included in the block"
)

Variables

View Source
var (
	// Variables used for retries
	RtyAttNum = uint(5)
	RtyAtt    = retry.Attempts(RtyAttNum)
	RtyDel    = retry.Delay(time.Millisecond * 400)
	RtyErr    = retry.LastErrorOnly(true)
)
View Source
var (
	// SupportedAlgorithms defines the list of signing algorithms used on Evmos:
	//  - secp256k1     (Cosmos)
	//  - eth_secp256k1 (Ethereum)
	SupportedAlgorithms = keyring.SigningAlgoList{hd.Secp256k1, ethhd.EthSecp256k1}
	// SupportedAlgorithmsLedger defines the list of signing algorithms used on Evmos for the Ledger device:
	//  - secp256k1     (Cosmos)
	//  - eth_secp256k1 (Ethereum)
	SupportedAlgorithmsLedger = keyring.SigningAlgoList{hd.Secp256k1, ethhd.EthSecp256k1}
)

Functions

func BuildSimTx

func BuildSimTx(info keyring.Info, txf tx.Factory, msgs ...sdk.Msg) ([]byte, error)

BuildSimTx creates an unsigned tx with an empty single signature and returns the encoded transaction or an error if the unsigned transaction cannot be built.

func CheckTendermintError

func CheckTendermintError(err error, tx tmtypes.Tx) *sdk.TxResponse

CheckTendermintError checks if the error returned from BroadcastTx is a Tendermint error that is returned before the tx is submitted due to precondition checks that failed. If an Tendermint error is detected, this function returns the correct code back in TxResponse.

TODO: Avoid brittle string matching in favor of error matching. This requires a change to Tendermint's RPCError type to allow retrieval or matching against a concrete error type.

func CreateMnemonic

func CreateMnemonic() (string, error)

CreateMnemonic creates a new mnemonic

func DefaultPageRequest

func DefaultPageRequest() *query.PageRequest

func GetHeightFromMetadata

func GetHeightFromMetadata(md metadata.MD) (int64, error)

func GetProveFromMetadata

func GetProveFromMetadata(md metadata.MD) (bool, error)

func LensKeyringAlgoOptions added in v0.5.0

func LensKeyringAlgoOptions() keyring.Option

Option defines a function keys options for the ethereum Secp256k1 curve. It supports secp256k1 and eth_secp256k1 keys for accounts.

func NewRPCClient

func NewRPCClient(addr string, timeout time.Duration) (*rpchttp.HTTP, error)

func SetHeightOnContext

func SetHeightOnContext(ctx context.Context, height int64) context.Context

func SetProveOnContext

func SetProveOnContext(ctx context.Context, prove bool) context.Context

Types

type ChainClient

type ChainClient struct {
	Config         *ChainClientConfig
	Keybase        keyring.Keyring
	KeyringOptions []keyring.Option
	RPCClient      rpcclient.Client
	LightProvider  provtypes.Provider
	Input          io.Reader
	Output         io.Writer

	Codec Codec
	// contains filtered or unexported fields
}

func NewChainClient

func NewChainClient(log *zap.Logger, ccc *ChainClientConfig, homepath string, input io.Reader, output io.Writer, kro ...keyring.Option) (*ChainClient, error)

func (*ChainClient) AccountFromKeyOrAddress added in v0.1.3

func (cc *ChainClient) AccountFromKeyOrAddress(keyOrAddress string) (out sdk.AccAddress, err error)

AccountFromKeyOrAddress returns an account from either a key or an address if empty string is passed in this returns the default key's address

func (*ChainClient) AddKey

func (cc *ChainClient) AddKey(name string, coinType uint32) (output *KeyOutput, err error)

func (*ChainClient) BroadcastTx

func (cc *ChainClient) BroadcastTx(ctx context.Context, tx []byte) (*sdk.TxResponse, error)

func (*ChainClient) CalculateGas

func (cc *ChainClient) CalculateGas(ctx context.Context, txf tx.Factory, msgs ...sdk.Msg) (txtypes.SimulateResponse, uint64, error)

func (*ChainClient) CreateKeystore

func (cc *ChainClient) CreateKeystore(path string) error

func (*ChainClient) DecodeBech32AccAddr

func (cc *ChainClient) DecodeBech32AccAddr(addr string) (sdk.AccAddress, error)

func (*ChainClient) DecodeBech32AccPub

func (cc *ChainClient) DecodeBech32AccPub(addr string) (sdk.AccAddress, error)

func (*ChainClient) DecodeBech32ConsAddr

func (cc *ChainClient) DecodeBech32ConsAddr(addr string) (sdk.AccAddress, error)

func (*ChainClient) DecodeBech32ConsPub

func (cc *ChainClient) DecodeBech32ConsPub(addr string) (sdk.AccAddress, error)

func (*ChainClient) DecodeBech32ValAddr

func (cc *ChainClient) DecodeBech32ValAddr(addr string) (sdk.ValAddress, error)

func (*ChainClient) DecodeBech32ValPub

func (cc *ChainClient) DecodeBech32ValPub(addr string) (sdk.AccAddress, error)

func (*ChainClient) DeleteKey

func (cc *ChainClient) DeleteKey(name string) error

func (*ChainClient) EncodeBech32AccAddr

func (cc *ChainClient) EncodeBech32AccAddr(addr sdk.AccAddress) (string, error)

func (*ChainClient) EncodeBech32AccPub

func (cc *ChainClient) EncodeBech32AccPub(addr sdk.AccAddress) (string, error)

func (*ChainClient) EncodeBech32ConsAddr

func (cc *ChainClient) EncodeBech32ConsAddr(addr sdk.AccAddress) (string, error)

func (*ChainClient) EncodeBech32ConsPub

func (cc *ChainClient) EncodeBech32ConsPub(addr sdk.AccAddress) (string, error)

func (*ChainClient) EncodeBech32ValAddr

func (cc *ChainClient) EncodeBech32ValAddr(addr sdk.ValAddress) (string, error)

func (*ChainClient) EncodeBech32ValPub

func (cc *ChainClient) EncodeBech32ValPub(addr sdk.AccAddress) (string, error)

func (*ChainClient) EnsureExists

func (cc *ChainClient) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error

EnsureExists returns an error if no account exists for the given address else nil.

func (*ChainClient) ExportPrivKeyArmor

func (cc *ChainClient) ExportPrivKeyArmor(keyName string) (armor string, err error)

func (*ChainClient) GetAccount

func (cc *ChainClient) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error)

GetAccount queries for an account given an address and a block height. An error is returned if the query or decoding fails.

func (*ChainClient) GetAccountNumberSequence

func (cc *ChainClient) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error)

GetAccountNumberSequence returns sequence and account number for the given address. It returns an error if the account couldn't be retrieved from the state.

func (*ChainClient) GetAccountWithHeight

func (cc *ChainClient) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error)

GetAccountWithHeight queries for an account given an address. Returns the height of the query with the account. An error is returned if the query or decoding fails.

func (*ChainClient) GetKeyAddress

func (cc *ChainClient) GetKeyAddress() (sdk.AccAddress, error)

func (*ChainClient) HandleAndPrintMsgSend added in v0.1.3

func (cc *ChainClient) HandleAndPrintMsgSend(res *sdk.TxResponse, err error) error

func (*ChainClient) Init added in v0.1.3

func (cc *ChainClient) Init() error

func (*ChainClient) Invoke

func (cc *ChainClient) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error)

Invoke implements the grpc ClientConn.Invoke method

func (*ChainClient) KeyAddOrRestore

func (cc *ChainClient) KeyAddOrRestore(keyName string, coinType uint32, mnemonic ...string) (*KeyOutput, error)

func (*ChainClient) KeyExists

func (cc *ChainClient) KeyExists(name string) bool

func (*ChainClient) KeystoreCreated

func (cc *ChainClient) KeystoreCreated(path string) bool

func (*ChainClient) ListAddresses

func (cc *ChainClient) ListAddresses() (map[string]string, error)

func (*ChainClient) MarshalProto

func (cc *ChainClient) MarshalProto(res proto.Message) ([]byte, error)

func (*ChainClient) MustEncodeAccAddr added in v0.1.3

func (cc *ChainClient) MustEncodeAccAddr(addr sdk.AccAddress) string

func (*ChainClient) MustEncodeValAddr added in v0.1.3

func (cc *ChainClient) MustEncodeValAddr(addr sdk.ValAddress) string

func (*ChainClient) NewStream

NewStream implements the grpc ClientConn.NewStream method

func (*ChainClient) PrepareFactory

func (cc *ChainClient) PrepareFactory(txf tx.Factory) (tx.Factory, error)

func (*ChainClient) PrintObject

func (cc *ChainClient) PrintObject(res interface{}) error

func (*ChainClient) PrintTxResponse

func (cc *ChainClient) PrintTxResponse(res *sdk.TxResponse) error

TODO: actually do something different here have a couple of levels of verbosity

func (*ChainClient) QueryABCI

func (cc *ChainClient) QueryABCI(ctx context.Context, req abci.RequestQuery) (abci.ResponseQuery, error)

func (*ChainClient) QueryAccount

func (cc *ChainClient) QueryAccount(ctx context.Context, address sdk.AccAddress) (authtypes.AccountI, error)

func (*ChainClient) QueryBalanceWithDenomTraces added in v0.1.3

func (cc *ChainClient) QueryBalanceWithDenomTraces(ctx context.Context, address sdk.AccAddress, pageReq *query.PageRequest) (sdk.Coins, error)

QueryBalanceWithDenomTraces is a helper function for query balance

func (*ChainClient) QueryDelegatorValidators

func (cc *ChainClient) QueryDelegatorValidators(ctx context.Context, address sdk.AccAddress) ([]string, error)

func (*ChainClient) QueryDenomsMetadata added in v0.1.3

func (cc *ChainClient) QueryDenomsMetadata(ctx context.Context, pageReq *query.PageRequest) (*bankTypes.QueryDenomsMetadataResponse, error)

func (*ChainClient) QueryDistributionCommission

func (cc *ChainClient) QueryDistributionCommission(ctx context.Context, address sdk.ValAddress) (sdk.DecCoins, error)

func (*ChainClient) QueryDistributionCommunityPool

func (cc *ChainClient) QueryDistributionCommunityPool(ctx context.Context) (sdk.DecCoins, error)

func (*ChainClient) QueryDistributionParams

func (cc *ChainClient) QueryDistributionParams(ctx context.Context) (*distTypes.Params, error)

func (*ChainClient) QueryDistributionRewards

func (cc *ChainClient) QueryDistributionRewards(ctx context.Context, delegatorAddress sdk.AccAddress, validatorAddress sdk.ValAddress) (sdk.DecCoins, error)

func (*ChainClient) QueryDistributionSlashes

func (cc *ChainClient) QueryDistributionSlashes(ctx context.Context, validatorAddress sdk.ValAddress, startHeight, endHeight uint64, pageReq *query.PageRequest) (*distTypes.QueryValidatorSlashesResponse, error)

QueryDistributionSlashes returns all slashes of a validator, optionally pass the start and end height

func (*ChainClient) QueryDistributionValidatorRewards

func (cc *ChainClient) QueryDistributionValidatorRewards(ctx context.Context, validatorAddress sdk.ValAddress) (sdk.DecCoins, error)

QueryDistributionValidatorRewards returns all the validator distribution rewards from a given height

func (*ChainClient) QueryTotalSupply added in v0.1.3

func (cc *ChainClient) QueryTotalSupply(ctx context.Context, pageReq *query.PageRequest) (*bankTypes.QueryTotalSupplyResponse, error)

QueryTotalSupply returns the total supply of coins on a chain

func (*ChainClient) QueryTx added in v0.1.3

func (cc *ChainClient) QueryTx(ctx context.Context, hashHex string, prove bool) (*ctypes.ResultTx, error)

QueryTx takes a hex encoded tx hash and decodes it before attempting to query the tx via the RPCClient.

func (*ChainClient) QueryTxs added in v0.1.3

func (cc *ChainClient) QueryTxs(ctx context.Context, page, limit int, events []string) ([]*ctypes.ResultTx, error)

QueryTxs returns an array of transactions related to the specified event search criteria.

func (*ChainClient) RestoreKey

func (cc *ChainClient) RestoreKey(name, mnemonic string, coinType uint32) (address string, err error)

func (*ChainClient) RunGRPCQuery

func (cc *ChainClient) RunGRPCQuery(ctx context.Context, method string, req interface{}, md metadata.MD) (abci.ResponseQuery, metadata.MD, error)

RunGRPCQuery runs a gRPC query from the clientCtx, given all necessary arguments for the gRPC method, and returns the ABCI response. It is used to factorize code between client (Invoke) and server (RegisterGRPCServer) gRPC handlers.

func (*ChainClient) SendMsg

func (cc *ChainClient) SendMsg(ctx context.Context, msg sdk.Msg) (*sdk.TxResponse, error)

func (*ChainClient) SendMsgs

func (cc *ChainClient) SendMsgs(ctx context.Context, msgs []sdk.Msg) (*sdk.TxResponse, error)

SendMsgs wraps the msgs in a StdTx, signs and sends it. An error is returned if there was an issue sending the transaction. A successfully sent, but failed transaction will not return an error. If a transaction is successfully sent, the result of the execution of that transaction will be logged. A boolean indicating if a transaction was successfully sent and executed successfully is returned.

func (*ChainClient) SetSDKContext

func (cc *ChainClient) SetSDKContext() func()

SetSDKConfig sets the SDK config to the proper bech32 prefixes Don't use this unless you know what you're doing. if lens is successful, this can be eliminated TODO: :dagger: :knife: :chainsaw: remove this function

func (*ChainClient) ShowAddress

func (cc *ChainClient) ShowAddress(name string) (address string, err error)

func (*ChainClient) TxFactory

func (cc *ChainClient) TxFactory() tx.Factory

func (*ChainClient) TxServiceBroadcast

func (cc *ChainClient) TxServiceBroadcast(ctx context.Context, req *tx.BroadcastTxRequest) (*tx.BroadcastTxResponse, error)

TxServiceBroadcast is a helper function to broadcast a Tx with the correct gRPC types from the tx service. Calls `clientCtx.BroadcastTx` under the hood.

type ChainClientConfig

type ChainClientConfig struct {
	Key            string                  `json:"key" yaml:"key"`
	ChainID        string                  `json:"chain-id" yaml:"chain-id"`
	RPCAddr        string                  `json:"rpc-addr" yaml:"rpc-addr"`
	GRPCAddr       string                  `json:"grpc-addr" yaml:"grpc-addr"`
	AccountPrefix  string                  `json:"account-prefix" yaml:"account-prefix"`
	KeyringBackend string                  `json:"keyring-backend" yaml:"keyring-backend"`
	GasAdjustment  float64                 `json:"gas-adjustment" yaml:"gas-adjustment"`
	GasPrices      string                  `json:"gas-prices" yaml:"gas-prices"`
	KeyDirectory   string                  `json:"key-directory" yaml:"key-directory"`
	Debug          bool                    `json:"debug" yaml:"debug"`
	Timeout        string                  `json:"timeout" yaml:"timeout"`
	BlockTimeout   string                  `json:"block-timeout" yaml:"block-timeout"`
	OutputFormat   string                  `json:"output-format" yaml:"output-format"`
	SignModeStr    string                  `json:"sign-mode" yaml:"sign-mode"`
	Modules        []module.AppModuleBasic `json:"-" yaml:"-"`
}

func GetCosmosHubConfig

func GetCosmosHubConfig(keyHome string, debug bool) *ChainClientConfig

func GetOsmosisConfig

func GetOsmosisConfig(keyHome string, debug bool) *ChainClientConfig

func (*ChainClientConfig) SignMode

func (ccc *ChainClientConfig) SignMode() signing.SignMode

func (*ChainClientConfig) Validate

func (ccc *ChainClientConfig) Validate() error

type Codec

type Codec struct {
	InterfaceRegistry types.InterfaceRegistry
	Marshaler         codec.Codec
	TxConfig          client.TxConfig
	Amino             *codec.LegacyAmino
}

func MakeCodec

func MakeCodec(moduleBasics []module.AppModuleBasic) Codec

func MakeCodecConfig

func MakeCodecConfig() Codec

type KeyOutput

type KeyOutput struct {
	Mnemonic string `json:"mnemonic" yaml:"mnemonic"`
	Address  string `json:"address" yaml:"address"`
}

KeyOutput contains mnemonic and address of key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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