tx

package
v2.10.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 44 Imported by: 0

README

The tx package provides a robust set of tools for building, signing, and managing transactions in a Cosmos SDK-based blockchain application.

Overview

This package includes several key components:

  1. Transaction Factory
  2. Transaction Config
  3. Transaction Encoder/Decoder
  4. Signature Handling

Architecture

graph TD
    A[Client] --> B[Factory]
    B --> D[TxConfig]
    D --> E[TxEncodingConfig]
    D --> F[TxSigningConfig]
    B --> G[Tx]
    G --> H[Encoder]
    G --> I[Decoder]
    F --> J[SignModeHandler]
    F --> K[SigningContext]
    B --> L[AuxTxBuilder]

Key Components

TxConfig

TxConfig provides configuration for transaction handling, including:

  • Encoding and decoding
  • Sign mode handling
  • Signature JSON marshaling/unmarshaling
classDiagram
    class TxConfig {
        <<interface>>
        TxEncodingConfig
        TxSigningConfig
    }

    class TxEncodingConfig {
        <<interface>>
        TxEncoder() txEncoder
        TxDecoder() txDecoder
        TxJSONEncoder() txEncoder
        TxJSONDecoder() txDecoder
        Decoder() Decoder
    }

    class TxSigningConfig {
        <<interface>>
        SignModeHandler() *signing.HandlerMap
        SigningContext() *signing.Context
        MarshalSignatureJSON([]Signature) ([]byte, error)
        UnmarshalSignatureJSON([]byte) ([]Signature, error)
    }

    class txConfig {
        TxEncodingConfig
        TxSigningConfig
    }

    class defaultEncodingConfig {
        cdc codec.BinaryCodec
        decoder Decoder
        TxEncoder() txEncoder
        TxDecoder() txDecoder
        TxJSONEncoder() txEncoder
        TxJSONDecoder() txDecoder
    }

    class defaultTxSigningConfig {
        signingCtx *signing.Context
        handlerMap *signing.HandlerMap
        cdc codec.BinaryCodec
        SignModeHandler() *signing.HandlerMap
        SigningContext() *signing.Context
        MarshalSignatureJSON([]Signature) ([]byte, error)
        UnmarshalSignatureJSON([]byte) ([]Signature, error)
    }

    TxConfig <|-- txConfig
    TxEncodingConfig <|.. defaultEncodingConfig
    TxSigningConfig <|.. defaultTxSigningConfig
    txConfig *-- defaultEncodingConfig
    txConfig *-- defaultTxSigningConfig

Factory

The Factory is the main entry point for creating and managing transactions. It handles:

  • Account preparation
  • Gas calculation
  • Unsigned transaction building
  • Transaction signing
  • Transaction simulation
  • Transaction broadcasting
classDiagram
    class Factory {
        keybase keyring.Keyring
        cdc codec.BinaryCodec
        accountRetriever account.AccountRetriever
        ac address.Codec
        conn gogogrpc.ClientConn
        txConfig TxConfig
        txParams TxParameters
        tx txState

        NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, parameters) Factory
        Prepare() error
        BuildUnsignedTx(msgs ...transaction.Msg) error
        BuildsSignedTx(ctx context.Context, msgs ...transaction.Msg) (Tx, error)
        calculateGas(msgs ...transaction.Msg) error
        Simulate(msgs ...transaction.Msg) (*apitx.SimulateResponse, uint64, error)
        UnsignedTxString(msgs ...transaction.Msg) (string, error)
        BuildSimTx(msgs ...transaction.Msg) ([]byte, error)
        sign(ctx context.Context, overwriteSig bool) (Tx, error)
        WithGas(gas uint64)
        WithSequence(sequence uint64)
        WithAccountNumber(accnum uint64)
        getTx() (Tx, error)
        getFee() (*apitx.Fee, error)
        getSigningTxData() (signing.TxData, error)
        setSignatures(...Signature) error
    }

    class TxParameters {
        <<struct>>
        chainID string
        AccountConfig
        GasConfig
        FeeConfig
        SignModeConfig
        TimeoutConfig
        MemoConfig
    }

    class TxConfig {
        <<interface>>
    }

    class Tx {
        <<interface>>
    }

    class txState {
        <<struct>>
        msgs []transaction.Msg
        memo string
        fees []*base.Coin
        gasLimit uint64
        feeGranter []byte
        feePayer []byte
        timeoutHeight uint64
        unordered bool
        timeoutTimestamp uint64
        signatures []Signature
        signerInfos []*apitx.SignerInfo
    }

    Factory *-- TxParameters
    Factory *-- TxConfig
    Factory *-- txState
    Factory ..> Tx : creates

