Documentation ¶
Index ¶
- func BackEnds() []string
- type BlockConnected
- type BlockDisconnected
- type BlockFilterer
- type ClientConnected
- type FilterBlocksRequest
- type FilterBlocksResponse
- type FilteredBlockConnected
- type Interface
- type NeutrinoClient
- func (s *NeutrinoClient) BackEnd() string
- func (s *NeutrinoClient) BlockStamp() (*waddrmgr.BlockStamp, er.R)
- func (s *NeutrinoClient) FilterBlocks(req *FilterBlocksRequest) (*FilterBlocksResponse, er.R)
- func (s *NeutrinoClient) GetBestBlock() (*chainhash.Hash, int32, er.R)
- func (s *NeutrinoClient) GetBlock(hash *chainhash.Hash) (*wire.MsgBlock, er.R)
- func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, er.R)
- func (s *NeutrinoClient) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, er.R)
- func (s *NeutrinoClient) GetBlockHeight(hash *chainhash.Hash) (int32, er.R)
- func (s *NeutrinoClient) IsCurrent() bool
- func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, er.R)
- func (s *NeutrinoClient) Start() er.R
- func (s *NeutrinoClient) Stop()
- func (s *NeutrinoClient) WaitForShutdown()
- type RPCClient
- func (c *RPCClient) BackEnd() string
- func (c *RPCClient) BlockStamp() (*waddrmgr.BlockStamp, er.R)
- func (c *RPCClient) FilterBlocks(req *FilterBlocksRequest) (*FilterBlocksResponse, er.R)
- func (c *RPCClient) IsCurrent() bool
- func (c *RPCClient) POSTClient() (*rpcclient.Client, er.R)
- func (c *RPCClient) Start() er.R
- func (c *RPCClient) Stop()
- func (c *RPCClient) WaitForShutdown()
- type RelevantTx
- type RescanFinished
- type RescanProgress
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BlockConnected ¶
BlockConnected is a notification for a newly-attached block to the best chain.
type BlockDisconnected ¶
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 ImportedReverseFilter map[string]struct{} // 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 // If true, do not include coinbase transactions IgnoreCoinbase bool }
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 FilterBlocksRequest ¶
type FilterBlocksRequest struct { Blocks []wtxmgr.BlockMeta ExternalAddrs map[waddrmgr.ScopedIndex]btcutil.Address InternalAddrs map[waddrmgr.ScopedIndex]btcutil.Address ImportedAddrs []btcutil.Address WatchedOutPoints map[wire.OutPoint]btcutil.Address IgnoreCoinbase bool }
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 ¶
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() er.R Stop() WaitForShutdown() GetBestBlock() (*chainhash.Hash, int32, er.R) GetBlock(*chainhash.Hash) (*wire.MsgBlock, er.R) GetBlockHash(int64) (*chainhash.Hash, er.R) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, er.R) IsCurrent() bool FilterBlocks(*FilterBlocksRequest) (*FilterBlocksResponse, er.R) BlockStamp() (*waddrmgr.BlockStamp, er.R) SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash, er.R) BackEnd() string }
Interface allows more than one backing blockchain source, such as a pktd RPC chain server, or an SPV library, as long as we write a driver for it.
type NeutrinoClient ¶
type NeutrinoClient struct { CS *neutrino.ChainService // contains filtered or unexported fields }
NeutrinoClient is an implementation of the btcwalet 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, er.R)
BlockStamp returns the latest block notified by the client, or an error if the client has been shut down.
func (*NeutrinoClient) FilterBlocks ¶
func (s *NeutrinoClient) FilterBlocks( req *FilterBlocksRequest) (*FilterBlocksResponse, er.R)
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 postive match, the full block will be fetched and filtered. This method returns a FilterBlocksReponse 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 ¶
GetBestBlock replicates the RPC client's GetBestBlock command.
func (*NeutrinoClient) GetBlockHash ¶
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, er.R)
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 ¶
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) SendRawTransaction ¶
func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) ( *chainhash.Hash, er.R)
SendRawTransaction replicates the RPC client's SendRawTransaction command.
func (*NeutrinoClient) Start ¶
func (s *NeutrinoClient) Start() er.R
Start replicates the RPC client's Start method.
func (*NeutrinoClient) Stop ¶
func (s *NeutrinoClient) Stop()
Stop replicates the RPC client's Stop method.
func (*NeutrinoClient) WaitForShutdown ¶
func (s *NeutrinoClient) WaitForShutdown()
WaitForShutdown replicates the RPC client's WaitForShutdown method.
type RPCClient ¶
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, er.R)
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.
func (*RPCClient) BlockStamp ¶
func (c *RPCClient) BlockStamp() (*waddrmgr.BlockStamp, er.R)
BlockStamp returns the latest block notified by the client, or an error if the client has been shut down.
func (*RPCClient) FilterBlocks ¶
func (c *RPCClient) FilterBlocks( req *FilterBlocksRequest) (*FilterBlocksResponse, er.R)
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 postive match, the full block will be fetched and filtered. This method returns a FilterBlocksReponse 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 ¶
IsCurrent returns whether the chain backend considers its view of the network as "current".
func (*RPCClient) POSTClient ¶
POSTClient creates the equivalent HTTP POST rpcclient.Client.
func (*RPCClient) Start ¶
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 RelevantTx ¶
RelevantTx is a notification for a transaction which spends wallet inputs or pays to a watched address.
type RescanFinished ¶
RescanFinished is a notification that a previous rescan request has finished.