utils

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxSize uint64 = 500

DefaultMaxSize is the default maximum size of the cache.

Functions

func GetDecodedTxs

func GetDecodedTxs(txDecoder sdk.TxDecoder, txs [][]byte) ([]sdk.Tx, error)

GetDecodedTxs returns the decoded transactions from the given bytes.

func GetEncodedTxs

func GetEncodedTxs(txEncoder sdk.TxEncoder, txs []sdk.Tx) ([][]byte, error)

GetEncodedTxs returns the encoded transactions from the given bytes.

func GetTxHash

func GetTxHash(encoder sdk.TxEncoder, tx sdk.Tx) (string, error)

GetTxHash returns the string hash representation of a transaction.

func RemoveTxsFromLane

func RemoveTxsFromLane(txs []sdk.Tx, mempool sdkmempool.Mempool) error

RemoveTxsFromLane removes the transactions from the given lane's mempool.

func TxHash added in v2.1.4

func TxHash(txBytes []byte) string

TxHash returns the string hash representation of the given transactions.

Types

type CacheTxDecoder added in v2.1.4

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

CacheTxDecoder wraps the sdk.TxDecoder and caches the decoded transactions with an LRU'esque cache. Each transaction is cached using the transaction's hash as the key. The cache is purged when the number of transactions in the cache exceeds the maximum size. The oldest transactions are removed first.

func NewCacheTxDecoder added in v2.1.4

func NewCacheTxDecoder(
	decoder sdk.TxDecoder,
	maxSize uint64,
) (*CacheTxDecoder, error)

NewCacheTxDecoder returns a new CacheTxDecoder with the given cache interval.

func NewDefaultCacheTxDecoder added in v2.1.4

func NewDefaultCacheTxDecoder(
	decoder sdk.TxDecoder,
) (*CacheTxDecoder, error)

NewDefaultCacheTxDecoder returns a new CacheTxDecoder.

func (*CacheTxDecoder) Contains added in v2.1.4

func (ctd *CacheTxDecoder) Contains(txBytes []byte) bool

Contains returns true if the cache contains the transaction with the given hash.

func (*CacheTxDecoder) Len added in v2.1.4

func (ctd *CacheTxDecoder) Len() int

Len returns the number of transactions in the cache.

func (*CacheTxDecoder) TxDecoder added in v2.1.4

func (ctd *CacheTxDecoder) TxDecoder() sdk.TxDecoder

Decode decodes the transaction bytes into a sdk.Tx. It caches the decoded transaction using the transaction's hash as the key.

type TxWithInfo

type TxWithInfo struct {
	// Hash is the hex-encoded hash of the transaction.
	Hash string
	// Size is the size of the transaction in bytes.
	Size int64
	// GasLimit is the gas limit of the transaction.
	GasLimit uint64
	// TxBytes is the bytes of the transaction.
	TxBytes []byte
	// Priority defines the priority of the transaction.
	Priority any
	// Signers defines the signers of a transaction.
	Signers []signerextraction.SignerData
}

TxWithInfo contains the information required for a transaction to be included in a proposal.

func NewTxInfo

func NewTxInfo(
	hash string,
	size int64,
	gasLimit uint64,
	txBytes []byte,
	priority any,
	signers []signerextraction.SignerData,
) TxWithInfo

NewTxInfo returns a new TxInfo instance.

func (TxWithInfo) String

func (t TxWithInfo) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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