Encoder/Decoder

The package includes functions for encoding and decoding transactions in both binary and JSON formats.

classDiagram
    class Decoder {
        <<interface>>
        Decode(txBytes []byte) (*txdecode.DecodedTx, error)
    }

    class txDecoder {
        <<function>>
        decode(txBytes []byte) (Tx, error)
    }

    class txEncoder {
        <<function>>
        encode(tx Tx) ([]byte, error)
    }

    class EncoderUtils {
        <<utility>>
        decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder
        encodeTx(tx Tx) ([]byte, error)
        decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder
        encodeJsonTx(tx Tx) ([]byte, error)
        protoTxBytes(tx *txv1beta1.Tx) ([]byte, error)
    }

    class MarshalOptions {
        <<utility>>
        Deterministic bool
    }

    class JSONMarshalOptions {
        <<utility>>
        Indent string
        UseProtoNames bool
        UseEnumNumbers bool
    }

    Decoder <.. EncoderUtils : uses
    txDecoder <.. EncoderUtils : creates
    txEncoder <.. EncoderUtils : implements
    EncoderUtils ..> MarshalOptions : uses
    EncoderUtils ..> JSONMarshalOptions : uses

Sequence Diagrams

Generate Aux Signer Data
sequenceDiagram
    participant User
    participant GenerateOrBroadcastTxCLI
    participant generateAuxSignerData
    participant makeAuxSignerData
    participant AuxTxBuilder
    participant ctx.PrintProto

    User->>GenerateOrBroadcastTxCLI: Call with isAux flag
    GenerateOrBroadcastTxCLI->>generateAuxSignerData: Call

    generateAuxSignerData->>makeAuxSignerData: Call
    makeAuxSignerData->>AuxTxBuilder: NewAuxTxBuilder()
    
    makeAuxSignerData->>AuxTxBuilder: SetAddress(f.txParams.fromAddress)
    
    alt f.txParams.offline
        makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(f.AccountNumber())
        makeAuxSignerData->>AuxTxBuilder: SetSequence(f.Sequence())
    else
        makeAuxSignerData->>f.accountRetriever: GetAccountNumberSequence()
        makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(accNum)
        makeAuxSignerData->>AuxTxBuilder: SetSequence(seq)
    end
    
    makeAuxSignerData->>AuxTxBuilder: SetMsgs(msgs...)
    makeAuxSignerData->>AuxTxBuilder: SetSignMode(f.SignMode())
    
    makeAuxSignerData->>f.keybase: GetPubKey(f.txParams.fromName)
    makeAuxSignerData->>AuxTxBuilder: SetPubKey(pubKey)
    
    makeAuxSignerData->>AuxTxBuilder: SetChainID(f.txParams.chainID)
    makeAuxSignerData->>AuxTxBuilder: GetSignBytes()
    
    makeAuxSignerData->>f.keybase: Sign(f.txParams.fromName, signBz, f.SignMode())
    makeAuxSignerData->>AuxTxBuilder: SetSignature(sig)
    
    makeAuxSignerData->>AuxTxBuilder: GetAuxSignerData()
    AuxTxBuilder-->>makeAuxSignerData: Return AuxSignerData
    makeAuxSignerData-->>generateAuxSignerData: Return AuxSignerData
    
    generateAuxSignerData->>ctx.PrintProto: Print AuxSignerData
    ctx.PrintProto-->>GenerateOrBroadcastTxCLI: Return result
    GenerateOrBroadcastTxCLI-->>User: Return result
