chain

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: ISC Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultGetRawTxBatchSize specifies the default number of requests to
	// be batched before sending them to the bitcoind client.
	DefaultGetRawTxBatchSize = 1000

	// DefaultBatchWaitInterval defines the default time to sleep between
	// each batched calls.
	DefaultBatchWaitInterval = 1 * time.Second
)

Variables

View Source
var (
	// ErrBackendVersion is returned when running against a bitcoind or
	// btcd that is older than the minimum version supported by the
	// rpcclient.
	ErrBackendVersion = errors.New("backend version too low")

	// ErrInvalidParam is returned when the caller provides an invalid
	// parameter to an RPC method.
	ErrInvalidParam = errors.New("invalid param")

	// ErrUndefined is used when an error returned is not recognized. We
	// should gradually increase our error types to avoid returning this
	// error.
	ErrUndefined = errors.New("undefined")
)
View Source
var Bitcoind28ErrMap = map[string]error{

	"transaction outputs already in utxo set": ErrTxAlreadyConfirmed,
}

Bitcoind28ErrMap contains error messages from bitcoind version v28.0 (and later) that are returned from the `testmempoolaccept` and are different than in previous versions.

View Source
var BtcdErrMap = map[string]error{

	"replacement transaction has an insufficient fee rate":     ErrInsufficientFee,
	"replacement transaction has an insufficient absolute fee": ErrInsufficientFee,

	"replacement transaction evicts more transactions than permitted": ErrTooManyReplacements,

	"replacement transaction spends new unconfirmed input": ErrReplacementAddsUnconfirmed,

	"replacement transaction spends parent transaction": ErrConflictingTx,

	"output already spent in mempool": ErrMempoolConflict,

	"transaction has no outputs": ErrEmptyOutput,

	"transaction has no inputs": ErrEmptyInput,

	"transaction contains duplicate inputs": ErrDuplicateInput,

	"transaction input refers to previous output that is null": ErrEmptyPrevOut,

	"fees which is under the required amount":               ErrMempoolMinFeeNotMet,
	"has insufficient priority":                             ErrInsufficientFee,
	"has been rejected by the rate limiter due to low fees": ErrInsufficientFee,

	"transaction output has negative value": ErrNegativeOutput,

	"transaction output value is higher than max allowed value": ErrLargeOutput,

	"total value of all transaction outputs exceeds max allowed value": ErrLargeTotalOutput,

	"sigop cost is too hight": ErrTooManySigOps,

	"database contains entry for spent tx output": ErrTxAlreadyKnown,
	"transaction already exists in blockchain":    ErrTxAlreadyConfirmed,

	"already have transaction in mempool": ErrTxAlreadyInMempool,

	"either does not exist or has already been spent": ErrMissingInputs,
	"orphan transaction":                              ErrMissingInputs,

	"serialized transaction is too big": ErrOversizeTx,

	"transaction is an invalid coinbase": ErrCoinbaseTx,

	"transaction version": ErrNonStandardVersion,

	"non-standard script form": ErrNonStandardScript,
	"has a non-standard input": ErrNonStandardScript,

	"milti-signature script": ErrBareMultiSig,

	"signature script is not push only": ErrScriptSigNotPushOnly,

	"signature script size is larger than max allowed": ErrScriptSigSize,

	"weight of transaction is larger than max allowed": ErrTxTooLarge,

	"payment is dust": ErrDust,

	"more than one transaction output in a nulldata script": ErrMultiOpReturn,

	"transaction is not finalized":               ErrNonFinal,
	"tried to spend coinbase transaction output": ErrNonFinal,

	"transaction's sequence locks on inputs not met": ErrNonBIP68Final,

	"missing-inputs": ErrMissingInputs,

	"max-fee-exceeded": ErrMaxFeeExceeded,
}

BtcdErrMap takes the errors returned from btcd's `testmempoolaccept` and `sendrawtransaction` RPCs and map them to the errors defined above, which are results from calling either `testmempoolaccept` or `sendrawtransaction` in `bitcoind`.

Errors not mapped in `btcd`:

  • deployment error from `validateSegWitDeployment`.
  • the error when total inputs is higher than max allowed value from `CheckTransactionInputs`.
  • the error when total outputs is higher than total inputs from `CheckTransactionInputs`.
  • errors from `CalcSequenceLock`.

NOTE: This is not an exhaustive list of errors, but it covers the usage case of LND.

View Source
var BtcdErrMapPre2402 = map[string]error{

	"is higher than max allowed value": ErrLargeOutput,

	"already spent by transaction": ErrMempoolConflict,

	"evicts more transactions than permitted": ErrTooManyReplacements,

	"spends parent transaction": ErrConflictingTx,

	"has an insufficient fee rate":     ErrInsufficientFee,
	"has an insufficient absolute fee": ErrInsufficientFee,

	"already have transaction": ErrTxAlreadyInMempool,

	"is an individual coinbase": ErrCoinbaseTx,

	"transaction already exists": ErrTxAlreadyConfirmed,

	"is larger than max allowed weight of": ErrTxTooLarge,

	"bytes is larger than max allowed size of": ErrScriptSigSize,

	"is dust": ErrDust,
}

BtcdErrMapPre2402 defines the error mapping for btcd versions prior to 0.24.2 - all the errors changed in this commit have been defined here to support older versions: - https://github.com/btcsuite/btcd/pull/2053/commits/ef54c49df443815d50765e8c4f31a87944d950a6

View Source
var (
	// ErrBitcoindClientShuttingDown is an error returned when we attempt
	// to receive a notification for a specific item and the bitcoind client
	// is in the middle of shutting down.
	ErrBitcoindClientShuttingDown = errors.New("client is shutting down")
)
View Source
var ErrBitcoindStartTimeout = errors.New("bitcoind start timeout")

ErrBitcoindStartTimeout is returned when the bitcoind daemon fails to load and verify blocks under 30s during startup.

View Source
var ErrUnimplemented = errors.New("unimplemented")

ErrUnimplemented is returned when a certain method is not implemented for a given interface.

Functions

func BackEnds

func BackEnds() []string

BackEnds returns a list of the available back ends. TODO: Refactor each into a driver and use dynamic registration.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger btclog.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 btclog.

Types

type BitcoindClient

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

BitcoindClient represents a persistent client connection to a bitcoind server for information regarding the current best block chain.

func SetupBitcoind

func SetupBitcoind(cfg *BitcoindConfig) (*BitcoindClient, error)

func (*BitcoindClient) BackEnd

func (c *BitcoindClient) BackEnd() string

BackEnd returns the name of the driver.

