gasprice

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMaxPrice = big.NewInt(500 * params.GWei)

Functions

This section is empty.

Types

type CirculeQueue

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

CirculeQueue currently is only for special usage. Thread unsafe!

func NewCirculeQueue

func NewCirculeQueue(c int) *CirculeQueue

func NewCirculeQueueByItems

func NewCirculeQueueByItems(items []interface{}) *CirculeQueue

func (*CirculeQueue) EnAndReplace

func (q *CirculeQueue) EnAndReplace(b interface{}) (d interface{})

EnAndReplace enqueue one price and return the replaced one, if there's no item replaced, the return will be nil.

type Config

type Config struct {
	Blocks     int
	Percentile int
	Default    *big.Int `toml:",omitempty"`
	MaxPrice   *big.Int `toml:",omitempty"`

	PredConfig
}

type Oracle

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

Oracle recommends gas prices based on the content of recent blocks. Suitable for both light and full clients.

func NewOracle

func NewOracle(backend OracleBackend, params Config) *Oracle

NewOracle returns a new gasprice oracle which can recommend suitable gasprice for newly created transaction.

func (*Oracle) SuggestPrice added in v0.1.3

func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error)

SuggestPrice returns a gasprice so that newly created transaction can have a very high chance to be included in the following blocks.

type OracleBackend

type OracleBackend interface {
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
	ChainConfig() *params.ChainConfig

	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

OracleBackend includes all necessary background APIs for oracle.

type PredConfig

type PredConfig struct {
	PredictIntervalSecs int
	MinTxCntPerBlock    int // minimum tx cnt per block for caculations.
	FastFactor          int // how many times of avgTxCnt for the fast index
	MedianFactor        int // how many times of avgTxCnt for the median index
	LowFactor           int // how many times of avgTxCnt for the low index
	MinMedianIndex      int // min index in all pending transactions for median price
	MinLowIndex         int // min index in all pending transactions for low price

	FastPercentile   int //fast percentile for the case there are no many pending transactions
	MeidanPercentile int

	MaxValidPendingSecs int
}

type Prediction

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

func NewPrediction

func NewPrediction(cfg Config, backend OracleBackend, pool *core.TxPool) *Prediction

func (*Prediction) CurrentPrices

func (p *Prediction) CurrentPrices() []uint

CurrentPrices returns the current prediction about gas price in gwei; the results should be readonly, and the reason didn't do a copy is that there's no necessary

func (*Prediction) Stop

func (p *Prediction) Stop()

Stop stops the prediction loop

type Stats

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

Stats statistics tx count of the last few blocks

func NewStats

func NewStats(txc []int) *Stats

func (*Stats) Add

func (s *Stats) Add(cnt int)

func (*Stats) Avg

func (s *Stats) Avg() int

type TxByPrice

type TxByPrice types.Transactions

TxByPrice sorts the txs descending by price

func (TxByPrice) Len

func (s TxByPrice) Len() int

func (TxByPrice) Less

func (s TxByPrice) Less(i, j int) bool

func (TxByPrice) Swap

func (s TxByPrice) Swap(i, j int)

Jump to

Keyboard shortcuts

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