Documentation
¶
Index ¶
- Constants
- func BroadcastTx(ctx context.Context, txf Factory, broadcaster broadcast.Broadcaster) ([]byte, error)
- func DryRun(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
- func GenerateAndBroadcastTxCLI(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
- func GenerateAndBroadcastTxCLIWithBroadcaster(ctx context.Context, conn grpc.ClientConn, broadcaster broadcast.Broadcaster, ...) ([]byte, error)
- func GenerateAndBroadcastTxCLIWithPrompt(ctx context.Context, conn grpc.ClientConn, prompt func([]byte) (bool, error), ...) ([]byte, error)
- func GenerateOnly(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
- func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (proto.Message, error)
- type AccountConfig
- type ConfigOptions
- type Decoder
- type ExecutionOptions
- type Factory
- func (f *Factory) BuildSimTx(msgs ...transaction.Msg) ([]byte, error)
- func (f *Factory) BuildUnsignedTx(msgs ...transaction.Msg) error
- func (f *Factory) BuildsSignedTx(ctx context.Context, msgs ...transaction.Msg) (Tx, error)
- func (f *Factory) Simulate(msgs ...transaction.Msg) (*apitx.SimulateResponse, uint64, error)
- func (f *Factory) UnsignedTxString(msgs ...transaction.Msg) (string, error)
- func (f *Factory) WithAccountNumber(accnum uint64)
- func (f *Factory) WithGas(gas uint64)
- func (f *Factory) WithSequence(sequence uint64)
- type FeeConfig
- type GasConfig
- type GasEstimateResponse
- type HasValidateBasic
- type MultiSignatureData
- type Signature
- type SignatureData
- type SingleSignatureData
- type Tx
- type TxConfig
- type TxEncodingConfig
- type TxParameters
- type TxSigningConfig
Constants ¶
const ( FlagTimeoutTimestamp = "timeout-timestamp" FlagChainID = "chain-id" FlagNote = "note" FlagSignMode = "sign-mode" FlagAccountNumber = "account-number" FlagSequence = "sequence" FlagFrom = "from" FlagDryRun = "dry-run" FlagGas = "gas" FlagGasAdjustment = "gas-adjustment" FlagGasPrices = "gas-prices" FlagFees = "fees" FlagFeePayer = "fee-payer" FlagFeeGranter = "fee-granter" FlagUnordered = "unordered" FlagOffline = "offline" FlagGenerateOnly = "generate-only" )
Flag constants for transaction-related flags
Variables ¶
This section is empty.
Functions ¶
func BroadcastTx ¶
func BroadcastTx(ctx context.Context, txf Factory, broadcaster broadcast.Broadcaster) ([]byte, error)
BroadcastTx attempts to sign and broadcast a transaction using the provided factory and broadcaster. GenerateTx must be called first to prepare the transaction for signing. This function then signs the transaction using the factory's signing capabilities, encodes it, and finally broadcasts it using the provided broadcaster.
func DryRun ¶
func DryRun(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
DryRun simulates a transaction without broadcasting it to the network. It initializes a transaction factory using the provided context, connection and messages, then performs a dry run simulation of the transaction. Returns the simulation response bytes and any error encountered.
func GenerateAndBroadcastTxCLI ¶
func GenerateAndBroadcastTxCLI(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
GenerateAndBroadcastTxCLI will either generate and print an unsigned transaction or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure.
func GenerateAndBroadcastTxCLIWithBroadcaster ¶
func GenerateAndBroadcastTxCLIWithBroadcaster( ctx context.Context, conn grpc.ClientConn, broadcaster broadcast.Broadcaster, msgs ...transaction.Msg, ) ([]byte, error)
GenerateAndBroadcastTxCLIWithBroadcaster will either generate and print an unsigned transaction or sign it and broadcast it with the specified broadcaster returning an error upon failure.
func GenerateAndBroadcastTxCLIWithPrompt ¶
func GenerateAndBroadcastTxCLIWithPrompt( ctx context.Context, conn grpc.ClientConn, prompt func([]byte) (bool, error), msgs ...transaction.Msg, ) ([]byte, error)
GenerateAndBroadcastTxCLIWithPrompt generates, signs and broadcasts a transaction after prompting the user for confirmation. It takes a context, gRPC client connection, prompt function for user confirmation, and transaction messages. The prompt function receives the unsigned transaction bytes and returns a boolean indicating user confirmation and any error. Returns the broadcast response bytes and any error encountered.
func GenerateOnly ¶
func GenerateOnly(ctx context.Context, conn grpc.ClientConn, msgs ...transaction.Msg) ([]byte, error)
GenerateOnly generates an unsigned transaction without broadcasting it. It initializes a transaction factory using the provided context, connection and messages, then generates an unsigned transaction. Returns the unsigned transaction bytes and any error encountered.
func SimulateTx ¶
func SimulateTx(ctx clientcontext.Context, conn grpc.ClientConn, msgs ...transaction.Msg) (proto.Message, error)
SimulateTx simulates a tx and returns the simulation response obtained by the query.
Types ¶
type AccountConfig ¶
type AccountConfig struct { // accountNumber is the unique identifier for the account. AccountNumber uint64 // sequence is the sequence number of the transaction. Sequence uint64 // fromName is the name of the account sending the transaction. FromName string // fromAddress is the address of the account sending the transaction. FromAddress string // address is the byte representation of the account address. Address []byte }
AccountConfig defines the 'account' related fields in a transaction.
type ConfigOptions ¶
type ConfigOptions struct { AddressCodec address.Codec Decoder Decoder Cdc codec.BinaryCodec ValidatorAddressCodec address.Codec FileResolver signing.ProtoFileResolver TypeResolver signing.TypeResolver CustomGetSigner map[protoreflect.FullName]signing.GetSignersFunc MaxRecursionDepth int EnabledSignModes []apitxsigning.SignMode CustomSignModes []signing.SignModeHandler TextualCoinMetadataQueryFn textual.CoinMetadataQueryFn }
ConfigOptions defines the configuration options for transaction processing.
type ExecutionOptions ¶
type ExecutionOptions struct {
// contains filtered or unexported fields
}
ExecutionOptions defines the transaction execution options ran by the client
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory defines a client transaction factory that facilitates generating and signing an application-specific transaction.
func NewFactory ¶
func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, parameters TxParameters, ) (Factory, error)
NewFactory returns a new instance of Factory.
func NewFactoryFromFlagSet ¶
func NewFactoryFromFlagSet(flags *pflag.FlagSet, keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, ) (Factory, error)
func (*Factory) BuildSimTx ¶
func (f *Factory) BuildSimTx(msgs ...transaction.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 (*Factory) BuildUnsignedTx ¶
func (f *Factory) BuildUnsignedTx(msgs ...transaction.Msg) error
BuildUnsignedTx builds a transaction to be signed given a set of messages. Once created, the fee, memo, and messages are set.
func (*Factory) BuildsSignedTx ¶
func (*Factory) Simulate ¶
func (f *Factory) Simulate(msgs ...transaction.Msg) (*apitx.SimulateResponse, uint64, error)
Simulate simulates the execution of a transaction and returns the simulation response obtained by the query and the adjusted gas amount.
func (*Factory) UnsignedTxString ¶
func (f *Factory) UnsignedTxString(msgs ...transaction.Msg) (string, error)
UnsignedTxString 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 (*Factory) WithAccountNumber ¶
WithAccountNumber returns a copy of the Factory with an updated account number.
func (*Factory) WithSequence ¶
WithSequence returns a copy of the Factory with an updated sequence number.
type FeeConfig ¶
type FeeConfig struct {
// contains filtered or unexported fields
}
FeeConfig holds the fee details for a transaction.
func NewFeeConfig ¶
NewFeeConfig creates a new FeeConfig with the specified fees, feePayer, and feeGranter. It parses the fees string into a slice of Coin, handling normalization.
type GasConfig ¶
type GasConfig struct {
// contains filtered or unexported fields
}
GasConfig defines the 'gas' related fields in a transaction. GasConfig defines the gas-related settings for a transaction.
func NewGasConfig ¶
NewGasConfig creates a new GasConfig with the specified gas, gasAdjustment, and gasPrices. If the provided gas value is zero, it defaults to a predefined value (defaultGas). The gasPrices string is parsed into a slice of DecCoin.
type GasEstimateResponse ¶
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"`
}
GasEstimateResponse defines a response definition for tx gas estimation.
func (GasEstimateResponse) String ¶
func (gr GasEstimateResponse) String() string
type HasValidateBasic ¶
type HasValidateBasic interface { // ValidateBasic does a simple validation check that // doesn't require access to any other information. ValidateBasic() error }
HasValidateBasic is a copy of types.HasValidateBasic to avoid sdk import.
type MultiSignatureData ¶
type MultiSignatureData struct { BitArray *apicrypto.CompactBitArray // Bitmap of signers. Signatures []SignatureData // Individual signatures. }
MultiSignatureData encapsulates signatures from a multisig transaction.
type Signature ¶
type Signature struct { PubKey cryptotypes.PubKey // Public key for signature verification. Data SignatureData // Signature data containing the actual signatures. Sequence uint64 // Account sequence, relevant for SIGN_MODE_DIRECT. }
Signature holds the necessary components to verify transaction signatures.
type SignatureData ¶
type SignatureData interface {
// contains filtered or unexported methods
}
SignatureData defines an interface for different signature data types.
func SignatureDataFromProto ¶
func SignatureDataFromProto(descData *apitxsigning.SignatureDescriptor_Data) (SignatureData, error)
SignatureDataFromProto converts a protobuf SignatureDescriptor_Data to a SignatureData interface. This function supports both Single and Multi signature data types.
type SingleSignatureData ¶
type SingleSignatureData struct { SignMode apitxsigning.SignMode // Mode of the signature. Signature []byte // Actual binary signature. }
SingleSignatureData stores a single signer's signature and its mode.
type Tx ¶
type Tx interface { transaction.Tx // GetSigners fetches the addresses of the signers of the transaction. GetSigners() ([][]byte, error) // GetPubKeys retrieves the public keys of the signers of the transaction. GetPubKeys() ([]cryptotypes.PubKey, error) // GetSignatures fetches the signatures attached to the transaction. GetSignatures() ([]Signature, error) // GetSigningTxData returns the signing.TxData for the transaction. GetSigningTxData() (signing.TxData, error) }
Tx defines the interface for transaction operations.
type TxConfig ¶
type TxConfig interface { TxEncodingConfig TxSigningConfig }
TxConfig is an interface that a client can use to generate a concrete transaction type defined by the application.
func NewTxConfig ¶
func NewTxConfig(options ConfigOptions) (TxConfig, error)
NewTxConfig creates a new TxConfig instance using the provided ConfigOptions. It validates the options, initializes the signing context, and sets up the decoder if not provided.
type TxEncodingConfig ¶
type TxEncodingConfig interface { // TxEncoder returns an encoder for binary transaction encoding. TxEncoder() txEncoder // TxDecoder returns a decoder for binary transaction decoding. TxDecoder() txDecoder // TxJSONEncoder returns an encoder for JSON transaction encoding. TxJSONEncoder() txEncoder // TxJSONDecoder returns a decoder for JSON transaction decoding. TxJSONDecoder() txDecoder // TxTextEncoder returns an encoder for text transaction encoding. TxTextEncoder() txEncoder // TxTextDecoder returns a decoder for text transaction decoding. TxTextDecoder() txDecoder // Decoder returns the Decoder interface for decoding transaction bytes into a DecodedTx. Decoder() Decoder }
TxEncodingConfig defines the interface for transaction encoding and decoding. It provides methods for both binary and JSON encoding/decoding.
type TxParameters ¶
type TxParameters struct { ChainID string // ChainID specifies the unique identifier of the blockchain where the transaction will be processed. SignMode apitxsigning.SignMode // signMode determines the signing mode to be used for the transaction. AccountConfig // AccountConfig includes information about the transaction originator's account. GasConfig // GasConfig specifies the gas settings for the transaction. FeeConfig // FeeConfig details the fee associated with the transaction. ExecutionOptions // ExecutionOptions includes settings that modify how the transaction is executed. // contains filtered or unexported fields }
TxParameters defines the parameters required for constructing a transaction.
type TxSigningConfig ¶
type TxSigningConfig interface { // SignModeHandler returns a reference to the HandlerMap which manages the different signing modes. SignModeHandler() *signing.HandlerMap // SigningContext returns a reference to the Context which holds additional data required during signing. SigningContext() *signing.Context // MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. MarshalSignatureJSON([]Signature) ([]byte, error) // UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. UnmarshalSignatureJSON([]byte) ([]Signature, error) }
TxSigningConfig defines the interface for transaction signing configurations.