diff --git a/chain.go b/chain.go index 8cb54fb43..48fb600ef 100644 --- a/chain.go +++ b/chain.go @@ -1,4 +1,5 @@ -// Copyright (c) 2014-2016 The btcsuite developers +// Copyright (c) 2014-2017 The btcsuite developers +// Copyright (c) 2015-2017 The Decred developers // Use of this source code is governed by an ISC // license that can be found in the LICENSE file. @@ -654,3 +655,58 @@ func (c *Client) GetTxOutAsync(txHash *chainhash.Hash, index uint32, mempool boo func (c *Client) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error) { return c.GetTxOutAsync(txHash, index, mempool).Receive() } + +// FutureRescanBlocksResult is a future promise to deliver the result of a +// RescanBlocksAsync RPC invocation (or an applicable error). +// +// NOTE: This is a btcsuite extension ported from +// github.com/decred/dcrrpcclient. +type FutureRescanBlocksResult chan *response + +// Receive waits for the response promised by the future and returns the +// discovered rescanblocks data. +// +// NOTE: This is a btcsuite extension ported from +// github.com/decred/dcrrpcclient. +func (r FutureRescanBlocksResult) Receive() ([]btcjson.RescannedBlock, error) { + res, err := receiveFuture(r) + if err != nil { + return nil, err + } + + var rescanBlocksResult []btcjson.RescannedBlock + err = json.Unmarshal(res, &rescanBlocksResult) + if err != nil { + return nil, err + } + + return rescanBlocksResult, nil +} + +// RescanBlocksAsync returns an instance of a type that can be used to get the +// result of the RPC at some future time by invoking the Receive function on the +// returned instance. +// +// See RescanBlocks for the blocking version and more details. +// +// NOTE: This is a btcsuite extension ported from +// github.com/decred/dcrrpcclient. +func (c *Client) RescanBlocksAsync(blockHashes []chainhash.Hash) FutureRescanBlocksResult { + strBlockHashes := make([]string, len(blockHashes)) + for i := range blockHashes { + strBlockHashes[i] = blockHashes[i].String() + } + + cmd := btcjson.NewRescanBlocksCmd(strBlockHashes) + return c.sendCmd(cmd) +} + +// RescanBlocks rescans the blocks identified by blockHashes, in order, using +// the client's loaded transaction filter. The blocks do not need to be on the +// main chain, but they do need to be adjacent to each other. +// +// NOTE: This is a btcsuite extension ported from +// github.com/decred/dcrrpcclient. +func (c *Client) RescanBlocks(blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, error) { + return c.RescanBlocksAsync(blockHashes).Receive() +} diff --git a/notify.go b/notify.go index 3391708c5..600ae14cc 100644 --- a/notify.go +++ b/notify.go @@ -156,11 +156,15 @@ type NotificationHandlers struct { // signaled on this notification, rather than relying on the return // result of a rescan request, due to how btcd may send various rescan // notifications after the rescan request has already returned. + // + // NOTE: Deprecated. Not used with RescanBlocks. OnRescanFinished func(hash *chainhash.Hash, height int32, blkTime time.Time) // OnRescanProgress is invoked periodically when a rescan is underway. // It will only be invoked if a preceding call to Rescan or // RescanEndHeight has been made and the function is non-nil. + // + // NOTE: Deprecated. Not used with RescanBlocks. OnRescanProgress func(hash *chainhash.Hash, height int32, blkTime time.Time) // OnTxAccepted is invoked when a transaction is accepted into the @@ -1121,6 +1125,8 @@ func (c *Client) NotifyReceived(addresses []btcutil.Address) error { // FutureRescanResult is a future promise to deliver the result of a RescanAsync // or RescanEndHeightAsync RPC invocation (or an applicable error). +// +// NOTE: Deprecated. Use FutureRescanBlocksResult instead. type FutureRescanResult chan *response // Receive waits for the response promised by the future and returns an error @@ -1143,6 +1149,8 @@ func (r FutureRescanResult) Receive() error { // reconnect. // // NOTE: This is a btcd extension and requires a websocket connection. +// +// NOTE: Deprecated. Use RescanBlocksAsync instead. func (c *Client) RescanAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) FutureRescanResult { @@ -1206,6 +1214,8 @@ func (c *Client) RescanAsync(startBlock *chainhash.Hash, // reconnect. // // NOTE: This is a btcd extension and requires a websocket connection. +// +// NOTE: Deprecated. Use RescanBlocks instead. func (c *Client) Rescan(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint) error { @@ -1220,6 +1230,8 @@ func (c *Client) Rescan(startBlock *chainhash.Hash, // See RescanEndBlock for the blocking version and more details. // // NOTE: This is a btcd extension and requires a websocket connection. +// +// NOTE: Deprecated. Use RescanBlocksAsync instead. func (c *Client) RescanEndBlockAsync(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint, endBlock *chainhash.Hash) FutureRescanResult { @@ -1280,6 +1292,8 @@ func (c *Client) RescanEndBlockAsync(startBlock *chainhash.Hash, // See Rescan to also perform a rescan through current end of the longest chain. // // NOTE: This is a btcd extension and requires a websocket connection. +// +// NOTE: Deprecated. Use RescanBlocks instead. func (c *Client) RescanEndHeight(startBlock *chainhash.Hash, addresses []btcutil.Address, outpoints []*wire.OutPoint, endBlock *chainhash.Hash) error {