tx

package
v0.0.0-...-b8c38bb Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCommitTimeoutHeightOffset is the default number of blocks after the
	// latest block (when broadcasting) that a transactions should be considered
	// errored if it has not been committed.
	DefaultCommitTimeoutHeightOffset = 5
)

Variables

View Source
var (
	// ErrInvalidMsg signifies that there was an issue in validating the
	// transaction message. This could be due to format, content, or other
	// constraints imposed on the message.
	ErrInvalidMsg = errorsmod.Register(codespace, 4, "failed to validate tx message")

	// ErrCheckTx indicates an error occurred during the ABCI check transaction
	// process, which verifies the transaction's integrity before it is added
	// to the mempool.
	ErrCheckTx = errorsmod.Register(codespace, 5, "error during ABCI check tx")

	// ErrTxTimeout is raised when a transaction has taken too long to
	// complete, surpassing a predefined threshold.
	ErrTxTimeout = errorsmod.Register(codespace, 6, "tx timed out")

	// ErrQueryTx indicates an error occurred while trying to query for the status
	// of a specific transaction, likely due to issues with the query parameters
	// or the state of the blockchain network.
	ErrQueryTx = errorsmod.Register(codespace, 7, "error encountered while querying for tx")

	// ErrInvalidTxHash represents an error which is triggered when the
	// transaction hash provided does not adhere to the expected format or
	// constraints, implying it may be corrupted or tampered with.
	ErrInvalidTxHash = errorsmod.Register(codespace, 8, "invalid tx hash")

	// ErrNonTxEventBytes indicates an attempt to deserialize bytes that do not
	// correspond to a transaction event. This error is triggered when the provided
	// byte data isn't recognized as a valid transaction event representation.
	ErrNonTxEventBytes = errorsmod.Register(codespace, 9, "attempted to deserialize non-tx event bytes")

	// ErrUnmarshalTx signals a failure in the unmarshaling process of a transaction.
	// This error is triggered when the system encounters issues translating a set of
	// bytes into the corresponding Tx structure or object.
	ErrUnmarshalTx = errorsmod.Register(codespace, 10, "failed to unmarshal tx")
)

Functions

func NewTxClient

func NewTxClient(
	ctx context.Context,
	deps depinject.Config,
	opts ...client.TxClientOption,
) (_ client.TxClient, err error)

NewTxClient attempts to construct a new TxClient using the given dependencies and options.

It performs the following steps:

  1. Initializes a default txClient with the default commit timeout height offset, an empty error channel map, and an empty transaction timeout pool.
  2. Injects the necessary dependencies using depinject.
  3. Applies any provided options to customize the client.
  4. Validates and sets any missing default configurations using the validateConfigAndSetDefaults method.
  5. Subscribes the client to its own transactions. This step might be reconsidered for relocation to a potential Start() method in the future.

Required dependencies:

  • client.TxContext
  • client.EventsQueryClient
  • client.BlockClient

Available options:

  • WithSigningKeyName
  • WithCommitTimeoutHeightOffset

func NewTxContext

func NewTxContext(deps depinject.Config) (client.TxContext, error)

NewTxContext initializes a new cosmosTxContext with the given dependencies. It uses depinject to populate its members and returns a client.TxContext interface type.

Required dependencies:

  • cosmosclient.Context
  • cosmostx.Factory

func UnmarshalTxResult

func UnmarshalTxResult(txResultBz []byte) (*abci.TxResult, error)

UnmarshalTxResult attempts to deserialize a slice of bytes into a TxResult It checks if the given bytes correspond to a valid transaction event. If the resulting TxResult has empty transaction bytes, it assumes that the message was not a transaction results and returns an error.

func WithCommitTimeoutBlocks

func WithCommitTimeoutBlocks(timeout int64) client.TxClientOption

WithCommitTimeoutBlocks sets the timeout duration in terms of number of blocks for the client to wait for broadcast transactions to be committed before returning a timeout error.

func WithSigningKeyName

func WithSigningKeyName(keyName string) client.TxClientOption

WithSigningKeyName sets the name of the key which should be retrieved from the keyring and used for signing transactions.

Types

type CometTxEvent

type CometTxEvent struct {
	Data struct {
		// TxResult is nested to accommodate CometBFT's serialization format,
		// ensuring correct deserialization of transaction results.
		Value struct {
			TxResult abci.TxResult
		} `json:"value"`
	} `json:"data"`
}

CometTxEvent is used to deserialize incoming transaction event messages from the respective events query subscription. This structure is adapted to handle CometBFT's unique serialization format, which diverges from conventional approaches seen in implementations like rollkit's. The design ensures accurate parsing and compatibility with CometBFT's serialization of transaction results.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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