tx

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: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastTx added in v1.0.0

func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error

BroadcastTx attempts to generate, sign and broadcast a transaction with the given set of messages. It will also simulate gas requirements if necessary. It will return an error upon failure.

func BuildSimTx added in v1.0.0

func BuildSimTx(txf 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 CalculateGas added in v1.0.0

func CalculateGas(
	queryFunc func(string, []byte) ([]byte, int64, error), txf Factory, msgs ...sdk.Msg,
) (sdk.SimulationResponse, uint64, error)

CalculateGas simulates the execution of a transaction and returns the simulation response obtained by the query and the adjusted gas amount.

func GenerateOrBroadcastTx added in v1.0.0

func GenerateOrBroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error

GenerateOrBroadcastTx will either generate and print and unsigned transaction or sign it and broadcast it returning an error upon failure.

func GenerateTx added in v1.0.0

func GenerateTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error

GenerateTx will generate an unsigned transaction and print it to the writer specified by ctx.Output. If simulation was requested, the gas will be simulated and also printed to the same writer before the transaction is printed.

func Sign added in v1.0.0

func Sign(txf Factory, name, passphrase string, tx ClientTx) ([]byte, error)

Sign signs a given tx with the provided name and passphrase. If the Factory's Keybase is not set, a new one will be created based on the client's backend. The bytes signed over are canconical. The resulting signature will be set on the transaction. Finally, the marshaled transaction is returned. An error is returned upon failure.

Note, It is assumed the Factory has the necessary fields set that are required by the CanonicalSignBytes call.

func WriteGeneratedTxResponse added in v1.0.0

func WriteGeneratedTxResponse(
	ctx context.CLIContext, w http.ResponseWriter, txg Generator, br rest.BaseReq, msgs ...sdk.Msg,
)

WriteGeneratedTxResponse writes a generated unsigned transaction to the provided http.ResponseWriter. It will simulate gas costs if requested by the BaseReq. Upon any error, the error will be written to the http.ResponseWriter.

Types

type AccountRetriever added in v1.0.0

type AccountRetriever interface {
	EnsureExists(addr sdk.AccAddress) error
	GetAccountNumberSequence(addr sdk.AccAddress) (uint64, uint64, error)
}

AccountRetriever defines the interfaces required for use by the Factory to ensure an account exists and to be able to query for account fields necessary for signing.

type ClientFee added in v1.0.0

type ClientFee interface {
	sdk.Fee
	SetGas(uint64)
	SetAmount(sdk.Coins)
}

type ClientSignature added in v1.0.0

type ClientSignature interface {
	sdk.Signature
	SetPubKey(crypto.PubKey) error
	SetSignature([]byte)
}

type ClientTx added in v1.0.0

type ClientTx interface {
	sdk.Tx
	codec.ProtoMarshaler

	SetMsgs(...sdk.Msg) error
	GetSignatures() []sdk.Signature
	SetSignatures(...ClientSignature) error
	GetFee() sdk.Fee
	SetFee(ClientFee) error
	GetMemo() string
	SetMemo(string)

	// CanonicalSignBytes returns the canonical JSON bytes to sign over, given a
	// chain ID, along with an account and sequence number. The JSON encoding
	// ensures all field names adhere to their proto definition, default values
	// are omitted, and follows the JSON Canonical Form.
	CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error)
}

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

func BuildUnsignedTx added in v1.0.0

func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error)

BuildUnsignedTx builds a transaction to be signed given a set of messages. The transaction is initially created via the provided factory's generator. Once created, the fee, memo, and messages are set.

type Factory added in v1.0.0

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

Factory defines a client transaction factory that facilitates generating and signing an application-specific transaction.

func NewFactoryFromCLI added in v1.0.0

func NewFactoryFromCLI(input io.Reader) Factory

func PrepareFactory added in v1.0.0

func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error)

PrepareFactory ensures the account defined by ctx.GetFromAddress() exists and if the account number and/or the account sequence number are zero (not set), they will be queried for and set on the provided Factory. A new Factory with the updated fields will be returned.