Generate Only
sequenceDiagram
    participant User
    participant GenerateOrBroadcastTxCLI
    participant generateOnly
    participant Factory
    participant ctx.PrintString

    User->>GenerateOrBroadcastTxCLI: Call with generateOnly flag
    GenerateOrBroadcastTxCLI->>generateOnly: Call

    generateOnly->>Factory: Prepare()
    alt Error in Prepare
        Factory-->>generateOnly: Return error
        generateOnly-->>GenerateOrBroadcastTxCLI: Return error
        GenerateOrBroadcastTxCLI-->>User: Return error
    end

    generateOnly->>Factory: UnsignedTxString(msgs...)
    Factory->>Factory: BuildUnsignedTx(msgs...)
    Factory->>Factory: setMsgs(msgs...)
    Factory->>Factory: setMemo(f.txParams.memo)
    Factory->>Factory: setFees(f.txParams.gasPrices)
    Factory->>Factory: setGasLimit(f.txParams.gas)
    Factory->>Factory: setFeeGranter(f.txParams.feeGranter)
    Factory->>Factory: setFeePayer(f.txParams.feePayer)
    Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight)

    Factory->>Factory: getTx()
    Factory->>Factory: txConfig.TxJSONEncoder()
    Factory->>Factory: encoder(tx)

    Factory-->>generateOnly: Return unsigned tx string
    generateOnly->>ctx.PrintString: Print unsigned tx string
    ctx.PrintString-->>generateOnly: Return result
    generateOnly-->>GenerateOrBroadcastTxCLI: Return result
    GenerateOrBroadcastTxCLI-->>User: Return result
DryRun
sequenceDiagram
    participant User
    participant GenerateOrBroadcastTxCLI
    participant dryRun
    participant Factory
    participant os.Stderr

    User->>GenerateOrBroadcastTxCLI: Call with dryRun flag
    GenerateOrBroadcastTxCLI->>dryRun: Call

    dryRun->>Factory: Prepare()
    alt Error in Prepare
        Factory-->>dryRun: Return error
        dryRun-->>GenerateOrBroadcastTxCLI: Return error
        GenerateOrBroadcastTxCLI-->>User: Return error
    end

    dryRun->>Factory: Simulate(msgs...)
    Factory->>Factory: BuildSimTx(msgs...)
    Factory->>Factory: BuildUnsignedTx(msgs...)
    Factory->>Factory: getSimPK()
    Factory->>Factory: getSimSignatureData(pk)
    Factory->>Factory: setSignatures(sig)
    Factory->>Factory: getTx()
    Factory->>Factory: txConfig.TxEncoder()(tx)
    
    Factory->>ServiceClient: Simulate(context.Background(), &apitx.SimulateRequest{})
    ServiceClient->>Factory: Return result
    
    Factory-->>dryRun: Return (simulation, gas, error)
    alt Error in Simulate
        dryRun-->>GenerateOrBroadcastTxCLI: Return error
        GenerateOrBroadcastTxCLI-->>User: Return error
    end

    dryRun->>os.Stderr: Fprintf(GasEstimateResponse{GasEstimate: gas})
    os.Stderr-->>dryRun: Return result
    dryRun-->>GenerateOrBroadcastTxCLI: Return result
    GenerateOrBroadcastTxCLI-->>User: Return result
