nonce

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockDiffNotEnough = errors.New("the block number is not old enough to be considered not pending")

ErrBlockDiffNotEnough indicates that the pending block is not old enough.

View Source
var ErrPendingTxMayBeStuck = errors.New("pending tx may be stuck")

ErrPendingTxMayBeStuck indicates that the pending tx may be stuck.

View Source
var ErrReceiptNotFound = errors.New("receipt not found")

ErrReceiptNotFound indicates that the receipt wasn't found.

Functions

This section is empty.

Types

type ChainClient

type ChainClient interface {
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	HeaderByNumber(ctx context.Context, n *big.Int) (*types.Header, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
	SendTransaction(ctx context.Context, tx *types.Transaction) error
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
}

ChainClient provides the basic api the a chain needs to provide for an NonceTracker.

type NonceStore

type NonceStore interface {
	ListPendingTx(context.Context, common.Address) ([]PendingTx, error)
	InsertPendingTx(context.Context, common.Address, int64, common.Hash) error
	DeletePendingTxByHash(context.Context, common.Hash) error
	ReplacePendingTxByHash(context.Context, common.Hash, common.Hash) error
}

NonceStore provides the api for managing the storage of nonce and pending txs.

type NonceTracker

type NonceTracker interface {
	// GetNonce returns the nonce to be used in the next transaction.
	// The call is blocked until the client calls unlock.
	// The client should also call registerPendingTx if it managed to submit a transaction sucessuflly.
	GetNonce(context.Context) (RegisterPendingTx, UnlockTracker, int64)

	// GetPendingCount returns the number of pendings txs.
	GetPendingCount(context.Context) int

	// Resync resyncs nonce tracker state with the network.
	// NOTICE: must not call `Resync(..)` if there are still an "open call" to the method `GetNonce(...)`.
	Resync(context.Context) error
}

NonceTracker manages nonce by keeping track of pendings Tx.

type PendingTx

type PendingTx struct {
	ChainID        int64
	Hash           common.Hash
	Nonce          int64
	Address        common.Address
	BumpPriceCount int
	CreatedAt      time.Time
}

PendingTx represents a pending tx.

type RegisterPendingTx

type RegisterPendingTx func(common.Hash)

RegisterPendingTx registers a pending tx in the nonce tracker.

type UnlockTracker

type UnlockTracker func()

UnlockTracker unlocks the tracker so another thread can call GetNonce.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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