func (*BitcoindClient) BlockStamp

func (c *BitcoindClient) BlockStamp() (*waddrmgr.BlockStamp, error)

BlockStamp returns the latest block notified by the client, or an error if the client has been shut down.

func (*BitcoindClient) EstimateFee added in v0.0.13

func (c *BitcoindClient) EstimateFee(numBlocks int64) (float64, error)

func (*BitcoindClient) FilterBlocks

func (c *BitcoindClient) FilterBlocks(
	req *FilterBlocksRequest) (*FilterBlocksResponse, error)

FilterBlocks scans the blocks contained in the FilterBlocksRequest for any addresses of interest. Each block will be fetched and filtered sequentially, returning a FilterBlocksResponse for the first block containing a matching address. If no matches are found in the range of blocks requested, the returned response will be nil.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) GetBestBlock

func (c *BitcoindClient) GetBestBlock() (*chainhash.Hash, int32, error)

GetBestBlock returns the highest block known to bitcoind.

func (*BitcoindClient) GetBlock

func (c *BitcoindClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock returns a block from the hash.

func (*BitcoindClient) GetBlockHash

func (c *BitcoindClient) GetBlockHash(height int64) (*chainhash.Hash, error)

GetBlockHash returns a block hash from the height.

func (*BitcoindClient) GetBlockHeader

func (c *BitcoindClient) GetBlockHeader(
	hash *chainhash.Hash) (*wire.BlockHeader, error)

GetBlockHeader returns a block header from the hash.

func (*BitcoindClient) GetBlockHeaderVerbose

func (c *BitcoindClient) GetBlockHeaderVerbose(
	hash *chainhash.Hash) (*btcjson.GetBlockHeaderVerboseResult, error)

GetBlockHeaderVerbose returns a block header from the hash.

func (*BitcoindClient) GetBlockHeight

func (c *BitcoindClient) GetBlockHeight(hash *chainhash.Hash) (int32, error)

GetBlockHeight returns the height for the hash, if known, or returns an error.

func (*BitcoindClient) GetBlockVerbose

func (c *BitcoindClient) GetBlockVerbose(
	hash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error)

GetBlockVerbose returns a verbose block from the hash.

func (*BitcoindClient) GetRawMempool

func (c *BitcoindClient) GetRawMempool() ([]*chainhash.Hash, error)

GetRawMempool returns the raw mempool.

func (*BitcoindClient) GetRawTransaction

func (c *BitcoindClient) GetRawTransaction(
	hash *chainhash.Hash) (*btcutil.Tx, error)

GetRawTransaction returns a `btcutil.Tx` from the tx hash.

func (*BitcoindClient) GetRawTransactionVerbose

func (c *BitcoindClient) GetRawTransactionVerbose(
	hash *chainhash.Hash) (*btcjson.TxRawResult, error)

GetRawTransactionVerbose returns a TxRawResult from the tx hash.

func (*BitcoindClient) GetTxOut

func (c *BitcoindClient) GetTxOut(txHash *chainhash.Hash, index uint32,
	mempool bool) (*btcjson.GetTxOutResult, error)

GetTxOut returns a txout from the outpoint info provided.

func (*BitcoindClient) IsCurrent

func (c *BitcoindClient) IsCurrent() bool

IsCurrent returns whether the chain backend considers its view of the network as "current".

func (*BitcoindClient) LoadTxFilter

func (c *BitcoindClient) LoadTxFilter(reset bool, filters ...interface{}) error

LoadTxFilter uses the given filters to what we should match transactions against to determine if they are relevant to the client. The reset argument is used to reset the current filters.

The current filters supported are of the following types:

[]btcutil.Address
[]wire.OutPoint
[]*wire.OutPoint
map[wire.OutPoint]btcutil.Address
[]chainhash.Hash
[]*chainhash.Hash

func (*BitcoindClient) LookupInputMempoolSpend

func (c *BitcoindClient) LookupInputMempoolSpend(op wire.OutPoint) (
	chainhash.Hash, bool)

LookupInputMempoolSpend returns the transaction hash and true if the given input is found being spent in mempool, otherwise it returns nil and false.

func (*BitcoindClient) MapRPCErr added in v0.0.13

func (c *BitcoindClient) MapRPCErr(rpcErr error) error

MapRPCErr takes an error returned from calling RPC methods from various chain backends and maps it to an defined error here.

func (*BitcoindClient) Notifications

func (c *BitcoindClient) Notifications() <-chan interface{}

Notifications returns a channel to retrieve notifications from.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) NotifyBlocks

func (c *BitcoindClient) NotifyBlocks() error

NotifyBlocks allows the chain backend to notify the caller whenever a block is connected or disconnected.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) NotifyReceived

func (c *BitcoindClient) NotifyReceived(addrs []btcutil.Address) error

NotifyReceived allows the chain backend to notify the caller whenever a transaction pays to any of the given addresses.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) NotifySpent

func (c *BitcoindClient) NotifySpent(outPoints []*wire.OutPoint) error

NotifySpent allows the chain backend to notify the caller whenever a transaction spends any of the given outpoints.

func (*BitcoindClient) NotifyTx

func (c *BitcoindClient) NotifyTx(txids []chainhash.Hash) error

NotifyTx allows the chain backend to notify the caller whenever any of the given transactions confirm within the chain.

func (*BitcoindClient) PublicNotifications added in v0.0.13

func (c *BitcoindClient) PublicNotifications() <-chan interface{}

func (*BitcoindClient) Rescan

func (c *BitcoindClient) Rescan(blockHash *chainhash.Hash,
	addresses []btcutil.Address, outPoints map[wire.OutPoint]btcutil.Address) error

Rescan rescans from the block with the given hash until the current block, after adding the passed addresses and outpoints to the client's watch list.

func (*BitcoindClient) RescanBlocks

func (c *BitcoindClient) RescanBlocks(
	blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, error)

RescanBlocks rescans any blocks passed, returning only the blocks that matched as []btcjson.BlockDetails.

func (*BitcoindClient) SendRawTransaction

func (c *BitcoindClient) SendRawTransaction(tx *wire.MsgTx,
	allowHighFees bool) (*chainhash.Hash, error)

SendRawTransaction sends a raw transaction via bitcoind.

func (*BitcoindClient) SetBirthday

func (c *BitcoindClient) SetBirthday(t time.Time)

SetBirthday sets the birthday of the bitcoind rescan client.

NOTE: This should be done before the client has been started in order for it to properly carry its duties.

func (*BitcoindClient) Start

func (c *BitcoindClient) Start() error

