Documentation ¶
Index ¶
- Variables
- type ContainerItem
- type TxContainer
- func (q *TxContainer) Add(tx types.Transaction) bool
- func (q *TxContainer) ByteSize() int64
- func (q *TxContainer) First() types.Transaction
- func (q *TxContainer) Full() bool
- func (q *TxContainer) GetByHash(hash string) types.Transaction
- func (q *TxContainer) Has(tx types.Transaction) bool
- func (q *TxContainer) HasByHash(hash string) bool
- func (q *TxContainer) IFind(predicate func(types.Transaction) bool) types.Transaction
- func (q *TxContainer) Last() types.Transaction
- func (q *TxContainer) Remove(txs ...types.Transaction)
- func (q *TxContainer) Size() int64
- func (q *TxContainer) Sort()
- type TxPool
- func (tp *TxPool) ByteSize() int64
- func (tp *TxPool) Container() types.TxContainer
- func (tp *TxPool) GetByFrom(address util.String) []types.Transaction
- func (tp *TxPool) GetByHash(hash string) types.Transaction
- func (tp *TxPool) Has(tx types.Transaction) bool
- func (tp *TxPool) HasByHash(hash string) bool
- func (tp *TxPool) Put(tx types.Transaction) error
- func (tp *TxPool) Remove(txs ...types.Transaction)
- func (tp *TxPool) Size() int64
Constants ¶
This section is empty.
Variables ¶
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
type TxPool ¶
TxPool stores transactions.
func New ¶
New creates a new instance of TxPool. Cap size is the max amount of transactions that can be maintained 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) Remove ¶
func (tp *TxPool) Remove(txs ...types.Transaction)
Remove removes transactions