util

package
v0.0.0-...-3fe421b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 10 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompleteAndBroadcastTxCLI

func CompleteAndBroadcastTxCLI(txBldr auth.TxBuilder, cliCtx CLIContext, msgs sdk.ProtoMsg, legacyCodec bool) (*sdk.TxResponse, error)

CompleteAndBroadcastTxCLI implements a utility function that facilitates sending a series of messages in a signed transaction given a TxBuilder and a QueryContext. It ensures that the account exists, has a proper number and sequence set. In addition, it builds and signs a transaction with the supplied messages. Finally, it broadcasts the signed transaction to a node.

func Paginate

func Paginate(numObjs, page, limit, defLimit int) (start, end int)

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. If the start page is invalid, non-positive values are returned signaling the request is invalid.

NOTE: The start page is assumed to be 1-indexed.

func PrepareTxBuilder

func PrepareTxBuilder(txBldr auth.TxBuilder, cliCtx CLIContext) (auth.TxBuilder, error)

PrepareTxBuilder populates a TxBuilder in preparation for the build of a Tx.

Types

type BroadcastType

type BroadcastType int
const (
	BroadcastSync BroadcastType = iota + 1
	BroadcastAsync
	BroadcastBlock
)

type CLIContext

type CLIContext struct {
	Codec         *codec.Codec
	Client        rpcclient.Client
	FromAddress   sdk.Address
	Passphrase    string
	Height        int64
	BroadcastMode BroadcastType
	PrivateKey    crypto.PrivateKey
}

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

func NewCLIContext

func NewCLIContext(node rpcclient.Client, fromAddress sdk.Address, passphrase string) CLIContext

NewCLIContext 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.

func (CLIContext) BroadcastTx

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

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

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

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

func (ctx CLIContext) EnsureExists(addr sdk.Address) error

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

func (CLIContext) GetAccount

func (ctx CLIContext) GetAccount(addr sdk.Address) (exported.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 (CLIContext) GetAccountWithHeight

func (ctx CLIContext) GetAccountWithHeight(addr sdk.Address) (exported.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 (CLIContext) GetFromAddress

func (ctx CLIContext) GetFromAddress() sdk.Address

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

func (CLIContext) GetNode

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

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

func (ctx CLIContext) QueryStore(key bytes.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) QueryWithData

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

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

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

func (CLIContext) WithCodec

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

WithCodec returns a copy of the context with an updated codec.

func (CLIContext) WithFromAddress

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

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

func (CLIContext) WithHeight

func (ctx CLIContext) WithHeight(height int64) CLIContext

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

Jump to

Keyboard shortcuts

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