Start initializes the bitcoind rescan client using the backing bitcoind connection and starts all goroutines necessary in order to process rescans and ZMQ notifications.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) Stop

func (c *BitcoindClient) Stop()

Stop stops the bitcoind rescan client from processing rescans and ZMQ notifications.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) TestMempoolAccept

func (c *BitcoindClient) TestMempoolAccept(txns []*wire.MsgTx,
	maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error)

TestMempoolAcceptCmd returns result of mempool acceptance tests indicating if raw transaction(s) would be accepted by mempool.

NOTE: This is part of the chain.Interface interface.

func (*BitcoindClient) WaitForShutdown

func (c *BitcoindClient) WaitForShutdown()

WaitForShutdown blocks until the client has finished disconnecting and all handlers have exited.

NOTE: This is part of the chain.Interface interface.

type BitcoindConfig

type BitcoindConfig struct {
	// ChainParams are the chain parameters the bitcoind server is running
	// on.
	ChainParams *chaincfg.Params

	// Host is the IP address and port of the bitcoind's RPC server.
	Host string

	// User is the username to use to authenticate to bitcoind's RPC server.
	User string

	// Pass is the passphrase to use to authenticate to bitcoind's RPC
	// server.
	Pass string

	// ZMQConfig holds the configuration settings required for setting up
	// zmq connections to bitcoind.
	ZMQConfig *ZMQConfig

	// PollingConfig holds the configuration settings required for using
	// RPC polling for block and transaction notifications instead of the
	// ZMQ interface.
	PollingConfig *PollingConfig

	// Dialer is a closure we'll use to dial Bitcoin peers. If the chain
	// backend is running over Tor, this must support dialing peers over Tor
	// as well.
	Dialer Dialer

	// PrunedModeMaxPeers is the maximum number of peers we'll attempt to
	// retrieve pruned blocks from.
	//
	// NOTE: This only applies for pruned bitcoind nodes.
	PrunedModeMaxPeers int

	ConnectionTimeout time.Duration
}

BitcoindConfig contains all of the parameters required to establish a connection to a bitcoind's RPC.

func NewBitcoindConfig

func NewBitcoindConfig(host, user, password string) *BitcoindConfig

type BitcoindConn

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

BitcoindConn represents a persistent client connection to a bitcoind node that listens for events read from a ZMQ connection.

func NewBitcoindConn

func NewBitcoindConn(cfg *BitcoindConfig) (*BitcoindConn, error)

NewBitcoindConn creates a client connection to the node described by the host string. The ZMQ connections are established immediately to ensure liveness. If the remote node does not operate on the same bitcoin network as described by the passed chain parameters, the connection will be disconnected.

func (*BitcoindConn) AddClient

func (c *BitcoindConn) AddClient(client *BitcoindClient)

AddClient adds a client to the set of active rescan clients of the current chain connection. This allows the connection to include the specified client in its notification delivery.

NOTE: This function is safe for concurrent access.

func (*BitcoindConn) GetBlock

func (c *BitcoindConn) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock returns a raw block from the server given its hash. If the server has already pruned the block, it will be retrieved from one of its peers.

func (*BitcoindConn) NewBitcoindClient

func (c *BitcoindConn) NewBitcoindClient() *BitcoindClient

NewBitcoindClient returns a bitcoind client using the current bitcoind connection. This allows us to share the same connection using multiple clients.

func (*BitcoindConn) RemoveClient

func (c *BitcoindConn) RemoveClient(id uint64)

RemoveClient removes the client with the given ID from the set of active rescan clients. Once removed, the client will no longer receive block and transaction notifications from the chain connection.

NOTE: This function is safe for concurrent access.

func (*BitcoindConn) Start

func (c *BitcoindConn) Start() error

Start attempts to establish a RPC and ZMQ connection to a bitcoind node. If successful, a goroutine is spawned to read events from the ZMQ connection. It's possible for this function to fail due to a limited number of connection attempts. This is done to prevent waiting forever on the connection to be established in the case that the node is down.

func (*BitcoindConn) Stop

func (c *BitcoindConn) Stop()

Stop terminates the RPC and ZMQ connection to a bitcoind node and removes any active rescan clients.

type BitcoindEvents

type BitcoindEvents interface {
	// TxNotifications will return a channel which will deliver new
	// transactions.
	TxNotifications() <-chan *wire.MsgTx

	// BlockNotifications will return a channel which will deliver new
	// blocks.
	BlockNotifications() <-chan *wire.MsgBlock

	// LookupInputSpend will return the transaction found in mempool that
	// spends the given input.
	LookupInputSpend(op wire.OutPoint) (chainhash.Hash, bool)

	// Start will kick off any goroutines required for operation.
	Start() error

	// Stop will clean up any resources and goroutines.
	Stop() error
}

BitcoindEvents is the interface that must be satisfied by any type that serves bitcoind block and transactions events.

func NewBitcoindEventSubscriber

func NewBitcoindEventSubscriber(cfg *BitcoindConfig, client *rpcclient.Client,
	bClient batchClient) (BitcoindEvents, error)

NewBitcoindEventSubscriber initialises a new BitcoinEvents object impl depending on the config passed.

type BlockConnected

type BlockConnected wtxmgr.BlockMeta

BlockConnected is a notification for a newly-attached block to the best chain.

type BlockDisconnected

type BlockDisconnected wtxmgr.BlockMeta

BlockDisconnected is a notifcation that the block described by the BlockStamp was reorganized out of the best chain.

type BlockFilterer

type BlockFilterer struct {
	// Params specifies the chain params of the current network.
	Params *chaincfg.Params

	// ExReverseFilter holds a reverse index mapping an external address to
	// the scoped index from which it was derived.
	ExReverseFilter map[string]waddrmgr.ScopedIndex

	// InReverseFilter holds a reverse index mapping an internal address to
	// the scoped index from which it was derived.
	InReverseFilter map[string]waddrmgr.ScopedIndex

	// WathcedOutPoints is a global set of outpoints being tracked by the
	// wallet. This allows the block filterer to check for spends from an
	// outpoint we own.
	WatchedOutPoints map[wire.OutPoint]btcutil.Address

	// FoundExternal is a two-layer map recording the scope and index of
	// external addresses found in a single block.
	FoundExternal map[waddrmgr.KeyScope]map[uint32]struct{}

	// FoundInternal is a two-layer map recording the scope and index of
	// internal addresses found in a single block.
	FoundInternal map[waddrmgr.KeyScope]map[uint32]struct{}

	// FoundOutPoints is a set of outpoints found in a single block whose
	// address belongs to the wallet.
	FoundOutPoints map[wire.OutPoint]btcutil.Address

	// RelevantTxns records the transactions found in a particular block
	// that contained matches from an address in either ExReverseFilter or
	// InReverseFilter.
	RelevantTxns []*wire.MsgTx
}

