context

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultVerifierCacheSize defines the default Tendermint cache size.
	DefaultVerifierCacheSize = 10
)

Variables

This section is empty.

Functions

func CheckTendermintError added in v1.0.0

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 CreateVerifier added in v1.0.0

func CreateVerifier(ctx CLIContext, cacheSize int) (tmlite.Verifier, error)

CreateVerifier returns a Tendermint verifier from a CLIContext object and cache size. An error is returned if the CLIContext is missing required values or if the verifier could not be created. A CLIContext must at the very least have the chain ID and home directory set. If the CLIContext has TrustNode enabled, no verifier will be created.

func ErrInvalidAccount added in v0.24.0

func ErrInvalidAccount(addr sdk.AccAddress) error

ErrInvalidAccount returns a standardized error reflecting that a given account address does not exist.

func ErrVerifyCommit added in v0.25.0

func ErrVerifyCommit(height int64) error

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 added in v0.31.0

func GetFromFields(kr keyring.Keyring, from string, genOnly bool) (sdk.AccAddress, string, error)

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.

Types

type CLIContext added in v0.24.0

type CLIContext struct {
	FromAddress   sdk.AccAddress
	Client        rpcclient.Client
	ChainID       string
	Marshaler     codec.Marshaler
	Input         io.Reader
	Keyring       keyring.Keyring
	Output        io.Writer
	OutputFormat  string
	Height        int64
	HomeDir       string
	NodeURI       string
	From          string
	BroadcastMode string
	Verifier      tmlite.Verifier
	FromName      string
	TrustNode     bool
	UseLedger     bool
	Simulate      bool
	GenerateOnly  bool
	Offline       bool
	Indent        bool
	SkipConfirm   bool

	// TODO: Deprecated (remove).
	Codec *codec.Codec
}

CLIContext implements a typical CLI context created in SDK modules for transaction handling and queries.

func NewCLIContext added in v0.24.0

func NewCLIContext() CLIContext

NewCLIContext returns a new initialized CLIContext with parameters from the command line using Viper.

func NewCLIContextWithFrom added in v1.0.0

func NewCLIContextWithFrom(from string) CLIContext

NewCLIContextWithFrom returns a new initialized CLIContext with parameters from the command line using Viper. It takes a key name or address and populates the FromName and FromAddress field accordingly. It will also create Tendermint verifier using the chain ID, home directory and RPC URI provided by the command line. If using a CLIContext in tests or any non CLI-based environment, the verifier will not be created and will be set as nil because FlagTrustNode must be set.

func NewCLIContextWithInput added in v1.0.0

func NewCLIContextWithInput(input io.Reader) CLIContext

NewCLIContextWithInput returns a new initialized CLIContext with a io.Reader and parameters from the command line using Viper.

func NewCLIContextWithInputAndFrom added in v1.0.0

func NewCLIContextWithInputAndFrom(input io.Reader, from string) CLIContext

NewCLIContextWithInputAndFrom returns a new initialized CLIContext with parameters from the command line using Viper. It takes a io.Reader and and key name or address and populates the FromName and FromAddress field accordingly. It will also create Tendermint verifier using the chain ID, home directory and RPC URI provided by the command line. If using a CLIContext in tests or any non CLI-based environment, the verifier will not be created and will be set as nil because FlagTrustNode must be set.

func (CLIContext) BroadcastTx added in v0.24.0

func (ctx CLIContext) 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 (CLIContext) BroadcastTxAsync added in v0.24.0

func (ctx CLIContext) BroadcastTxAsync(txBytes []byte) (sdk.TxResponse, error)

BroadcastTxAsync broadcasts transaction bytes to a Tendermint node asynchronously (i.e. returns immediately).

func (CLIContext) BroadcastTxCommit added in v1.0.0

func (ctx CLIContext) 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 (CLIContext) BroadcastTxSync added in v0.25.0

func (ctx CLIContext) BroadcastTxSync(txBytes []byte) (sdk.TxResponse, error)

BroadcastTxSync broadcasts transaction bytes to a Tendermint node synchronously (i.e. returns after CheckTx execution).

func (CLIContext) GetFromAddress added in v0.24.0

func (ctx CLIContext) GetFromAddress() sdk.AccAddress

GetFromAddress returns the from address from the context's name.

func (CLIContext) GetFromName added in v0.25.0

func (ctx CLIContext) GetFromName() string

GetFromName returns the key name for the current context.

func (CLIContext) GetNode added in v0.24.0

func (ctx CLIContext) GetNode() (rpcclient.Client, error)

GetNode returns an RPC client. If the context's client is not defined, an error is returned.

func (CLIContext) PrintOutput added in v0.30.0

func (ctx CLIContext) PrintOutput(toPrint interface{}) error

