client

package
v0.0.0-...-8cda47c Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 64 Imported by: 0

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}
	// SupportedAlgorithmsLedger defines the list of signing algorithms used on Evmos for the Ledger device:
	//  - secp256k1     (Cosmos)
	//  - eth_secp256k1 (Ethereum)
	SupportedAlgorithmsLedger = keyring.SigningAlgoList{hd.Secp256k1}
)

Functions

func BroadcastTx

func BroadcastTx(ctx context.Context, broadcaster *Broadcaster, broadcastingUser User, msgs ...sdk.Msg) (sdk.TxResponse, error)

BroadcastTx uses the provided Broadcaster to broadcast all the provided messages which will be signed by the User provided. The sdk.TxResponse and an error are returned.

func BuildSimTx

func BuildSimTx(info *keyring.Record, 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 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 HealthChecks

func HealthChecks(chainClients ...*ChainClient)

HealthChecks will continuously check the liveness of each of the given ChainClients. If a ChainClient's RPC node is active, chainClient.IsActive() will return true.

func LensKeyringAlgoOptions

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 SetHeightOnContext

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

func SetProveOnContext

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

Types

type Broadcaster

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

func NewBroadcaster

func NewBroadcaster(cl *ChainClient) *Broadcaster

NewBroadcaster returns a instance of Broadcaster which can be used with broadcast.Tx to broadcast messages sdk messages.

func (*Broadcaster) ConfigureClientContextOptions

func (b *Broadcaster) ConfigureClientContextOptions(opts ...ClientContextOpt)

ConfigureClientContextOptions ensure the given configuration functions are run when calling GetClientContext after all default options have been applied.

func (*Broadcaster) ConfigureFactoryOptions

func (b *Broadcaster) ConfigureFactoryOptions(opts ...FactoryOpt)

ConfigureFactoryOptions ensure the given configuration functions are run when calling GetFactory after all default options have been applied.

func (*Broadcaster) GetClientContext

func (b *Broadcaster) GetClientContext(ctx context.Context, user User) (client.Context, error)

GetClientContext returns a client context that is configured with this Broadcaster's CosmosChain and the provided user. ConfigureClientContextOptions can be used to configure arbitrary options to configure the returned client.Context.

func (*Broadcaster) GetFactory

func (b *Broadcaster) GetFactory(ctx context.Context, user User) (tx.Factory, error)

GetFactory returns an instance of tx.Factory that is configured with this Broadcaster's CosmosChain and the provided user. ConfigureFactoryOptions can be used to specify arbitrary options to configure the returned factory.

func (*Broadcaster) GetTxResponseBytes

func (b *Broadcaster) GetTxResponseBytes(ctx context.Context, user User) ([]byte, error)

GetTxResponseBytes returns the sdk.TxResponse bytes which returned from broadcast.Tx.

func (*Broadcaster) UnmarshalTxResponseBytes

func (b *Broadcaster) UnmarshalTxResponseBytes(ctx context.Context, bytes []byte) (sdk.TxResponse, error)

UnmarshalTxResponseBytes accepts the sdk.TxResponse bytes and unmarshalls them into an instance of sdk.TxResponse.

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 NewChainClientWithRootKeyDir

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

Chain client where keys are in 'rootKeyDirectory/keyring-test' (or whichever keyring-backend is chosen)

func (*ChainClient) AccountFromKeyOrAddress

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) CalculateGas

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

func (*ChainClient) CliContext

func (cc *ChainClient) CliContext() client.Context

CliContext creates a new Cosmos SDK client context

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) GetIbcConfig

func (c *ChainClient) GetIbcConfig(destChain string) (registry.IbcConfig, error)

Get the IBC configuration where this chain is the source and destChain is the IBC endpoint.

func (*ChainClient) GetIbcTransferConfig

func (c *ChainClient) GetIbcTransferConfig(destChain string) (srcChannel, srcPort, clientId string, err error)

func (*ChainClient) GetKeyAddress

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

func (*ChainClient) HandleAndPrintMsgSend

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

func (*ChainClient) Init

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) IsActive

func (cc *ChainClient) IsActive() bool

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

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

func (*ChainClient) MustEncodeValAddr

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) QueryDelegatorValidators

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

func (*ChainClient) QueryDenomsMetadata

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) QueryLatestHeight

func (cc *ChainClient) QueryLatestHeight(ctx context.Context) (int64, error)

func (*ChainClient) QueryTotalSupply

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

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

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, memo string) (*sdk.TxResponse, error)

func (*ChainClient) SendMsgs

func (cc *ChainClient) SendMsgs(ctx context.Context, msgs []sdk.Msg, memo string) (*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 {
	ChainName      string                  `json:"-" yaml:"-"`
	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"`
	MinGasAmount   uint64                  `json:"min-gas-amount" yaml:"min-gas-amount"`
	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"`
	ExtraCodecs    []string                `json:"extra-codecs" yaml:"extra-codecs"`
	Modules        []module.AppModuleBasic `json:"-" yaml:"-"`
	Slip44         int                     `json:"slip44" yaml:"slip44"`
}

func GetChain

func GetChain(ctx context.Context, chainName string, logger *zap.Logger, options *ChainConfigOptions) (*ChainClientConfig, error)

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 ChainConfigOptions

type ChainConfigOptions struct {
	PreferredRpcHosts   []string
	PreferredRpcDomains []string
}

type ClientContextOpt

type ClientContextOpt func(clientContext client.Context) client.Context

type Codec

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

func MakeCodec

func MakeCodec(moduleBasics []module.AppModuleBasic, extraCodecs []string, accBech32Prefix, valBech32Prefix string) Codec

func MakeCodecConfig

func MakeCodecConfig(accBech32Prefix, valBech32Prefix string) Codec

type FactoryOpt

type FactoryOpt func(factory tx.Factory) tx.Factory

type KeyOutput

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

KeyOutput contains mnemonic and address of key

type User

type User interface {
	KeyName() string
	FormattedAddress() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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