chainfee

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type AtomPerKByte

type AtomPerKByte dcrutil.Amount

AtomPerKByte represents a fee rate in atom/kB.

const (
	// FeePerKBFloor is the lowest fee rate in atom/kB that we should use
	// for determining transaction fees. Originally, this was used due to
	// the conversion from sats/kB => sats/KW causing a possible rounding
	// error, but in Decred we use this to track the widely deployed
	// minimum relay fee.
	FeePerKBFloor AtomPerKByte = 1e4
)

func (AtomPerKByte) FeeForSize

func (s AtomPerKByte) FeeForSize(bytes int64) dcrutil.Amount

FeeForSize calculates the fee resulting from this fee rate and the given size in bytes.

func (AtomPerKByte) String

func (s AtomPerKByte) String() string

String returns a pretty string representation for the rate in DCR/kB.

type DcrdEstimator

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

DcrdEstimator is an implementation of the FeeEstimator interface backed by the RPC interface of an active dcrd node. This implementation will proxy any fee estimation requests to dcrd's RPC interface.

func NewDcrdEstimator

func NewDcrdEstimator(rpcConfig rpcclient.ConnConfig,
	fallBackFeeRate AtomPerKByte) (*DcrdEstimator, error)

NewDcrdEstimator creates a new DcrdFeeEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the dcrd node, and also a fall back fee rate. The fallback fee rate is used in the occasion that the estimator has insufficient data, or returns zero for a fee estimate.

func (*DcrdEstimator) EstimateFeePerKB

func (b *DcrdEstimator) EstimateFeePerKB(numBlocks uint32) (AtomPerKByte, error)

EstimateFeePerKB queries the connected chain client for a fee estimation for the given block range.

NOTE: This method is part of the FeeEstimator interface.

func (*DcrdEstimator) RelayFeePerKB

func (b *DcrdEstimator) RelayFeePerKB() AtomPerKByte

RelayFeePerKB returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the FeeEstimator interface.

func (*DcrdEstimator) Start

func (b *DcrdEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the FeeEstimator interface.

func (*DcrdEstimator) Stop

func (b *DcrdEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the FeeEstimator interface.

type Estimator

type Estimator interface {
	// EstimateFeePerKB takes in a target for the number of blocks until
	// an initial confirmation and returns the estimated fee expressed in
	// atoms/byte.
	EstimateFeePerKB(numBlocks uint32) (AtomPerKByte, error)

	// Start signals the Estimator to start any processes or goroutines
	// it needs to perform its duty.
	Start() error

	// Stop stops any spawned goroutines and cleans up the resources used
	// by the fee estimator.
	Stop() error

	// RelayFeePerKB returns the minimum fee rate required for transactions
	// to be relayed. This is also the basis for calculation of the dust
	// limit.
	RelayFeePerKB() AtomPerKByte
}

Estimator provides the ability to estimate on-chain transaction fees for various combinations of transaction sizes and desired confirmation time (measured by number of blocks).

type SparseConfFeeSource

type SparseConfFeeSource struct {
	// URL is the fee estimation API specified by the user.
	URL string
}

SparseConfFeeSource is an implementation of the WebAPIFeeSource that utilizes a user-specified fee estimation API for Bitcoin. It expects the response to be in the JSON format: `fee_by_block_target: { ... }` where the value maps block targets to fee estimates (in sat per kilovbyte).

func (SparseConfFeeSource) GenQueryURL

func (s SparseConfFeeSource) GenQueryURL() string

GenQueryURL generates the full query URL. The value returned by this method should be able to be used directly as a path for an HTTP GET request.

NOTE: Part of the WebAPIFeeSource interface.

func (SparseConfFeeSource) ParseResponse

func (s SparseConfFeeSource) ParseResponse(r io.Reader) (map[uint32]uint32, error)

ParseResponse attempts to parse the body of the response generated by the above query URL. Typically this will be JSON, but the specifics are left to the WebAPIFeeSource implementation.

NOTE: Part of the WebAPIFeeSource interface.

type StaticEstimator

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

StaticEstimator will return a static value for all fee calculation requests. It is designed to be replaced by a proper fee calculation implementation. The fees are not accessible directly, because changing them would not be thread safe.

func NewStaticEstimator

func NewStaticEstimator(feePerKB,
	relayFee AtomPerKByte) *StaticEstimator

NewStaticEstimator returns a new static fee estimator instance.

func (StaticEstimator) EstimateFeePerKB

func (e StaticEstimator) EstimateFeePerKB(numBlocks uint32) (AtomPerKByte, error)

EstimateFeePerKB will return the static value for fee calculations.

NOTE: This method is part of the FeeEstimator interface.

func (StaticEstimator) RelayFeePerKB

func (e StaticEstimator) RelayFeePerKB() AtomPerKByte

RelayFeePerKB returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the FeeEstimator interface.

func (StaticEstimator) Start

func (e StaticEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (StaticEstimator) Stop

func (e StaticEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type WebAPIEstimator

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

WebAPIEstimator is an implementation of the Estimator interface that queries an HTTP-based fee estimation from an existing web API.

func NewWebAPIEstimator

func NewWebAPIEstimator(api WebAPIFeeSource, noCache bool) *WebAPIEstimator

NewWebAPIEstimator creates a new WebAPIEstimator from a given URL and a fallback default fee. The fees are updated whenever a new block is mined.

func (*WebAPIEstimator) EstimateFeePerKB

func (w *WebAPIEstimator) EstimateFeePerKB(numBlocks uint32) (
	AtomPerKByte, error)

EstimateFeePerKB takes in a target for the number of blocks until an initial confirmation and returns the estimated fee expressed in sat/kw.

NOTE: This method is part of the FeeEstimator interface.

func (*WebAPIEstimator) RelayFeePerKB

func (w *WebAPIEstimator) RelayFeePerKB() AtomPerKByte

RelayFeePerKB returns the minimum fee rate required for transactions to be relayed.

NOTE: This method is part of the FeeEstimator interface.

func (*WebAPIEstimator) Start

func (w *WebAPIEstimator) Start() error

Start signals the Estimator to start any processes or goroutines it needs to perform its duty.

NOTE: This method is part of the Estimator interface.

func (*WebAPIEstimator) Stop

func (w *WebAPIEstimator) Stop() error

Stop stops any spawned goroutines and cleans up the resources used by the fee estimator.

NOTE: This method is part of the Estimator interface.

type WebAPIFeeSource

type WebAPIFeeSource interface {
	// GenQueryURL generates the full query URL. The value returned by this
	// method should be able to be used directly as a path for an HTTP GET
	// request.
	GenQueryURL() string

	// ParseResponse attempts to parse the body of the response generated
	// by the above query URL. Typically this will be JSON, but the
	// specifics are left to the WebAPIFeeSource implementation.
	ParseResponse(r io.Reader) (map[uint32]uint32, error)
}

WebAPIFeeSource is an interface allows the WebAPIEstimator to query an arbitrary HTTP-based fee estimator. Each new set/network will gain an implementation of this interface in order to allow the WebAPIEstimator to be fully generic in its logic.

Jump to

Keyboard shortcuts

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