1 // Copyright (c) 2014-2017 The btcsuite developers
2 // Copyright (c) 2015-2017 The Decred developers
3 // Use of this source code is governed by an ISC
4 // license that can be found in the LICENSE file.
13 "github.com/btcsuite/btcd/btcjson"
14 "github.com/btcsuite/btcd/chaincfg/chainhash"
15 "github.com/btcsuite/btcd/wire"
18 // FutureGetBestBlockHashResult is a future promise to deliver the result of a
19 // GetBestBlockAsync RPC invocation (or an applicable error).
20 type FutureGetBestBlockHashResult chan *response
22 // Receive waits for the response promised by the future and returns the hash of
23 // the best block in the longest block chain.
24 func (r FutureGetBestBlockHashResult) Receive() (*chainhash.Hash, error) {
25 res, err := receiveFuture(r)
30 // Unmarshal result as a string.
32 err = json.Unmarshal(res, &txHashStr)
36 return chainhash.NewHashFromStr(txHashStr)
39 // GetBestBlockHashAsync returns an instance of a type that can be used to get
40 // the result of the RPC at some future time by invoking the Receive function on
41 // the returned instance.
43 // See GetBestBlockHash for the blocking version and more details.
44 func (c *Client) GetBestBlockHashAsync() FutureGetBestBlockHashResult {
45 cmd := btcjson.NewGetBestBlockHashCmd()
49 // GetBestBlockHash returns the hash of the best block in the longest block
51 func (c *Client) GetBestBlockHash() (*chainhash.Hash, error) {
52 return c.GetBestBlockHashAsync().Receive()
55 // FutureGetBlockResult is a future promise to deliver the result of a
56 // GetBlockAsync RPC invocation (or an applicable error).
57 type FutureGetBlockResult chan *response
59 // Receive waits for the response promised by the future and returns the raw
60 // block requested from the server given its hash.
61 func (r FutureGetBlockResult) Receive() (*wire.MsgBlock, error) {
62 res, err := receiveFuture(r)
67 // Unmarshal result as a string.
69 err = json.Unmarshal(res, &blockHex)
74 // Decode the serialized block hex to raw bytes.
75 serializedBlock, err := hex.DecodeString(blockHex)
80 // Deserialize the block and return it.
81 var msgBlock wire.MsgBlock
82 err = msgBlock.Deserialize(bytes.NewReader(serializedBlock))
89 // GetBlockAsync returns an instance of a type that can be used to get the
90 // result of the RPC at some future time by invoking the Receive function on the
93 // See GetBlock for the blocking version and more details.
94 func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult {
97 hash = blockHash.String()
100 cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(false), nil)
101 return c.sendCmd(cmd)
104 // GetBlock returns a raw block from the server given its hash.
106 // See GetBlockVerbose to retrieve a data structure with information about the
108 func (c *Client) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
109 return c.GetBlockAsync(blockHash).Receive()
112 // FutureGetBlockVerboseResult is a future promise to deliver the result of a
113 // GetBlockVerboseAsync RPC invocation (or an applicable error).
114 type FutureGetBlockVerboseResult chan *response
116 // Receive waits for the response promised by the future and returns the data
117 // structure from the server with information about the requested block.
118 func (r FutureGetBlockVerboseResult) Receive() (*btcjson.GetBlockVerboseResult, error) {
119 res, err := receiveFuture(r)
124 // Unmarshal the raw result into a BlockResult.
125 var blockResult btcjson.GetBlockVerboseResult
126 err = json.Unmarshal(res, &blockResult)
130 return &blockResult, nil
133 // GetBlockVerboseAsync returns an instance of a type that can be used to get
134 // the result of the RPC at some future time by invoking the Receive function on
135 // the returned instance.
137 // See GetBlockVerbose for the blocking version and more details.
138 func (c *Client) GetBlockVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult {
140 if blockHash != nil {
141 hash = blockHash.String()
144 cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), nil)
145 return c.sendCmd(cmd)
148 // GetBlockVerbose returns a data structure from the server with information
149 // about a block given its hash.
151 // See GetBlockVerboseTx to retrieve transaction data structures as well.
152 // See GetBlock to retrieve a raw block instead.
153 func (c *Client) GetBlockVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) {
154 return c.GetBlockVerboseAsync(blockHash).Receive()
157 // GetBlockVerboseTxAsync returns an instance of a type that can be used to get
158 // the result of the RPC at some future time by invoking the Receive function on
159 // the returned instance.
161 // See GetBlockVerboseTx or the blocking version and more details.
162 func (c *Client) GetBlockVerboseTxAsync(blockHash *chainhash.Hash) FutureGetBlockVerboseResult {
164 if blockHash != nil {
165 hash = blockHash.String()
168 cmd := btcjson.NewGetBlockCmd(hash, btcjson.Bool(true), btcjson.Bool(true))
169 return c.sendCmd(cmd)
172 // GetBlockVerboseTx returns a data structure from the server with information
173 // about a block and its transactions given its hash.
175 // See GetBlockVerbose if only transaction hashes are preferred.
176 // See GetBlock to retrieve a raw block instead.
177 func (c *Client) GetBlockVerboseTx(blockHash *chainhash.Hash) (*btcjson.GetBlockVerboseResult, error) {
178 return c.GetBlockVerboseTxAsync(blockHash).Receive()
181 // FutureGetBlockCountResult is a future promise to deliver the result of a
182 // GetBlockCountAsync RPC invocation (or an applicable error).
183 type FutureGetBlockCountResult chan *response
185 // Receive waits for the response promised by the future and returns the number
186 // of blocks in the longest block chain.
187 func (r FutureGetBlockCountResult) Receive() (int64, error) {
188 res, err := receiveFuture(r)
193 // Unmarshal the result as an int64.
195 err = json.Unmarshal(res, &count)
202 // GetBlockCountAsync returns an instance of a type that can be used to get the
203 // result of the RPC at some future time by invoking the Receive function on the
204 // returned instance.
206 // See GetBlockCount for the blocking version and more details.
207 func (c *Client) GetBlockCountAsync() FutureGetBlockCountResult {
208 cmd := btcjson.NewGetBlockCountCmd()
209 return c.sendCmd(cmd)
212 // GetBlockCount returns the number of blocks in the longest block chain.
213 func (c *Client) GetBlockCount() (int64, error) {
214 return c.GetBlockCountAsync().Receive()
217 // FutureGetDifficultyResult is a future promise to deliver the result of a
218 // GetDifficultyAsync RPC invocation (or an applicable error).
219 type FutureGetDifficultyResult chan *response
221 // Receive waits for the response promised by the future and returns the
222 // proof-of-work difficulty as a multiple of the minimum difficulty.
223 func (r FutureGetDifficultyResult) Receive() (float64, error) {
224 res, err := receiveFuture(r)
229 // Unmarshal the result as a float64.
230 var difficulty float64
231 err = json.Unmarshal(res, &difficulty)
235 return difficulty, nil
238 // GetDifficultyAsync returns an instance of a type that can be used to get the
239 // result of the RPC at some future time by invoking the Receive function on the
240 // returned instance.
242 // See GetDifficulty for the blocking version and more details.
243 func (c *Client) GetDifficultyAsync() FutureGetDifficultyResult {
244 cmd := btcjson.NewGetDifficultyCmd()
245 return c.sendCmd(cmd)
248 // GetDifficulty returns the proof-of-work difficulty as a multiple of the
249 // minimum difficulty.
250 func (c *Client) GetDifficulty() (float64, error) {
251 return c.GetDifficultyAsync().Receive()
254 // FutureGetBlockChainInfoResult is a promise to deliver the result of a
255 // GetBlockChainInfoAsync RPC invocation (or an applicable error).
256 type FutureGetBlockChainInfoResult chan *response
258 // Receive waits for the response promised by the future and returns chain info
259 // result provided by the server.
260 func (r FutureGetBlockChainInfoResult) Receive() (*btcjson.GetBlockChainInfoResult, error) {
261 res, err := receiveFuture(r)
266 var chainInfo btcjson.GetBlockChainInfoResult
267 if err := json.Unmarshal(res, &chainInfo); err != nil {
270 return &chainInfo, nil
273 // GetBlockChainInfoAsync returns an instance of a type that can be used to get
274 // the result of the RPC at some future time by invoking the Receive function
275 // on the returned instance.
277 // See GetBlockChainInfo for the blocking version and more details.
278 func (c *Client) GetBlockChainInfoAsync() FutureGetBlockChainInfoResult {
279 cmd := btcjson.NewGetBlockChainInfoCmd()
280 return c.sendCmd(cmd)
283 // GetBlockChainInfo returns information related to the processing state of
284 // various chain-specific details such as the current difficulty from the tip
285 // of the main chain.
286 func (c *Client) GetBlockChainInfo() (*btcjson.GetBlockChainInfoResult, error) {
287 return c.GetBlockChainInfoAsync().Receive()
290 // FutureGetBlockHashResult is a future promise to deliver the result of a
291 // GetBlockHashAsync RPC invocation (or an applicable error).
292 type FutureGetBlockHashResult chan *response
294 // Receive waits for the response promised by the future and returns the hash of
295 // the block in the best block chain at the given height.
296 func (r FutureGetBlockHashResult) Receive() (*chainhash.Hash, error) {
297 res, err := receiveFuture(r)
302 // Unmarshal the result as a string-encoded sha.
304 err = json.Unmarshal(res, &txHashStr)
308 return chainhash.NewHashFromStr(txHashStr)
311 // GetBlockHashAsync returns an instance of a type that can be used to get the
312 // result of the RPC at some future time by invoking the Receive function on the
313 // returned instance.
315 // See GetBlockHash for the blocking version and more details.
316 func (c *Client) GetBlockHashAsync(blockHeight int64) FutureGetBlockHashResult {
317 cmd := btcjson.NewGetBlockHashCmd(blockHeight)
318 return c.sendCmd(cmd)
321 // GetBlockHash returns the hash of the block in the best block chain at the
323 func (c *Client) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
324 return c.GetBlockHashAsync(blockHeight).Receive()
327 // FutureGetBlockHeaderResult is a future promise to deliver the result of a
328 // GetBlockHeaderAsync RPC invocation (or an applicable error).
329 type FutureGetBlockHeaderResult chan *response
331 // Receive waits for the response promised by the future and returns the
332 // blockheader requested from the server given its hash.
333 func (r FutureGetBlockHeaderResult) Receive() (*wire.BlockHeader, error) {
334 res, err := receiveFuture(r)
339 // Unmarshal result as a string.
341 err = json.Unmarshal(res, &bhHex)
346 serializedBH, err := hex.DecodeString(bhHex)
351 // Deserialize the blockheader and return it.
352 var bh wire.BlockHeader
353 err = bh.Deserialize(bytes.NewReader(serializedBH))
361 // GetBlockHeaderAsync returns an instance of a type that can be used to get the
362 // result of the RPC at some future time by invoking the Receive function on the
363 // returned instance.
365 // See GetBlockHeader for the blocking version and more details.
366 func (c *Client) GetBlockHeaderAsync(blockHash *chainhash.Hash) FutureGetBlockHeaderResult {
368 if blockHash != nil {
369 hash = blockHash.String()
372 cmd := btcjson.NewGetBlockHeaderCmd(hash, btcjson.Bool(false))
373 return c.sendCmd(cmd)
376 // GetBlockHeader returns the blockheader from the server given its hash.
378 // See GetBlockHeaderVerbose to retrieve a data structure with information about the
380 func (c *Client) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
381 return c.GetBlockHeaderAsync(blockHash).Receive()
384 // FutureGetBlockHeaderVerboseResult is a future promise to deliver the result of a
385 // GetBlockAsync RPC invocation (or an applicable error).
386 type FutureGetBlockHeaderVerboseResult chan *response
388 // Receive waits for the response promised by the future and returns the
389 // data structure of the blockheader requested from the server given its hash.
390 func (r FutureGetBlockHeaderVerboseResult) Receive() (*btcjson.GetBlockHeaderVerboseResult, error) {
391 res, err := receiveFuture(r)
396 // Unmarshal result as a string.
397 var bh btcjson.GetBlockHeaderVerboseResult
398 err = json.Unmarshal(res, &bh)
406 // GetBlockHeaderVerboseAsync returns an instance of a type that can be used to get the
407 // result of the RPC at some future time by invoking the Receive function on the
408 // returned instance.
410 // See GetBlockHeader for the blocking version and more details.
411 func (c *Client) GetBlockHeaderVerboseAsync(blockHash *chainhash.Hash) FutureGetBlockHeaderVerboseResult {
413 if blockHash != nil {
414 hash = blockHash.String()
417 cmd := btcjson.NewGetBlockHeaderCmd(hash, btcjson.Bool(true))
418 return c.sendCmd(cmd)
421 // GetBlockHeaderVerbose returns a data structure with information about the
422 // blockheader from the server given its hash.
424 // See GetBlockHeader to retrieve a blockheader instead.
425 func (c *Client) GetBlockHeaderVerbose(blockHash *chainhash.Hash) (*btcjson.GetBlockHeaderVerboseResult, error) {
426 return c.GetBlockHeaderVerboseAsync(blockHash).Receive()
429 // FutureGetMempoolEntryResult is a future promise to deliver the result of a
430 // GetMempoolEntryAsync RPC invocation (or an applicable error).
431 type FutureGetMempoolEntryResult chan *response
433 // Receive waits for the response promised by the future and returns a data
434 // structure with information about the transaction in the memory pool given
436 func (r FutureGetMempoolEntryResult) Receive() (*btcjson.GetMempoolEntryResult, error) {
437 res, err := receiveFuture(r)
442 // Unmarshal the result as an array of strings.
443 var mempoolEntryResult btcjson.GetMempoolEntryResult
444 err = json.Unmarshal(res, &mempoolEntryResult)
449 return &mempoolEntryResult, nil
452 // GetMempoolEntryAsync returns an instance of a type that can be used to get the
453 // result of the RPC at some future time by invoking the Receive function on the
454 // returned instance.
456 // See GetMempoolEntry for the blocking version and more details.
457 func (c *Client) GetMempoolEntryAsync(txHash string) FutureGetMempoolEntryResult {
458 cmd := btcjson.NewGetMempoolEntryCmd(txHash)
459 return c.sendCmd(cmd)
462 // GetMempoolEntry returns a data structure with information about the
463 // transaction in the memory pool given its hash.
464 func (c *Client) GetMempoolEntry(txHash string) (*btcjson.GetMempoolEntryResult, error) {
465 return c.GetMempoolEntryAsync(txHash).Receive()
468 // FutureGetRawMempoolResult is a future promise to deliver the result of a
469 // GetRawMempoolAsync RPC invocation (or an applicable error).
470 type FutureGetRawMempoolResult chan *response
472 // Receive waits for the response promised by the future and returns the hashes
473 // of all transactions in the memory pool.
474 func (r FutureGetRawMempoolResult) Receive() ([]*chainhash.Hash, error) {
475 res, err := receiveFuture(r)
480 // Unmarshal the result as an array of strings.
481 var txHashStrs []string
482 err = json.Unmarshal(res, &txHashStrs)
487 // Create a slice of ShaHash arrays from the string slice.
488 txHashes := make([]*chainhash.Hash, 0, len(txHashStrs))
489 for _, hashStr := range txHashStrs {
490 txHash, err := chainhash.NewHashFromStr(hashStr)
494 txHashes = append(txHashes, txHash)
500 // GetRawMempoolAsync returns an instance of a type that can be used to get the
501 // result of the RPC at some future time by invoking the Receive function on the
502 // returned instance.
504 // See GetRawMempool for the blocking version and more details.
505 func (c *Client) GetRawMempoolAsync() FutureGetRawMempoolResult {
506 cmd := btcjson.NewGetRawMempoolCmd(btcjson.Bool(false))
507 return c.sendCmd(cmd)
510 // GetRawMempool returns the hashes of all transactions in the memory pool.
512 // See GetRawMempoolVerbose to retrieve data structures with information about
513 // the transactions instead.
514 func (c *Client) GetRawMempool() ([]*chainhash.Hash, error) {
515 return c.GetRawMempoolAsync().Receive()
518 // FutureGetRawMempoolVerboseResult is a future promise to deliver the result of
519 // a GetRawMempoolVerboseAsync RPC invocation (or an applicable error).
520 type FutureGetRawMempoolVerboseResult chan *response
522 // Receive waits for the response promised by the future and returns a map of
523 // transaction hashes to an associated data structure with information about the
524 // transaction for all transactions in the memory pool.
525 func (r FutureGetRawMempoolVerboseResult) Receive() (map[string]btcjson.GetRawMempoolVerboseResult, error) {
526 res, err := receiveFuture(r)
531 // Unmarshal the result as a map of strings (tx shas) to their detailed
533 var mempoolItems map[string]btcjson.GetRawMempoolVerboseResult
534 err = json.Unmarshal(res, &mempoolItems)
538 return mempoolItems, nil
541 // GetRawMempoolVerboseAsync returns an instance of a type that can be used to
542 // get the result of the RPC at some future time by invoking the Receive
543 // function on the returned instance.
545 // See GetRawMempoolVerbose for the blocking version and more details.
546 func (c *Client) GetRawMempoolVerboseAsync() FutureGetRawMempoolVerboseResult {
547 cmd := btcjson.NewGetRawMempoolCmd(btcjson.Bool(true))
548 return c.sendCmd(cmd)
551 // GetRawMempoolVerbose returns a map of transaction hashes to an associated
552 // data structure with information about the transaction for all transactions in
555 // See GetRawMempool to retrieve only the transaction hashes instead.
556 func (c *Client) GetRawMempoolVerbose() (map[string]btcjson.GetRawMempoolVerboseResult, error) {
557 return c.GetRawMempoolVerboseAsync().Receive()
560 // FutureVerifyChainResult is a future promise to deliver the result of a
561 // VerifyChainAsync, VerifyChainLevelAsyncRPC, or VerifyChainBlocksAsync
562 // invocation (or an applicable error).
563 type FutureVerifyChainResult chan *response
565 // Receive waits for the response promised by the future and returns whether
566 // or not the chain verified based on the check level and number of blocks
567 // to verify specified in the original call.
568 func (r FutureVerifyChainResult) Receive() (bool, error) {
569 res, err := receiveFuture(r)
574 // Unmarshal the result as a boolean.
576 err = json.Unmarshal(res, &verified)
583 // VerifyChainAsync returns an instance of a type that can be used to get the
584 // result of the RPC at some future time by invoking the Receive function on the
585 // returned instance.
587 // See VerifyChain for the blocking version and more details.
588 func (c *Client) VerifyChainAsync() FutureVerifyChainResult {
589 cmd := btcjson.NewVerifyChainCmd(nil, nil)
590 return c.sendCmd(cmd)
593 // VerifyChain requests the server to verify the block chain database using
594 // the default check level and number of blocks to verify.
596 // See VerifyChainLevel and VerifyChainBlocks to override the defaults.
597 func (c *Client) VerifyChain() (bool, error) {
598 return c.VerifyChainAsync().Receive()
601 // VerifyChainLevelAsync returns an instance of a type that can be used to get
602 // the result of the RPC at some future time by invoking the Receive function on
603 // the returned instance.
605 // See VerifyChainLevel for the blocking version and more details.
606 func (c *Client) VerifyChainLevelAsync(checkLevel int32) FutureVerifyChainResult {
607 cmd := btcjson.NewVerifyChainCmd(&checkLevel, nil)
608 return c.sendCmd(cmd)
611 // VerifyChainLevel requests the server to verify the block chain database using
612 // the passed check level and default number of blocks to verify.
614 // The check level controls how thorough the verification is with higher numbers
615 // increasing the amount of checks done as consequently how long the
616 // verification takes.
618 // See VerifyChain to use the default check level and VerifyChainBlocks to
619 // override the number of blocks to verify.
620 func (c *Client) VerifyChainLevel(checkLevel int32) (bool, error) {
621 return c.VerifyChainLevelAsync(checkLevel).Receive()
624 // VerifyChainBlocksAsync returns an instance of a type that can be used to get
625 // the result of the RPC at some future time by invoking the Receive function on
626 // the returned instance.
628 // See VerifyChainBlocks for the blocking version and more details.
629 func (c *Client) VerifyChainBlocksAsync(checkLevel, numBlocks int32) FutureVerifyChainResult {
630 cmd := btcjson.NewVerifyChainCmd(&checkLevel, &numBlocks)
631 return c.sendCmd(cmd)
634 // VerifyChainBlocks requests the server to verify the block chain database
635 // using the passed check level and number of blocks to verify.
637 // The check level controls how thorough the verification is with higher numbers
638 // increasing the amount of checks done as consequently how long the
639 // verification takes.
641 // The number of blocks refers to the number of blocks from the end of the
642 // current longest chain.
644 // See VerifyChain and VerifyChainLevel to use defaults.
645 func (c *Client) VerifyChainBlocks(checkLevel, numBlocks int32) (bool, error) {
646 return c.VerifyChainBlocksAsync(checkLevel, numBlocks).Receive()
649 // FutureGetTxOutResult is a future promise to deliver the result of a
650 // GetTxOutAsync RPC invocation (or an applicable error).
651 type FutureGetTxOutResult chan *response
653 // Receive waits for the response promised by the future and returns a
654 // transaction given its hash.
655 func (r FutureGetTxOutResult) Receive() (*btcjson.GetTxOutResult, error) {
656 res, err := receiveFuture(r)
661 // take care of the special case where the output has been spent already
662 // it should return the string "null"
663 if string(res) == "null" {
667 // Unmarshal result as an gettxout result object.
668 var txOutInfo *btcjson.GetTxOutResult
669 err = json.Unmarshal(res, &txOutInfo)
674 return txOutInfo, nil
677 // GetTxOutAsync returns an instance of a type that can be used to get
678 // the result of the RPC at some future time by invoking the Receive function on
679 // the returned instance.
681 // See GetTxOut for the blocking version and more details.
682 func (c *Client) GetTxOutAsync(txHash *chainhash.Hash, index uint32, mempool bool) FutureGetTxOutResult {
685 hash = txHash.String()
688 cmd := btcjson.NewGetTxOutCmd(hash, index, &mempool)
689 return c.sendCmd(cmd)
692 // GetTxOut returns the transaction output info if it's unspent and
694 func (c *Client) GetTxOut(txHash *chainhash.Hash, index uint32, mempool bool) (*btcjson.GetTxOutResult, error) {
695 return c.GetTxOutAsync(txHash, index, mempool).Receive()
698 // FutureRescanBlocksResult is a future promise to deliver the result of a
699 // RescanBlocksAsync RPC invocation (or an applicable error).
701 // NOTE: This is a btcsuite extension ported from
702 // github.com/decred/dcrrpcclient.
703 type FutureRescanBlocksResult chan *response
705 // Receive waits for the response promised by the future and returns the
706 // discovered rescanblocks data.
708 // NOTE: This is a btcsuite extension ported from
709 // github.com/decred/dcrrpcclient.
710 func (r FutureRescanBlocksResult) Receive() ([]btcjson.RescannedBlock, error) {
711 res, err := receiveFuture(r)
716 var rescanBlocksResult []btcjson.RescannedBlock
717 err = json.Unmarshal(res, &rescanBlocksResult)
722 return rescanBlocksResult, nil
725 // RescanBlocksAsync returns an instance of a type that can be used to get the
726 // result of the RPC at some future time by invoking the Receive function on the
727 // returned instance.
729 // See RescanBlocks for the blocking version and more details.
731 // NOTE: This is a btcsuite extension ported from
732 // github.com/decred/dcrrpcclient.
733 func (c *Client) RescanBlocksAsync(blockHashes []chainhash.Hash) FutureRescanBlocksResult {
734 strBlockHashes := make([]string, len(blockHashes))
735 for i := range blockHashes {
736 strBlockHashes[i] = blockHashes[i].String()
739 cmd := btcjson.NewRescanBlocksCmd(strBlockHashes)
740 return c.sendCmd(cmd)
743 // RescanBlocks rescans the blocks identified by blockHashes, in order, using
744 // the client's loaded transaction filter. The blocks do not need to be on the
745 // main chain, but they do need to be adjacent to each other.
747 // NOTE: This is a btcsuite extension ported from
748 // github.com/decred/dcrrpcclient.
749 func (c *Client) RescanBlocks(blockHashes []chainhash.Hash) ([]btcjson.RescannedBlock, error) {
750 return c.RescanBlocksAsync(blockHashes).Receive()
753 // FutureInvalidateBlockResult is a future promise to deliver the result of a
754 // InvalidateBlockAsync RPC invocation (or an applicable error).
755 type FutureInvalidateBlockResult chan *response
757 // Receive waits for the response promised by the future and returns the raw
758 // block requested from the server given its hash.
759 func (r FutureInvalidateBlockResult) Receive() error {
760 _, err := receiveFuture(r)
765 // InvalidateBlockAsync returns an instance of a type that can be used to get the
766 // result of the RPC at some future time by invoking the Receive function on the
767 // returned instance.
769 // See InvalidateBlock for the blocking version and more details.
770 func (c *Client) InvalidateBlockAsync(blockHash *chainhash.Hash) FutureInvalidateBlockResult {
772 if blockHash != nil {
773 hash = blockHash.String()
776 cmd := btcjson.NewInvalidateBlockCmd(hash)
777 return c.sendCmd(cmd)
780 // InvalidateBlock invalidates a specific block.
781 func (c *Client) InvalidateBlock(blockHash *chainhash.Hash) error {
782 return c.InvalidateBlockAsync(blockHash).Receive()