本文整理匯總了Golang中github.com/decred/dcrwallet/chain.RPCClient.Rescan方法的典型用法代碼示例。如果您正苦於以下問題:Golang RPCClient.Rescan方法的具體用法?Golang RPCClient.Rescan怎麽用?Golang RPCClient.Rescan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/decred/dcrwallet/chain.RPCClient
的用法示例。
在下文中一共展示了RPCClient.Rescan方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: rescan
// rescan synchronously scans over all blocks on the main chain starting at
// startHash and height up through the recorded main chain tip block. The
// progress channel, if non-nil, is sent non-error progress notifications with
// the heights the rescan has completed through, starting with the start height.
func (w *Wallet) rescan(chainClient *chain.RPCClient, startHash *chainhash.Hash, height int32,
p chan<- RescanProgress, cancel <-chan struct{}) error {
blockHashStorage := make([]chainhash.Hash, maxBlocksPerRescan)
rescanFrom := *startHash
inclusive := true
for {
select {
case <-cancel:
return nil
default:
}
var rescanBlocks []chainhash.Hash
err := walletdb.View(w.db, func(dbtx walletdb.ReadTx) error {
txmgrNs := dbtx.ReadBucket(wtxmgrNamespaceKey)
var err error
rescanBlocks, err = w.TxStore.GetMainChainBlockHashes(txmgrNs,
&rescanFrom, inclusive, blockHashStorage)
return err
})
if err != nil {
return err
}
if len(rescanBlocks) == 0 {
return nil
}
scanningThrough := height + int32(len(rescanBlocks)) - 1
log.Infof("Rescanning blocks %v-%v...", height,
scanningThrough)
rescanResults, err := chainClient.Rescan(rescanBlocks)
if err != nil {
return err
}
var rawBlockHeader wtxmgr.RawBlockHeader
err = walletdb.Update(w.db, func(dbtx walletdb.ReadWriteTx) error {
txmgrNs := dbtx.ReadWriteBucket(wtxmgrNamespaceKey)
for _, r := range rescanResults.DiscoveredData {
blockHash, err := chainhash.NewHashFromStr(r.Hash)
if err != nil {
return err
}
blockMeta, err := w.TxStore.GetBlockMetaForHash(txmgrNs, blockHash)
if err != nil {
return err
}
serHeader, err := w.TxStore.GetSerializedBlockHeader(txmgrNs,
blockHash)
if err != nil {
return err
}
err = copyHeaderSliceToArray(&rawBlockHeader, serHeader)
if err != nil {
return err
}
for _, hexTx := range r.Transactions {
serTx, err := hex.DecodeString(hexTx)
if err != nil {
return err
}
err = w.processTransaction(dbtx, serTx, &rawBlockHeader,
&blockMeta)
if err != nil {
return err
}
}
}
return nil
})
if err != nil {
return err
}
if p != nil {
p <- RescanProgress{ScannedThrough: scanningThrough}
}
rescanFrom = rescanBlocks[len(rescanBlocks)-1]
height += int32(len(rescanBlocks))
inclusive = false
}
}