txpool

package
v0.1.8-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContainerFull is an error about a full container
	ErrContainerFull = fmt.Errorf("container is full")

	// ErrTxAlreadyAdded is an error about a transaction
	// that is in the pool.
	ErrTxAlreadyAdded = fmt.Errorf("exact transaction already in the pool")
)

Functions

This section is empty.

Types

type ContainerItem

type ContainerItem struct {
	Tx      types.Transaction
	FeeRate util.String
}

ContainerItem represents the a container item. It wraps a transaction and its related information

type TxContainer

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

TxContainer represents the internal container used by TxPool. It provides a Put operation with automatic sorting by fee rate and nonce. The container is thread-safe.

func NewQueueNoSort

func NewQueueNoSort(cap int64) *TxContainer

NewQueueNoSort creates a new container with sorting turned off

func (*TxContainer) Add

func (q *TxContainer) Add(tx types.Transaction) bool

Add adds a transaction to the end of the container. Returns false if container capacity has been reached. It computes the fee rate and sorts the transactions after addition.

func (*TxContainer) ByteSize

func (q *TxContainer) ByteSize() int64

ByteSize gets the total byte size of all transactions in the container

func (*TxContainer) First

func (q *TxContainer) First() types.Transaction

First returns a single transaction at head. Returns nil if container is empty

func (*TxContainer) Full

func (q *TxContainer) Full() bool

Full checks if the container's capacity has been reached

func (*TxContainer) GetByHash

func (q *TxContainer) GetByHash(hash string) types.Transaction

GetByHash get a transaction by its hash from the pool

func (*TxContainer) Has

func (q *TxContainer) Has(tx types.Transaction) bool

Has checks whether a transaction is in the container

func (*TxContainer) HasByHash

func (q *TxContainer) HasByHash(hash string) bool

HasByHash is like Has but accepts a transaction hash

func (*TxContainer) IFind

func (q *TxContainer) IFind(predicate func(types.Transaction) bool) types.Transaction

IFind iterates over the transactions and passes each to the predicate function. When the predicate returns true, it stops and returns the last transaction that was passed to the predicate.

Do not modify the transaction in the predicate as it is a pointer to the transaction in container.

func (*TxContainer) Last

func (q *TxContainer) Last() types.Transaction

Last returns a single transaction at head. Returns nil if container is empty

func (*TxContainer) Remove

func (q *TxContainer) Remove(txs ...types.Transaction)

Remove removes a transaction

func (*TxContainer) Size

func (q *TxContainer) Size() int64

Size returns the number of items in the container

func (*TxContainer) Sort

func (q *TxContainer) Sort()

Sort sorts the container

type TxPool

type TxPool struct {
	sync.RWMutex // general mutex
	// contains filtered or unexported fields
}

TxPool stores transactions.

func New

func New(cap int64) *TxPool

New creates a new instance of TxPool. Cap size is the max amount of transactions that can be maintained in the pool.

func (*TxPool) ByteSize

func (tp *TxPool) ByteSize() int64

ByteSize gets the total byte size of all transactions in the pool

func (*TxPool) Container

func (tp *TxPool) Container() types.TxContainer

Container gets the underlying transaction container

func (*TxPool) GetByFrom

func (tp *TxPool) GetByFrom(address util.String) []types.Transaction

GetByFrom fetches transactions where the sender or `from` field match the given address

func (*TxPool) GetByHash

func (tp *TxPool) GetByHash(hash string) types.Transaction

GetByHash gets a transaction from the pool using its hash

func (*TxPool) Has

func (tp *TxPool) Has(tx types.Transaction) bool

Has checks whether a transaction is in the pool

func (*TxPool) HasByHash

func (tp *TxPool) HasByHash(hash string) bool

HasByHash is like Has but accepts a hash

func (*TxPool) Put

func (tp *TxPool) Put(tx types.Transaction) error

Put adds a transaction

func (*TxPool) Remove

func (tp *TxPool) Remove(txs ...types.Transaction)

Remove removes transactions

func (*TxPool) Size

func (tp *TxPool) Size() int64

Size gets the total number of transactions in the pool

Jump to

Keyboard shortcuts

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