Documentation
¶
Index ¶
- Constants
- func CheckTendermintError(err error, txBytes []byte) *sdk.TxResponse
- func ErrInvalidAccount(addr sdk.AccAddress) error
- func ErrVerifyCommit(height int64) error
- func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddress, string, error)
- func Paginate(numObjs, page, limit, defLimit int) (start, end int)
- func ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error)
- func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error
- func SetCmdClientContextHandler(clientCtx Context, cmd *cobra.Command) (err error)
- func ValidateCmd(cmd *cobra.Command, args []string) error
- type AccountRetriever
- type Context
- func GetClientContextFromCmd(cmd *cobra.Command) Context
- func ReadPersistentCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error)
- func ReadQueryCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error)
- func ReadTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, error)
- func (ctx Context) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error)
- func (ctx Context) BroadcastTxAsync(txBytes []byte) (*sdk.TxResponse, error)
- func (ctx Context) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error)
- func (ctx Context) BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error)
- func (ctx Context) GetFromAddress() sdk.AccAddress
- func (ctx Context) GetFromName() string
- func (ctx Context) GetNode() (rpcclient.Client, error)
- func (ctx Context) Invoke(_ gocontext.Context, method string, args, reply interface{}, ...) error
- func (Context) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error)
- func (ctx Context) PrintOutput(toPrint interface{}) error
- func (ctx Context) Query(path string) ([]byte, int64, error)
- func (ctx Context) QueryABCI(req abci.RequestQuery) (abci.ResponseQuery, error)
- func (ctx Context) QueryStore(key tmbytes.HexBytes, storeName string) ([]byte, int64, error)
- func (ctx Context) QuerySubspace(subspace []byte, storeName string) (res []sdk.KVPair, height int64, err error)
- func (ctx Context) QueryWithData(path string, data []byte) ([]byte, int64, error)
- func (ctx Context) WithAccountRetriever(retriever AccountRetriever) Context
- func (ctx Context) WithBroadcastMode(mode string) Context
- func (ctx Context) WithChainID(chainID string) Context
- func (ctx Context) WithClient(client rpcclient.Client) Context
- func (ctx Context) WithCodec(cdc *codec.Codec) Context
- func (ctx Context) WithFrom(from string) Context
- func (ctx Context) WithFromAddress(addr sdk.AccAddress) Context
- func (ctx Context) WithFromName(name string) Context
- func (ctx Context) WithGenerateOnly(generateOnly bool) Context
- func (ctx Context) WithHeight(height int64) Context
- func (ctx Context) WithHomeDir(dir string) Context
- func (ctx Context) WithInput(r io.Reader) Context
- func (ctx Context) WithInterfaceRegistry(interfaceRegistry codectypes.InterfaceRegistry) Context
- func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context
- func (ctx Context) WithKeyring(k keyring.Keyring) Context
- func (ctx Context) WithNodeURI(nodeURI string) Context
- func (ctx Context) WithOffline(offline bool) Context
- func (ctx Context) WithOutput(w io.Writer) Context
- func (ctx Context) WithOutputFormat(format string) Context
- func (ctx Context) WithSimulation(simulate bool) Context
- func (ctx Context) WithSkipConfirmation(skip bool) Context
- func (ctx Context) WithTxConfig(generator TxConfig) Context
- func (ctx Context) WithUseLedger(useLedger bool) Context
- type NodeQuerier
- type TestAccountRetriever
- type TxBuilder
- type TxConfig
Constants ¶
const ClientContextKey = sdk.ContextKey("client.context")
ClientContextKey defines the context key used to retrieve a client.Context from a command's Context.
Variables ¶
This section is empty.
Functions ¶
func CheckTendermintError ¶
func CheckTendermintError(err error, txBytes []byte) *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 ErrInvalidAccount ¶
func ErrInvalidAccount(addr sdk.AccAddress) error
ErrInvalidAccount returns a standardized error reflecting that a given account address does not exist.
func ErrVerifyCommit ¶
ErrVerifyCommit returns a common error reflecting that the blockchain commit at a given height can't be verified. The reason is that the base checkpoint of the certifier is newer than the given height
func GetFromFields ¶
GetFromFields returns a from account address and Keybase name given either an address or key name. If genOnly is true, only a valid Bech32 cosmos address is returned.
func Paginate ¶
Paginate returns the correct starting and ending index for a paginated query, given that client provides a desired page and limit of objects and the handler provides the total number of objects. The start page is assumed to be 1-indexed. If the start page is invalid, non-positive values are returned signaling the request is invalid; it returns non-positive values if limit is non-positive and defLimit is negative.
func ReadPageRequest ¶
func ReadPageRequest(flagSet *pflag.FlagSet) (*query.PageRequest, error)
ReadPageRequest reads and builds the necessary page request flags for pagination.
func SetCmdClientContext ¶
SetCmdClientContext sets a command's Context value to the provided argument.
func SetCmdClientContextHandler ¶
SetCmdClientContextHandler is to be used in a command pre-hook execution to read flags that populate a Context and sets that to the command's Context.
Types ¶
type AccountRetriever ¶
type AccountRetriever interface { EnsureExists(nodeQuerier NodeQuerier, addr types.AccAddress) error GetAccountNumberSequence(nodeQuerier NodeQuerier, addr types.AccAddress) (accNum uint64, accSeq uint64, err error) }
AccountRetriever defines the interfaces required by transactions to ensure an account exists and to be able to query for account fields necessary for signing.
type Context ¶
type Context struct { FromAddress sdk.AccAddress Client rpcclient.Client ChainID string JSONMarshaler codec.JSONMarshaler InterfaceRegistry codectypes.InterfaceRegistry Input io.Reader Keyring keyring.Keyring Output io.Writer OutputFormat string Height int64 HomeDir string From string BroadcastMode string FromName string UseLedger bool Simulate bool GenerateOnly bool Offline bool SkipConfirm bool TxConfig TxConfig AccountRetriever AccountRetriever NodeURI string // TODO: Deprecated (remove). Codec *codec.Codec }
Context implements a typical context created in SDK modules for transaction handling and queries.
func GetClientContextFromCmd ¶
GetClientContextFromCmd returns a Context from a command or an empty Context if it has not been set.
func ReadPersistentCommandFlags ¶
ReadPersistentCommandFlags returns a Context with fields set for "persistent" flags that do not necessarily change with context. These must be checked if the caller explicitly changed the values.
func ReadQueryCommandFlags ¶
ReadQueryCommandFlags returns an updated Context with fields set based on flags defined in GetCommands. An error is returned if any flag query fails.
Certain flags are naturally command and context dependent, so for these flags we do not check if they've been explicitly set by the caller. Other flags can be considered "persistent" (e.g. KeyBase or Client) and these should be checked if the caller explicitly set those.
func ReadTxCommandFlags ¶
ReadTxCommandFlags returns an updated Context with fields set based on flags defined in PostCommands. An error is returned if any flag query fails.
Certain flags are naturally command and context dependent, so for these flags we do not check if they've been explicitly set by the caller. Other flags can be considered "persistent" (e.g. KeyBase or Client) and these should be checked if the caller explicitly set those.
func (Context) BroadcastTx ¶
func (ctx Context) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error)
BroadcastTx broadcasts a transactions either synchronously or asynchronously based on the context parameters. The result of the broadcast is parsed into an intermediate structure which is logged if the context has a logger defined.
func (Context) BroadcastTxAsync ¶
func (ctx Context) BroadcastTxAsync(txBytes []byte) (*sdk.TxResponse, error)
BroadcastTxAsync broadcasts transaction bytes to a Tendermint node asynchronously (i.e. returns immediately).
func (Context) BroadcastTxCommit ¶
func (ctx Context) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error)
BroadcastTxCommit broadcasts transaction bytes to a Tendermint node and waits for a commit. An error is only returned if there is no RPC node connection or if broadcasting fails.
NOTE: This should ideally not be used as the request may timeout but the tx may still be included in a block. Use BroadcastTxAsync or BroadcastTxSync instead.
func (Context) BroadcastTxSync ¶
func (ctx Context) BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error)
BroadcastTxSync broadcasts transaction bytes to a Tendermint node synchronously (i.e. returns after CheckTx execution).
func (Context) GetFromAddress ¶
func (ctx Context) GetFromAddress() sdk.AccAddress
GetFromAddress returns the from address from the context's name.
func (Context) GetFromName ¶
GetFromName returns the key name for the current context.
func (Context) GetNode ¶
GetNode returns an RPC client. If the context's client is not defined, an error is returned.
func (Context) Invoke ¶
func (ctx Context) Invoke(_ gocontext.Context, method string, args, reply interface{}, _ ...grpc.CallOption) error
Invoke implements the grpc ClientConn.Invoke method
func (Context) NewStream ¶
func (Context) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error)
NewStream implements the grpc ClientConn.NewStream method
func (Context) PrintOutput ¶
PrintOutput outputs toPrint to the ctx.Output based on ctx.OutputFormat which is either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure.
func (Context) Query ¶
Query performs a query to a Tendermint node with the provided path. It returns the result and height of the query upon success or an error if the query fails.
func (Context) QueryABCI ¶
func (ctx Context) QueryABCI(req abci.RequestQuery) (abci.ResponseQuery, error)
QueryABCI performs a query to a Tendermint node with the provide RequestQuery. It returns the ResultQuery obtained from the query.
func (Context) QueryStore ¶
QueryStore performs a query to a Tendermint node with the provided key and store name. It returns the result and height of the query upon success or an error if the query fails.
func (Context) QuerySubspace ¶
func (ctx Context) QuerySubspace(subspace []byte, storeName string) (res []sdk.KVPair, height int64, err error)
QuerySubspace performs a query to a Tendermint node with the provided store name and subspace. It returns key value pair and height of the query upon success or an error if the query fails.
func (Context) QueryWithData ¶
QueryWithData performs a query to a Tendermint node with the provided path and a data payload. It returns the result and height of the query upon success or an error if the query fails.
func (Context) WithAccountRetriever ¶
func (ctx Context) WithAccountRetriever(retriever AccountRetriever) Context
WithAccountRetriever returns the context with an updated AccountRetriever
func (Context) WithBroadcastMode ¶
WithBroadcastMode returns a copy of the context with an updated broadcast mode.
func (Context) WithChainID ¶
WithChainID returns a copy of the context with an updated chain ID.
func (Context) WithClient ¶
WithClient returns a copy of the context with an updated RPC client instance.
func (Context) WithCodec ¶
WithCodec returns a copy of the context with an updated codec. TODO: Deprecated (remove).
func (Context) WithFrom ¶
WithFrom returns a copy of the context with an updated from address or name.
func (Context) WithFromAddress ¶
func (ctx Context) WithFromAddress(addr sdk.AccAddress) Context
WithFromAddress returns a copy of the context with an updated from account address.
func (Context) WithFromName ¶
WithFromName returns a copy of the context with an updated from account name.
func (Context) WithGenerateOnly ¶
WithGenerateOnly returns a copy of the context with updated GenerateOnly value
func (Context) WithHeight ¶
WithHeight returns a copy of the context with an updated height.
func (Context) WithHomeDir ¶
WithHomeDir returns a copy of the Context with HomeDir set.
func (Context) WithInterfaceRegistry ¶
func (ctx Context) WithInterfaceRegistry(interfaceRegistry codectypes.InterfaceRegistry) Context
WithInterfaceRegistry returns the context with an updated InterfaceRegistry
func (Context) WithJSONMarshaler ¶
func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context
WithJSONMarshaler returns a copy of the Context with an updated JSONMarshaler.
func (Context) WithKeyring ¶
WithKeyring returns a copy of the context with an updated keyring.
func (Context) WithNodeURI ¶
WithNodeURI returns a copy of the context with an updated node URI.
func (Context) WithOffline ¶
WithOffline returns a copy of the context with updated Offline value.
func (Context) WithOutput ¶
WithOutput returns a copy of the context with an updated output writer (e.g. stdout).
func (Context) WithOutputFormat ¶
WithOutputFormat returns a copy of the context with an updated OutputFormat field.
func (Context) WithSimulation ¶
WithSimulation returns a copy of the context with updated Simulate value
func (Context) WithSkipConfirmation ¶
WithSkipConfirmation returns a copy of the context with an updated SkipConfirm value.
func (Context) WithTxConfig ¶
WithTxConfig returns the context with an updated TxConfig
func (Context) WithUseLedger ¶
WithUseLedger returns a copy of the context with an updated UseLedger flag.
type NodeQuerier ¶
type NodeQuerier interface { // QueryWithData performs a query to a Tendermint node with the provided path // and a data payload. It returns the result and height of the query upon success // or an error if the query fails. QueryWithData(path string, data []byte) ([]byte, int64, error) }
NodeQuerier is an interface that is satisfied by types that provide the QueryWithData method
type TestAccountRetriever ¶
type TestAccountRetriever struct { Accounts map[string]struct { Address sdk.AccAddress Num uint64 Seq uint64 } }
TestAccountRetriever is an AccountRetriever that can be used in unit tests
func (TestAccountRetriever) EnsureExists ¶
func (t TestAccountRetriever) EnsureExists(_ NodeQuerier, addr sdk.AccAddress) error
EnsureExists implements AccountRetriever.EnsureExists
func (TestAccountRetriever) GetAccountNumberSequence ¶
func (t TestAccountRetriever) GetAccountNumberSequence(_ NodeQuerier, addr sdk.AccAddress) (accNum uint64, accSeq uint64, err error)
GetAccountNumberSequence implements AccountRetriever.GetAccountNumberSequence
type TxBuilder ¶
type TxBuilder interface { GetTx() signing.SigFeeMemoTx SetMsgs(msgs ...sdk.Msg) error SetSignatures(signatures ...signingtypes.SignatureV2) error SetMemo(memo string) SetFeeAmount(amount sdk.Coins) SetGasLimit(limit uint64) }
TxBuilder defines an interface which an application-defined concrete transaction type must implement. Namely, it must be able to set messages, generate signatures, and provide canonical bytes to sign over. The transaction must also know how to encode itself.
type TxConfig ¶
type TxConfig interface { NewTxBuilder() TxBuilder WrapTxBuilder(sdk.Tx) (TxBuilder, error) SignModeHandler() signing.SignModeHandler TxEncoder() sdk.TxEncoder TxDecoder() sdk.TxDecoder TxJSONEncoder() sdk.TxEncoder TxJSONDecoder() sdk.TxDecoder }
TxConfig defines an interface a client can utilize to generate an application-defined concrete transaction type. The type returned must implement TxBuilder.