add InvalidateBlock RPC command

This commit is contained in:
Ruben de Vries 2017-06-29 16:02:09 +02:00
parent 45b9cb481d
commit c72658166a
2 changed files with 33 additions and 0 deletions

View file

@ -10,3 +10,4 @@ Dave Collins <davec@conformal.com>
Geert-Johan Riemer <geertjohan.riemer@gmail.com> Geert-Johan Riemer <geertjohan.riemer@gmail.com>
Josh Rickmar <jrick@conformal.com> Josh Rickmar <jrick@conformal.com>
Michalis Kargakis <michaliskargakis@gmail.com> Michalis Kargakis <michaliskargakis@gmail.com>
Ruben de Vries <ruben@rubensayshi.com

View file

@ -749,3 +749,35 @@ func (c *Client) RescanBlocksAsync(blockHashes []chainhash.Hash) FutureRescanBlo
func (c *Client) RescanBlocks(blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, error) { func (c *Client) RescanBlocks(blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, error) {
return c.RescanBlocksAsync(blockHashes).Receive() return c.RescanBlocksAsync(blockHashes).Receive()
} }
// FutureInvalidateBlockResult is a future promise to deliver the result of a
// InvalidateBlockAsync RPC invocation (or an applicable error).
type FutureInvalidateBlockResult chan *response
// Receive waits for the response promised by the future and returns the raw
// block requested from the server given its hash.
func (r FutureInvalidateBlockResult) Receive() error {
_, err := receiveFuture(r)
return err
}
// InvalidateBlockAsync 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 InvalidateBlock for the blocking version and more details.
func (c *Client) InvalidateBlockAsync(blockHash *chainhash.Hash) FutureInvalidateBlockResult {
hash := ""
if blockHash != nil {
hash = blockHash.String()
}
cmd := btcjson.NewInvalidateBlockCmd(hash)
return c.sendCmd(cmd)
}
// InvalidateBlock invalidates a specific block.
func (c *Client) InvalidateBlock(blockHash *chainhash.Hash) error {
return c.InvalidateBlockAsync(blockHash).Receive()
}