Generate and Broadcast Tx
sequenceDiagram
    participant User
    participant GenerateOrBroadcastTxCLI
    participant BroadcastTx
    participant Factory
    participant clientCtx

    User->>GenerateOrBroadcastTxCLI: Call
    GenerateOrBroadcastTxCLI->>BroadcastTx: Call

    BroadcastTx->>Factory: Prepare()
    alt Error in Prepare
        Factory-->>BroadcastTx: Return error
        BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error
        GenerateOrBroadcastTxCLI-->>User: Return error
    end

    alt SimulateAndExecute is true
        BroadcastTx->>Factory: calculateGas(msgs...)
        Factory->>Factory: Simulate(msgs...)
        Factory->>Factory: WithGas(adjusted)
    end

    BroadcastTx->>Factory: BuildUnsignedTx(msgs...)
    Factory->>Factory: setMsgs(msgs...)
    Factory->>Factory: setMemo(f.txParams.memo)
    Factory->>Factory: setFees(f.txParams.gasPrices)
    Factory->>Factory: setGasLimit(f.txParams.gas)
    Factory->>Factory: setFeeGranter(f.txParams.feeGranter)
    Factory->>Factory: setFeePayer(f.txParams.feePayer)
    Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight)

    alt !clientCtx.SkipConfirm
        BroadcastTx->>Factory: getTx()
        BroadcastTx->>Factory: txConfig.TxJSONEncoder()
        BroadcastTx->>clientCtx: PrintRaw(txBytes)
        BroadcastTx->>clientCtx: Input.GetConfirmation()
        alt Not confirmed
            BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error
            GenerateOrBroadcastTxCLI-->>User: Return error
        end
    end

    BroadcastTx->>Factory: BuildsSignedTx(ctx, msgs...)
    Factory->>Factory: sign(ctx, true)
    Factory->>Factory: keybase.GetPubKey(fromName)
    Factory->>Factory: getSignBytesAdapter()
    Factory->>Factory: keybase.Sign(fromName, bytesToSign, signMode)
    Factory->>Factory: setSignatures(sig)
    Factory->>Factory: getTx()

    BroadcastTx->>Factory: txConfig.TxEncoder()
    BroadcastTx->>clientCtx: BroadcastTx(txBytes)

    alt Error in BroadcastTx
        clientCtx-->>BroadcastTx: Return error
        BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error
        GenerateOrBroadcastTxCLI-->>User: Return error
    end

    BroadcastTx->>clientCtx: OutputTx(res)
    clientCtx-->>BroadcastTx: Return result
    BroadcastTx-->>GenerateOrBroadcastTxCLI: Return result
    GenerateOrBroadcastTxCLI-->>User: Return result

Usage

To use the tx package, typically you would:

  1. Create a Factory
  2. Simulate the transaction (optional)
  3. Build a signed transaction
  4. Encode the transaction
  5. Broadcast the transaction

Here's a simplified example:

// Create a Factory
factory, err := NewFactory(keybase, cdc, accountRetriever, txConfig, addressCodec, conn, txParameters)
if err != nil {
    return err
}

// Simulate the transaction (optional)
simRes, gas, err := factory.Simulate(msgs...)
if err != nil {
    return err
}
factory.WithGas(gas)

// Build a signed transaction
signedTx, err := factory.BuildsSignedTx(context.Background(), msgs...)
if err != nil {
    return err
}

// Encode the transaction
txBytes, err := factory.txConfig.TxEncoder()(signedTx)
if err != nil {
    return err
}

// Broadcast the transaction
// (This step depends on your specific client implementation)

Documentation

Index

Constants

View Source
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 Decoder

type Decoder interface {
	Decode(txBytes []byte) (*txdecode.DecodedTx, error)
}

Decoder defines the interface for decoding transaction bytes into a DecodedTx.

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 (f *Factory) BuildsSignedTx(ctx context.Context, msgs ...transaction.Msg) (Tx, error)

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

func (f *Factory) WithAccountNumber(accnum uint64)

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

func (*Factory) WithGas

func (f *Factory) WithGas(gas uint64)

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

func (*Factory) WithSequence

func (f *Factory) WithSequence(sequence uint64)

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

func NewFeeConfig(fees, feePayer, feeGranter string) (FeeConfig, error)

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

func NewGasConfig(gas uint64, gasAdjustment float64, gasPrices string) (GasConfig, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