PrintOutput prints output while respecting output and indent flags NOTE: pass in marshalled structs that have been unmarshaled because this function will panic on marshaling errors.

TODO: Remove once client-side Protobuf migration has been completed. ref: https://github.com/KiraCore/cosmos-sdk/issues/5864

func (CLIContext) Println added in v1.0.0

func (ctx CLIContext) Println(toPrint interface{}) error

Println 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.Marshaler. An error is returned upon failure.

func (CLIContext) Query added in v0.24.0

func (ctx CLIContext) Query(path string) ([]byte, int64, error)

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 (CLIContext) QueryABCI added in v1.0.0

func (ctx CLIContext) 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 (CLIContext) QueryStore added in v0.24.0

func (ctx CLIContext) QueryStore(key tmbytes.HexBytes, storeName string) ([]byte, int64, error)

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 (CLIContext) QuerySubspace added in v0.24.0

func (ctx CLIContext) 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 (CLIContext) QueryWithData added in v0.25.0

func (ctx CLIContext) QueryWithData(path string, data []byte) ([]byte, int64, error)

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 (CLIContext) Verify added in v0.25.0

func (ctx CLIContext) Verify(height int64) (tmtypes.SignedHeader, error)

Verify verifies the consensus proof at given height.

func (CLIContext) WithBroadcastMode added in v1.0.0

func (ctx CLIContext) WithBroadcastMode(mode string) CLIContext

WithBroadcastMode returns a copy of the context with an updated broadcast mode.

func (CLIContext) WithChainID added in v1.0.0

func (ctx CLIContext) WithChainID(chainID string) CLIContext

WithChainID returns a copy of the context with an updated chain ID.

func (CLIContext) WithClient added in v0.24.0

func (ctx CLIContext) WithClient(client rpcclient.Client) CLIContext

WithClient returns a copy of the context with an updated RPC client instance.

func (CLIContext) WithCodec added in v0.24.0

func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext

WithCodec returns a copy of the context with an updated codec. TODO: Deprecated (remove).

func (CLIContext) WithFrom added in v0.25.0

func (ctx CLIContext) WithFrom(from string) CLIContext

WithFrom returns a copy of the context with an updated from address or name.

func (CLIContext) WithFromAddress added in v0.31.0

func (ctx CLIContext) WithFromAddress(addr sdk.AccAddress) CLIContext

WithFromAddress returns a copy of the context with an updated from account address.

func (CLIContext) WithFromName added in v0.31.0

func (ctx CLIContext) WithFromName(name string) CLIContext

WithFromName returns a copy of the context with an updated from account name.

func (CLIContext) WithGenerateOnly added in v0.28.1

func (ctx CLIContext) WithGenerateOnly(generateOnly bool) CLIContext

WithGenerateOnly returns a copy of the context with updated GenerateOnly value

func (CLIContext) WithHeight added in v1.0.0

func (ctx CLIContext) WithHeight(height int64) CLIContext

WithHeight returns a copy of the context with an updated height.

func (CLIContext) WithInput added in v1.0.0

func (ctx CLIContext) WithInput(r io.Reader) CLIContext

WithInput returns a copy of the context with an updated input.

func (CLIContext) WithKeyring added in v1.0.0

func (ctx CLIContext) WithKeyring(k keyring.Keyring) CLIContext

WithKeyring returns a copy of the context with an updated keyring.

func (CLIContext) WithMarshaler added in v1.0.0

func (ctx CLIContext) WithMarshaler(m codec.Marshaler) CLIContext

WithMarshaler returns a copy of the CLIContext with an updated Marshaler.

func (CLIContext) WithNodeURI added in v0.24.0

func (ctx CLIContext) WithNodeURI(nodeURI string) CLIContext

WithNodeURI returns a copy of the context with an updated node URI.

func (CLIContext) WithOutput added in v0.25.0

func (ctx CLIContext) WithOutput(w io.Writer) CLIContext

WithOutput returns a copy of the context with an updated output writer (e.g. stdout).

func (CLIContext) WithSimulation added in v0.28.1

func (ctx CLIContext) WithSimulation(simulate bool) CLIContext

WithSimulation returns a copy of the context with updated Simulate value

func (CLIContext) WithTrustNode added in v0.24.0

func (ctx CLIContext) WithTrustNode(trustNode bool) CLIContext

WithTrustNode returns a copy of the context with an updated TrustNode flag.

func (CLIContext) WithUseLedger added in v0.24.0

func (ctx CLIContext) WithUseLedger(useLedger bool) CLIContext

WithUseLedger returns a copy of the context with an updated UseLedger flag.

func (CLIContext) WithVerifier added in v0.25.0

func (ctx CLIContext) WithVerifier(verifier tmlite.Verifier) CLIContext

WithVerifier returns a copy of the context with an updated Verifier.

Jump to

Keyboard shortcuts

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