chainfee

package
v0.0.0-...-4461705 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 15 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 bronlog.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 bronlog.

Types

type BrocoindEstimator

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

BrocoindEstimator is an implementation of the Estimator interface backed by the RPC interface of an active brocoind node. This implementation will proxy any fee estimation requests to brocoind's RPC interface.

func NewBrocoindEstimator

func NewBrocoindEstimator(rpcConfig rpcclient.ConnConfig, feeMode string,
	fallBackFeeRate SatPerKWeight) (*BrocoindEstimator, error)

NewBrocoindEstimator creates a new BrocoindEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the brocoind 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 (*BrocoindEstimator) EstimateFeePerKW

func (b *BrocoindEstimator) EstimateFeePerKW(
	numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW 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 Estimator interface.

func (*BrocoindEstimator) RelayFeePerKW

func (b *BrocoindEstimator) RelayFeePerKW() SatPerKWeight

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

NOTE: This method is part of the Estimator interface.

func (*BrocoindEstimator) Start

func (b *BrocoindEstimator) 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 (*BrocoindEstimator) Stop

func (b *BrocoindEstimator) 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 BrondEstimator

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

BrondEstimator is an implementation of the Estimator interface backed by the RPC interface of an active brond node. This implementation will proxy any fee estimation requests to brond's RPC interface.

func NewBrondEstimator

func NewBrondEstimator(rpcConfig rpcclient.ConnConfig,
	fallBackFeeRate SatPerKWeight) (*BrondEstimator, error)

NewBrondEstimator creates a new BrondEstimator given a fully populated rpc config that is able to successfully connect and authenticate with the brond 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 (*BrondEstimator) EstimateFeePerKW

func (b *BrondEstimator) EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW 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 Estimator interface.

func (*BrondEstimator) RelayFeePerKW

func (b *BrondEstimator) RelayFeePerKW() SatPerKWeight

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

NOTE: This method is part of the Estimator interface.

func (*BrondEstimator) Start

func (b *BrondEstimator) 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 (*BrondEstimator) Stop

func (b *BrondEstimator) 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 Estimator

type Estimator interface {
	// EstimateFeePerKW takes in a target for the number of blocks until an
	// initial confirmation and returns the estimated fee expressed in
	// sat/kw.
	EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, 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

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

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 SatPerKVByte

type SatPerKVByte bronutil.Amount

SatPerKVByte represents a fee rate in sat/kb.

func (SatPerKVByte) FeeForVSize

func (s SatPerKVByte) FeeForVSize(vbytes int64) bronutil.Amount

FeeForVSize calculates the fee resulting from this fee rate and the given vsize in vbytes.

func (SatPerKVByte) FeePerKWeight

func (s SatPerKVByte) FeePerKWeight() SatPerKWeight

FeePerKWeight converts the current fee rate from sat/kb to sat/kw.

func (SatPerKVByte) String

func (s SatPerKVByte) String() string

String returns a human-readable string of the fee rate.

type SatPerKWeight

type SatPerKWeight bronutil.Amount

SatPerKWeight represents a fee rate in sat/kw.

const (
	// FeePerKwFloor is the lowest fee rate in sat/kw that we should use for
	// estimating transaction fees before signing.
	FeePerKwFloor SatPerKWeight = 253

	// AbsoluteFeePerKwFloor is the lowest fee rate in sat/kw of a
	// transaction that we should ever _create_. This is the the equivalent
	// of 1 sat/byte in sat/kw.
	AbsoluteFeePerKwFloor SatPerKWeight = 250
)

func (SatPerKWeight) FeeForWeight

func (s SatPerKWeight) FeeForWeight(wu int64) bronutil.Amount

FeeForWeight calculates the fee resulting from this fee rate and the given weight in weight units (wu).

func (SatPerKWeight) FeePerKVByte

func (s SatPerKWeight) FeePerKVByte() SatPerKVByte

FeePerKVByte converts the current fee rate from sat/kw to sat/kb.

func (SatPerKWeight) String

func (s SatPerKWeight) String() string

String returns a human-readable string of the fee rate.

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 Brocoin. 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(feePerKW, relayFee SatPerKWeight) *StaticEstimator

NewStaticEstimator returns a new static fee estimator instance.

func (StaticEstimator) EstimateFeePerKW

func (e StaticEstimator) EstimateFeePerKW(numBlocks uint32) (SatPerKWeight, error)

EstimateFeePerKW will return a static value for fee calculations.

NOTE: This method is part of the Estimator interface.

func (StaticEstimator) RelayFeePerKW

func (e StaticEstimator) RelayFeePerKW() SatPerKWeight

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

NOTE: This method is part of the Estimator 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) EstimateFeePerKW

func (w *WebAPIEstimator) EstimateFeePerKW(numBlocks uint32) (
	SatPerKWeight, error)

EstimateFeePerKW 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 Estimator interface.

func (*WebAPIEstimator) RelayFeePerKW

func (w *WebAPIEstimator) RelayFeePerKW() SatPerKWeight

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

NOTE: This method is part of the Estimator 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