func (Factory) AccountNumber added in v1.0.0

func (f Factory) AccountNumber() uint64

func (Factory) AccountRetriever added in v1.0.0

func (f Factory) AccountRetriever() AccountRetriever

func (Factory) ChainID added in v1.0.0

func (f Factory) ChainID() string

func (Factory) Fees added in v1.0.0

func (f Factory) Fees() sdk.Coins

func (Factory) Gas added in v1.0.0

func (f Factory) Gas() uint64

func (Factory) GasAdjustment added in v1.0.0

func (f Factory) GasAdjustment() float64

func (Factory) GasPrices added in v1.0.0

func (f Factory) GasPrices() sdk.DecCoins

func (Factory) Keybase added in v1.0.0

func (f Factory) Keybase() keyring.Keyring

func (Factory) Memo added in v1.0.0

func (f Factory) Memo() string

func (Factory) Sequence added in v1.0.0

func (f Factory) Sequence() uint64

func (Factory) SimulateAndExecute added in v1.0.0

func (f Factory) SimulateAndExecute() bool

SimulateAndExecute returns the option to simulate and then execute the transaction using the gas from the simulation results

func (Factory) WithAccountNumber added in v1.0.0

func (f Factory) WithAccountNumber(accnum uint64) Factory

WithAccountNumber returns a copy of the Factory with an updated account number.

func (Factory) WithAccountRetriever added in v1.0.0

func (f Factory) WithAccountRetriever(ar AccountRetriever) Factory

WithAccountRetriever returns a copy of the Factory with an updated AccountRetriever.

func (Factory) WithChainID added in v1.0.0

func (f Factory) WithChainID(chainID string) Factory

WithChainID returns a copy of the Factory with an updated chainID.

func (Factory) WithFees added in v1.0.0

func (f Factory) WithFees(fees string) Factory

WithFees returns a copy of the Factory with an updated fee.

func (Factory) WithGas added in v1.0.0

func (f Factory) WithGas(gas uint64) Factory

WithGas returns a copy of the Factory with an updated gas value.

func (Factory) WithGasAdjustment added in v1.0.0

func (f Factory) WithGasAdjustment(gasAdj float64) Factory

WithGasAdjustment returns a copy of the Factory with an updated gas adjustment.

func (Factory) WithGasPrices added in v1.0.0

func (f Factory) WithGasPrices(gasPrices string) Factory

WithGasPrices returns a copy of the Factory with updated gas prices.

func (Factory) WithKeybase added in v1.0.0

func (f Factory) WithKeybase(keybase keyring.Keyring) Factory

WithKeybase returns a copy of the Factory with updated Keybase.

func (Factory) WithMemo added in v1.0.0

func (f Factory) WithMemo(memo string) Factory

WithMemo returns a copy of the Factory with an updated memo.

func (Factory) WithSequence added in v1.0.0

func (f Factory) WithSequence(sequence uint64) Factory

WithSequence returns a copy of the Factory with an updated sequence number.

func (Factory) WithSimulateAndExecute added in v1.0.0

func (f Factory) WithSimulateAndExecute(sim bool) Factory

WithSimulateAndExecute returns a copy of the Factory with an updated gas simulation value.

func (Factory) WithTxGenerator added in v1.0.0

func (f Factory) WithTxGenerator(g Generator) Factory

WithTxGenerator returns a copy of the Factory with an updated Generator.

type GasEstimateResponse added in v1.0.0

type GasEstimateResponse struct {
	GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"`
}

GasEstimateResponse defines a response definition for tx gas estimation.

func (GasEstimateResponse) String added in v1.0.0

func (gr GasEstimateResponse) String() string

type Generator added in v1.0.0

type Generator interface {
	NewTx() ClientTx
	NewFee() ClientFee
	NewSignature() ClientSignature
}

Generator defines an interface a client can utilize to generate an application-defined concrete transaction type. The type returned must implement ClientTx.

Jump to

Keyboard shortcuts

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