BlockFilterer is used to iteratively scan blocks for a set of addresses of interest. This is done by constructing reverse indexes mapping the addresses to a ScopedIndex, which permits the reconstruction of the exact child deriviation paths that reported matches.

Once initialized, a BlockFilterer can be used to scan any number of blocks until a invocation of `FilterBlock` returns true. This allows the reverse indexes to be resused in the event that the set of addresses does not need to be altered. After a match is reported, a new BlockFilterer should be initialized with the updated set of addresses that include any new keys that are now within our look-ahead.

We track internal and external addresses separately in order to conserve the amount of space occupied in memory. Specifically, the account and branch combined contribute only 1-bit of information when using the default scopes used by the wallet. Thus we can avoid storing an additional 64-bits per address of interest by not storing the full derivation paths, and instead opting to allow the caller to contextually infer the account (DefaultAccount) and branch (Internal or External).

func NewBlockFilterer

func NewBlockFilterer(params *chaincfg.Params,
	req *FilterBlocksRequest) *BlockFilterer

NewBlockFilterer constructs the reverse indexes for the current set of external and internal addresses that we are searching for, and is used to scan successive blocks for addresses of interest. A particular block filter can be reused until the first call from `FitlerBlock` returns true.

func (*BlockFilterer) FilterBlock

func (bf *BlockFilterer) FilterBlock(block *wire.MsgBlock) bool

FilterBlock parses all txns in the provided block, searching for any that contain addresses of interest in either the external or internal reverse filters. This method return true iff the block contains a non-zero number of addresses of interest, or a transaction in the block spends from outpoints controlled by the wallet.

func (*BlockFilterer) FilterOutputAddrs

func (bf *BlockFilterer) FilterOutputAddrs(addrs []btcutil.Address) bool

FilterOutputAddrs tests the set of addresses against the block filterer's external and internal reverse address indexes. If any are found, they are added to set of external and internal found addresses, respectively. This method returns true iff a non-zero number of the provided addresses are of interest.

func (*BlockFilterer) FilterTx

func (bf *BlockFilterer) FilterTx(tx *wire.MsgTx) bool

FilterTx scans all txouts in the provided txn, testing to see if any found addresses match those contained within the external or internal reverse indexes. This method returns true iff the txn contains a non-zero number of addresses of interest, or the transaction spends from an outpoint that belongs to the wallet.

type ClientConnected

type ClientConnected struct{}

ClientConnected is a notification for when a client connection is opened or reestablished to the chain server.

type ConcurrentQueue

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

ConcurrentQueue is a concurrent-safe FIFO queue with unbounded capacity. Clients interact with the queue by pushing items into the in channel and popping items from the out channel. There is a goroutine that manages moving items from the in channel to the out channel in the correct order that must be started by calling Start().

func NewConcurrentQueue

func NewConcurrentQueue(bufferSize int) *ConcurrentQueue

NewConcurrentQueue constructs a ConcurrentQueue. The bufferSize parameter is the capacity of the output channel. When the size of the queue is below this threshold, pushes do not incur the overhead of the less efficient overflow structure.

func (*ConcurrentQueue) ChanIn

func (cq *ConcurrentQueue) ChanIn() chan<- interface{}

ChanIn returns a channel that can be used to push new items into the queue.

func (*ConcurrentQueue) ChanOut

func (cq *ConcurrentQueue) ChanOut() <-chan interface{}

ChanOut returns a channel that can be used to pop items from the queue.

func (*ConcurrentQueue) Start

func (cq *ConcurrentQueue) Start()

Start begins a goroutine that manages moving items from the in channel to the out channel. The queue tries to move items directly to the out channel minimize overhead, but if the out channel is full it pushes items to an overflow queue. This must be called before using the queue.

func (*ConcurrentQueue) Stop

func (cq *ConcurrentQueue) Stop()

Stop ends the goroutine that moves items from the in channel to the out channel.

type Dialer

type Dialer = func(string) (net.Conn, error)

Dialer represents a way to dial Bitcoin peers. If the chain backend is running over Tor, this must support dialing peers over Tor as well.

type FilterBlocksRequest

type FilterBlocksRequest struct {
	Blocks           []wtxmgr.BlockMeta
	ExternalAddrs    map[waddrmgr.ScopedIndex]btcutil.Address
	InternalAddrs    map[waddrmgr.ScopedIndex]btcutil.Address
	WatchedOutPoints map[wire.OutPoint]btcutil.Address
}

FilterBlocksRequest specifies a range of blocks and the set of internal and external addresses of interest, indexed by corresponding scoped-index of the child address. A global set of watched outpoints is also included to monitor for spends.

type FilterBlocksResponse

type FilterBlocksResponse struct {
	BatchIndex         uint32
	BlockMeta          wtxmgr.BlockMeta
	FoundExternalAddrs map[waddrmgr.KeyScope]map[uint32]struct{}
	FoundInternalAddrs map[waddrmgr.KeyScope]map[uint32]struct{}
	FoundOutPoints     map[wire.OutPoint]btcutil.Address
	RelevantTxns       []*wire.MsgTx
}

FilterBlocksResponse reports the set of all internal and external addresses found in response to a FilterBlockRequest, any outpoints found that correspond to those addresses, as well as the relevant transactions that can modify the wallet's balance. The index of the block within the FilterBlocksRequest is returned, such that the caller can reinitiate a request for the subsequent block after updating the addresses of interest.

type FilteredBlockConnected

type FilteredBlockConnected struct {
	Block       *wtxmgr.BlockMeta
	RelevantTxs []*wtxmgr.TxRecord
}

FilteredBlockConnected is an alternate notification that contains both block and relevant transaction information in one struct, which allows atomic updates.

type Interface

type Interface interface {
	Start() error
	Stop()
	WaitForShutdown()
	GetBestBlock() (*chainhash.Hash, int32, error)
	GetBlock(*chainhash.Hash) (*wire.MsgBlock, error)
	GetBlockHash(int64) (*chainhash.Hash, error)
	GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error)
	IsCurrent() bool
	FilterBlocks(*FilterBlocksRequest) (*FilterBlocksResponse, error)
	BlockStamp() (*waddrmgr.BlockStamp, error)
	SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash, error)
	Rescan(*chainhash.Hash, []btcutil.Address, map[wire.OutPoint]btcutil.Address) error
	NotifyReceived([]btcutil.Address) error
	NotifyBlocks() error
	Notifications() <-chan interface{}
	// PublicNotifications returns a channel to receive public notifications
	PublicNotifications() <-chan interface{}
	BackEnd() string
	TestMempoolAccept([]*wire.MsgTx, float64) ([]*btcjson.TestMempoolAcceptResult, error)
	MapRPCErr(err error) error
	EstimateFee(numBlocks int64) (float64, error)
}

Interface allows more than one backing blockchain source, such as a btcd RPC chain server, or an SPV library, as long as we write a driver for it.

type JitterTicker

type JitterTicker struct {
	// C is a read-only channel that receives ticks.
	C <-chan time.Time
	// contains filtered or unexported fields
}

JitterTicker is a ticker that adds jitter to the tick duration.

func NewJitterTicker

func NewJitterTicker(d time.Duration, jitter float64) *JitterTicker

NewJitterTicker returns a new JitterTicker.

func (*JitterTicker) Stop

func (jt *JitterTicker) Stop()

Stop stops the ticker.

type NeutrinoChainService

type NeutrinoChainService interface {
	Start() error
	GetBlock(chainhash.Hash, ...neutrino.QueryOption) (*btcutil.Block, error)
	GetBlockHeight(*chainhash.Hash) (int32, error)
	BestBlock() (*headerfs.BlockStamp, error)
	GetBlockHash(int64) (*chainhash.Hash, error)
	GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error)
	IsCurrent() bool
	SendTransaction(*wire.MsgTx) error
	GetCFilter(chainhash.Hash, wire.FilterType,
		...neutrino.QueryOption) (*gcs.Filter, error)
	GetUtxo(...neutrino.RescanOption) (*neutrino.SpendReport, error)
	BanPeer(string, banman.Reason) error
	IsBanned(addr string) bool
	AddPeer(*neutrino.ServerPeer)
	AddBytesSent(uint64)
	AddBytesReceived(uint64)
	NetTotals() (uint64, uint64)
	UpdatePeerHeights(*chainhash.Hash, int32, *neutrino.ServerPeer)
	ChainParams() chaincfg.Params
	Stop() error
	PeerByAddr(string) *neutrino.ServerPeer
}

NeutrinoChainService is an interface that encapsulates all the public methods of a *neutrino.ChainService

type NeutrinoClient

type NeutrinoClient struct {
	CS NeutrinoChainService
	// contains filtered or unexported fields
}

NeutrinoClient is an implementation of the btcwallet chain.Interface interface.

func NewNeutrinoClient

func NewNeutrinoClient(chainParams *chaincfg.Params,
	chainService *neutrino.ChainService) *NeutrinoClient

NewNeutrinoClient creates a new NeutrinoClient struct with a backing ChainService.

func (*NeutrinoClient) BackEnd

func (s *NeutrinoClient) BackEnd() string

BackEnd returns the name of the driver.

func (*NeutrinoClient) BlockStamp

func (s *NeutrinoClient) BlockStamp() (*waddrmgr.BlockStamp, error)

BlockStamp returns the latest block notified by the client, or an error if the client has been shut down.

func (*NeutrinoClient) EstimateFee added in v0.0.13

func (c *NeutrinoClient) EstimateFee(numBlocks int64) (float64, error)

func (*NeutrinoClient) FilterBlocks

func (s *NeutrinoClient) FilterBlocks(
	req *FilterBlocksRequest) (*FilterBlocksResponse, error)

FilterBlocks scans the blocks contained in the FilterBlocksRequest for any addresses of interest. For each requested block, the corresponding compact filter will first be checked for matches, skipping those that do not report anything. If the filter returns a positive match, the full block will be fetched and filtered. This method returns a FilterBlocksResponse for the first block containing a matching address. If no matches are found in the range of blocks requested, the returned response will be nil.

func (*NeutrinoClient) GetBestBlock

func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, error)

GetBestBlock replicates the RPC client's GetBestBlock command.

func (*NeutrinoClient) GetBlock

func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, error)

GetBlock replicates the RPC client's GetBlock command.

func (*NeutrinoClient) GetBlockHash

func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error)

GetBlockHash returns the block hash for the given height, or an error if the client has been shut down or the hash at the block height doesn't exist or is unknown.

func (*NeutrinoClient) GetBlockHeader

func (s *NeutrinoClient) GetBlockHeader(
	blockHash *chainhash.Hash) (*wire.BlockHeader, error)

GetBlockHeader returns the block header for the given block hash, or an error if the client has been shut down or the hash doesn't exist or is unknown.

func (*NeutrinoClient) GetBlockHeight

func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, error)

GetBlockHeight gets the height of a block by its hash. It serves as a replacement for the use of GetBlockVerboseTxAsync for the wallet package since we can't actually return a FutureGetBlockVerboseResult because the underlying type is private to rpcclient.

func (*NeutrinoClient) IsCurrent

func (s *NeutrinoClient) IsCurrent() bool

IsCurrent returns whether the chain backend considers its view of the network as "current".

func (*NeutrinoClient) MapRPCErr added in v0.0.13

func (s *NeutrinoClient) MapRPCErr(rpcErr error) error

MapRPCErr takes an error returned from calling RPC methods from various chain backends and maps it to an defined error here. It uses the `BtcdErrMap`, whose keys are btcd error strings and values are errors made from bitcoind error strings.

NOTE: we assume neutrino shares the same error strings as btcd.

func (*NeutrinoClient) Notifications

func (s *NeutrinoClient) Notifications() <-chan interface{}

Notifications replicates the RPC client's Notifications method.

func (*NeutrinoClient) NotifyBlocks

func (s *NeutrinoClient) NotifyBlocks() error

NotifyBlocks replicates the RPC client's NotifyBlocks command.

func (*NeutrinoClient) NotifyReceived

func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error

NotifyReceived replicates the RPC client's NotifyReceived command.

func (*NeutrinoClient) PublicNotifications added in v0.0.13

func (s *NeutrinoClient) PublicNotifications() <-chan interface{}

func (*NeutrinoClient) Rescan

func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address,
	outPoints map[wire.OutPoint]btcutil.Address) error

Rescan replicates the RPC client's Rescan command.

func (*NeutrinoClient) SendRawTransaction

func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (
	*chainhash.Hash, error)

SendRawTransaction replicates the RPC client's SendRawTransaction command.

func (*NeutrinoClient) SetStartTime

func (s *NeutrinoClient) SetStartTime(startTime time.Time)

SetStartTime is a non-interface method to set the birthday of the wallet using this object. Since only a single rescan at a time is currently supported, only one birthday needs to be set. This does not fully restart a running rescan, so should not be used to update a rescan while it is running. TODO: When factoring out to multiple rescans per Neutrino client, add a birthday per client.

func (*NeutrinoClient) Start

func (s *NeutrinoClient) Start() error

Start replicates the RPC client's Start method.

func (*NeutrinoClient) Stop

func (s *NeutrinoClient) Stop()

Stop replicates the RPC client's Stop method.

TODO(mstreet3): The Stop method does not cancel the long-running rescan goroutine. This is a memory leak. Stop should shutdown the rescan goroutine and reset the scanning state of the NeutrinoClient to false.

func (*NeutrinoClient) TestMempoolAccept

func (s *NeutrinoClient) TestMempoolAccept(txns []*wire.MsgTx,
	maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error)

TestMempoolAcceptCmd returns result of mempool acceptance tests indicating if raw transaction(s) would be accepted by mempool.

NOTE: This is part of the chain.Interface interface.

func (*NeutrinoClient) WaitForShutdown

func (s *NeutrinoClient) WaitForShutdown()

WaitForShutdown replicates the RPC client's WaitForShutdown method.

type PollingConfig

type PollingConfig struct {
	// BlockPollingInterval is the interval that will be used to poll
	// bitcoind for new blocks.
	BlockPollingInterval time.Duration

	// TxPollingInterval is the interval that will be used to poll bitcoind
	// for new transactions. If a jitter factor is configed, it will be
	// applied to this value to provide randomness in the range,
	// - max: TxPollingInterval * (1 + TxPollingIntervalJitter)
	// - min: TxPollingInterval * (1 - TxPollingIntervalJitter)
	TxPollingInterval time.Duration

	// TxPollingIntervalScale defines a factor that's used to simulates
	// jitter by scaling TxPollingInterval with it. This value must be no
	// less than 0. Default to 0, meaning no jitter will be applied.
	TxPollingIntervalJitter float64

	// RPCBatchSize defines the number of RPC requests to be batches before
	// sending them to the bitcoind node.
	RPCBatchSize uint32

	// RPCBatchInterval defines the time to wait before attempting the next
	// batch when the current one finishes.
	RPCBatchInterval time.Duration
}

PollingConfig holds all the config options used for setting up bitcoindRPCPollingEvents.

type PrunedBlockDispatcher

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

PrunedBlockDispatcher enables a chain client to request blocks that the server has already pruned. This is done by connecting to the server's full node peers and querying them directly. Ideally, this is a capability supported by the server, though this is not yet possible with bitcoind.

func NewPrunedBlockDispatcher

func NewPrunedBlockDispatcher(cfg *PrunedBlockDispatcherConfig) (
	*PrunedBlockDispatcher, error)

NewPrunedBlockDispatcher initializes a new PrunedBlockDispatcher instance backed by the given config.

func (*PrunedBlockDispatcher) CancelRequest

func (d *PrunedBlockDispatcher) CancelRequest(blockHash chainhash.Hash,
	err error)

CancelRequest removes all information regarding a failed block request. When for example the Peer disconnects or runs in a timeout we make sure that all related information is deleted and a new request for this block can be registered. Moreover will also cancel all depending goroutines.

func (*PrunedBlockDispatcher) Query

func (d *PrunedBlockDispatcher) Query(blocks []*chainhash.Hash,
	cancelChan chan<- error,
	opts ...query.QueryOption) (<-chan *wire.MsgBlock, <-chan error)

Query submits a request to query the information of the given blocks.

func (*PrunedBlockDispatcher) Start

func (d *PrunedBlockDispatcher) Start() error

Start allows the PrunedBlockDispatcher to begin handling incoming block requests.

func (*PrunedBlockDispatcher) Stop

func (d *PrunedBlockDispatcher) Stop()

Stop stops the PrunedBlockDispatcher from accepting any more incoming block requests.

type PrunedBlockDispatcherConfig

type PrunedBlockDispatcherConfig struct {
	// ChainParams represents the parameters of the current active chain.
	ChainParams *chaincfg.Params

	// NumTargetPeer represents the target number of peers we should
	// maintain connections with. This exists to prevent establishing
	// connections to all of the bitcoind's peers, which would be
	// unnecessary and ineffecient.
	NumTargetPeers int

	// Dial establishes connections to Bitcoin peers. This must support
	// dialing peers running over Tor if the backend also supports it.
	Dial func(string) (net.Conn, error)

	// GetPeers retrieves the active set of peers known to the backend node.
	GetPeers func() ([]btcjson.GetPeerInfoResult, error)

	// GetNodeAddresses returns random reachable addresses known to the
	// backend node. An optional number of addresses to return can be
	// provided, otherwise 8 are returned by default.
	GetNodeAddresses func(*int32) ([]btcjson.GetNodeAddressesResult, error)

	// PeerReadyTimeout is the amount of time we'll wait for a query peer to
	// be ready to receive incoming block requests. Peers cannot respond to
	// requests until the version exchange is completed upon connection
	// establishment.
	PeerReadyTimeout time.Duration

	// RefreshPeersTicker is the polling ticker that signals us when we
	// should attempt to refresh the set of known peers.
	RefreshPeersTicker ticker.Ticker

	// AllowSelfPeerConns is only used to allow the tests to bypass the peer
	// self connection detecting and disconnect logic since they
	// intentionally do so for testing purposes.
	AllowSelfPeerConns bool

	// MaxRequestInvs dictates how many invs we should fit in a single
	// getdata request to a peer. This only exists to facilitate the testing
	// of a request spanning multiple getdata messages.
	MaxRequestInvs int
}

PrunedBlockDispatcherConfig encompasses all of the dependencies required by the PrunedBlockDispatcher to carry out its duties.

type RPCClient

type RPCClient struct {
	*rpcclient.Client
	// contains filtered or unexported fields
}

RPCClient represents a persistent client connection to a bitcoin RPC server for information regarding the current best block chain.

func NewRPCClient

func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, certs []byte,
	disableTLS bool, reconnectAttempts int) (*RPCClient, error)

NewRPCClient creates a client connection to the server described by the connect string. If disableTLS is false, the remote RPC certificate must be provided in the certs slice. The connection is not established immediately, but must be done using the Start method. If the remote server does not operate on the same bitcoin network as described by the passed chain parameters, the connection will be disconnected.

TODO(yy): deprecate it in favor of NewRPCClientWithConfig.

func NewRPCClientWithConfig

func NewRPCClientWithConfig(cfg *RPCClientConfig) (*RPCClient, error)

NewRPCClientWithConfig creates a client connection to the server based on the config options supplised.

The connection is not established immediately, but must be done using the Start method. If the remote server does not operate on the same bitcoin network as described by the passed chain parameters, the connection will be disconnected.

func (*RPCClient) BackEnd

func (c *RPCClient) BackEnd() string

BackEnd returns the name of the driver.

func (*RPCClient) BlockStamp

func (c *RPCClient) BlockStamp() (*waddrmgr.BlockStamp, error)

BlockStamp returns the latest block notified by the client, or an error if the client has been shut down.

func (*RPCClient) EstimateFee added in v0.0.13

func (c *RPCClient) EstimateFee(numBlocks int64) (float64, error)

func (*RPCClient) FilterBlocks

func (c *RPCClient) FilterBlocks(
	req *FilterBlocksRequest) (*FilterBlocksResponse, error)

FilterBlocks scans the blocks contained in the FilterBlocksRequest for any addresses of interest. For each requested block, the corresponding compact filter will first be checked for matches, skipping those that do not report anything. If the filter returns a positive match, the full block will be fetched and filtered. This method returns a FilterBlocksResponse for the first block containing a matching address. If no matches are found in the range of blocks requested, the returned response will be nil.

func (*RPCClient) IsCurrent

func (c *RPCClient) IsCurrent() bool

IsCurrent returns whether the chain backend considers its view of the network as "current".

func (*RPCClient) LookupInputMempoolSpend

func (c *RPCClient) LookupInputMempoolSpend(op wire.OutPoint) (
	chainhash.Hash, bool)

LookupInputMempoolSpend returns the transaction hash and true if the given input is found being spent in mempool, otherwise it returns nil and false.

func (*RPCClient) MapRPCErr added in v0.0.13

func (c *RPCClient) MapRPCErr(rpcErr error) error

MapRPCErr takes an error returned from calling RPC methods from various chain backends and maps it to an defined error here. It uses the `BtcdErrMap`, whose keys are btcd error strings and values are errors made from bitcoind error strings.

func (*RPCClient) Notifications

func (c *RPCClient) Notifications() <-chan interface{}

Notifications returns a channel of parsed notifications sent by the remote bitcoin RPC server. This channel must be continually read or the process may abort for running out memory, as unread notifications are queued for later reads.

func (*RPCClient) POSTClient

func (c *RPCClient) POSTClient() (*rpcclient.Client, error)

POSTClient creates the equivalent HTTP POST rpcclient.Client.

func (*RPCClient) PublicNotifications added in v0.0.13

func (c *RPCClient) PublicNotifications() <-chan interface{}

func (*RPCClient) Rescan

func (c *RPCClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address,
	outPoints map[wire.OutPoint]btcutil.Address) error

Rescan wraps the normal Rescan command with an additional parameter that allows us to map an outpoint to the address in the chain that it pays to. This is useful when using BIP 158 filters as they include the prev pkScript rather than the full outpoint.

func (*RPCClient) SendRawTransaction added in v0.0.13

func (c *RPCClient) SendRawTransaction(tx *wire.MsgTx,
	allowHighFees bool) (*chainhash.Hash, error)

SendRawTransaction sends a raw transaction via btcd.

func (*RPCClient) Start

func (c *RPCClient) Start() error

Start attempts to establish a client connection with the remote server. If successful, handler goroutines are started to process notifications sent by the server. After a limited number of connection attempts, this function gives up, and therefore will not block forever waiting for the connection to be established to a server that may not exist.

func (*RPCClient) Stop

func (c *RPCClient) Stop()

Stop disconnects the client and signals the shutdown of all goroutines started by Start.

func (*RPCClient) WaitForShutdown

func (c *RPCClient) WaitForShutdown()

WaitForShutdown blocks until both the client has finished disconnecting and all handlers have exited.

type RPCClientConfig

type RPCClientConfig struct {
	// Conn describes the connection configuration parameters for the
	// client.
	Conn *rpcclient.ConnConfig

	// Params defines a Bitcoin network by its parameters.
	Chain *chaincfg.Params

	// NotificationHandlers defines callback function pointers to invoke
	// with notifications. If not set, the default handlers defined in this
	// client will be used.
	NotificationHandlers *rpcclient.NotificationHandlers

	// ReconnectAttempts defines the number to reties (each after an
	// increasing backoff) if the connection can not be established.
	ReconnectAttempts int
}

RPCClientConfig defines the config options used when initializing the RPC Client.

type RPCErr added in v0.0.13

type RPCErr uint32

RPCErr represents an error returned by bitcoind's RPC server.

const (
	// ErrMissingInputsOrSpent is returned when calling
	// `sendrawtransaction` with missing inputs.
	ErrMissingInputsOrSpent RPCErr = iota

	// ErrMaxBurnExceeded is returned when calling `sendrawtransaction`
	// with exceeding, falling short of, and equaling maxburnamount.
	ErrMaxBurnExceeded

	// ErrMaxFeeExceeded can happen when passing a signed tx to
	// `testmempoolaccept`, but the tx pays more fees than specified.
	ErrMaxFeeExceeded

	// ErrTxAlreadyKnown is used in the `reject-reason` field of
	// `testmempoolaccept` when a transaction is already in the blockchain.
	ErrTxAlreadyKnown

	// ErrTxAlreadyConfirmed is returned as an error from
	// `sendrawtransaction` when a transaction is already in the
	// blockchain.
	ErrTxAlreadyConfirmed

	// ErrMempoolConflict happens when RBF is not enabled yet the
	// transaction conflicts with an unconfirmed tx.  .
	//
	// NOTE: RBF rule 1.
	ErrMempoolConflict

	// ErrReplacementAddsUnconfirmed is returned when a transaction adds
	// new unconfirmed inputs.
	//
	// NOTE: RBF rule 2.
	ErrReplacementAddsUnconfirmed

	// ErrInsufficientFee is returned when fee rate used or fees paid
	// doesn't meet the requirements.
	//
	// NOTE: RBF rule 3 or 4.
	ErrInsufficientFee

	// ErrTooManyReplacements is returned when a transaction causes too
	// many transactions being replaced. This is set by
	// `MAX_REPLACEMENT_CANDIDATES` in `bitcoind` and defaults to 100.
	//
	// NOTE: RBF rule 5.
	ErrTooManyReplacements

	// ErrMempoolMinFeeNotMet is returned when the transaction doesn't meet
	// the minimum relay fee.
	ErrMempoolMinFeeNotMet

	// ErrConflictingTx is returned when a transaction that spends
	// conflicting tx outputs that are rejected.
	ErrConflictingTx

	// ErrEmptyOutput is returned when a transaction has no outputs.
	ErrEmptyOutput

	// ErrEmptyInput is returned when a transaction has no inputs.
	ErrEmptyInput

	// ErrTxTooSmall is returned when spending a tiny transaction(in
	// non-witness bytes) that is disallowed.
	//
	// NOTE: ErrTxTooLarge must be put after ErrTxTooSmall because it's a
	// subset of ErrTxTooSmall. Otherwise, if bitcoind returns
	// `tx-size-small`, it will be matched to ErrTxTooLarge.
	ErrTxTooSmall

	// ErrDuplicateInput is returned when a transaction has duplicate
	// inputs.
	ErrDuplicateInput

	// ErrEmptyPrevOut is returned when a non-coinbase transaction has
	// coinbase-like outpoint.
	ErrEmptyPrevOut

	// ErrBelowOutValue is returned when a transaction's output value is
	// greater than its input value.
	ErrBelowOutValue

	// ErrNegativeOutput is returned when a transaction has negative output
	// value.
	ErrNegativeOutput

	// ErrLargeOutput is returned when a transaction has too large output
	// value.
	ErrLargeOutput

	// ErrLargeTotalOutput is returned when a transaction has too large sum
	// of output values.
	ErrLargeTotalOutput

	// ErrScriptVerifyFlag is returned when there is invalid OP_IF
	// construction.
	ErrScriptVerifyFlag

	// ErrTooManySigOps is returned when a transaction has too many sigops.
	ErrTooManySigOps

	// ErrInvalidOpcode is returned when a transaction has invalid OP
	// codes.
	ErrInvalidOpcode

	// ErrTxAlreadyInMempool is returned when a transaction is in the
	// mempool.
	ErrTxAlreadyInMempool

	// ErrMissingInputs is returned when a transaction has missing inputs,
	// that never existed or only existed once in the past.
	ErrMissingInputs

	// ErrOversizeTx is returned when a transaction is too large.
	ErrOversizeTx

	// ErrCoinbaseTx is returned when the transaction is coinbase tx.
	ErrCoinbaseTx

	// ErrNonStandardVersion is returned when the transactions are not
	// standard - a version currently non-standard.
	ErrNonStandardVersion

	// ErrNonStandardScript is returned when the transactions are not
	// standard - non-standard script.
	ErrNonStandardScript

	// ErrBareMultiSig is returned when the transactions are not standard -
	// bare multisig script (2-of-3).
	ErrBareMultiSig

	// ErrScriptSigNotPushOnly is returned when the transactions are not
	// standard - not-pushonly scriptSig.
	ErrScriptSigNotPushOnly

	// ErrScriptSigSize is returned when the transactions are not standard
	// - too large scriptSig (>1650 bytes).
	ErrScriptSigSize

	// ErrTxTooLarge is returned when the transactions are not standard -
	// too large tx size.
	ErrTxTooLarge

	// ErrDust is returned when the transactions are not standard - output
	// too small.
	ErrDust

	// ErrMultiOpReturn is returned when the transactions are not standard
	// - muiltiple OP_RETURNs.
	ErrMultiOpReturn

	// ErrNonFinal is returned when spending a timelocked transaction that
	// hasn't expired yet.
	ErrNonFinal

	// ErrNonBIP68Final is returned when a transaction that is locked by
	// BIP68 sequence logic and not expired yet.
	ErrNonBIP68Final

	// ErrSameNonWitnessData is returned when another tx with the same
	// non-witness data is already in the mempool. For instance, these two
	// txns share the same `txid` but different `wtxid`.
	ErrSameNonWitnessData

	// ErrNonMandatoryScriptVerifyFlag is returned when passing a raw tx to
	// `testmempoolaccept`, which gives the error followed by (Witness
	// program hash mismatch).
	ErrNonMandatoryScriptVerifyFlag
)

This section defines all possible errors or reject reasons returned from bitcoind's `sendrawtransaction` or `testmempoolaccept` RPC.

type RelevantTx

type RelevantTx struct {
	TxRecord *wtxmgr.TxRecord
	Block    *wtxmgr.BlockMeta // nil if unmined
}

RelevantTx is a notification for a transaction which spends wallet inputs or pays to a watched address.

type ReorgFinished added in v0.0.13

type ReorgFinished struct {
	FromHash   *chainhash.Hash
	FromHeight int32
	ToHash     *chainhash.Hash
	ToHeight   int32
}

ReorgFinished is a notification that reorg has finished.

type RescanFinished

type RescanFinished struct {
	Hash   *chainhash.Hash
	Height int32
	Time   time.Time
}

RescanFinished is a notification that a previous rescan request has finished.

type RescanProgress

type RescanProgress struct {
	Hash   chainhash.Hash
	Height int32
	Time   time.Time
}

RescanProgress is a notification describing the current status of an in-progress rescan.

type ZMQConfig

type ZMQConfig struct {
	// ZMQBlockHost is the IP address and port of the bitcoind's rawblock
	// listener.
	ZMQBlockHost string

	// ZMQTxHost is the IP address and port of the bitcoind's rawtx
	// listener.
	ZMQTxHost string

	// ZMQReadDeadline represents the read deadline we'll apply when reading
	// ZMQ messages from either subscription.
	ZMQReadDeadline time.Duration

	// MempoolPollingInterval is the interval that will be used to poll
	// bitcoind to update the local mempool. If a jitter factor is
	// configed, it will be
	// applied to this value to provide randomness in the range,
	// - max: MempoolPollingInterval * (1 + PollingIntervalJitter)
	// - min: MempoolPollingInterval * (1 - PollingIntervalJitter)
	//
	// TODO(yy): replace this temp config with SEQUENCE check.
	MempoolPollingInterval time.Duration

	// PollingIntervalJitter a factor that's used to simulates jitter by
	// scaling MempoolPollingInterval with it. This value must be no less
	// than 0. Default to 0, meaning no jitter will be applied.
	//
	// TODO(yy): replace this temp config with SEQUENCE check.
	PollingIntervalJitter float64

	// RPCBatchSize defines the number of RPC requests to be batches before
	// sending them to the bitcoind node.
	RPCBatchSize uint32

	// RPCBatchInterval defines the time to wait before attempting the next
	// batch when the current one finishes.
	RPCBatchInterval time.Duration
}

ZMQConfig holds all the config values needed to set up a ZMQ connection to bitcoind.

Jump to

Keyboard shortcuts

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