wallet: remove unused function scanChain
This commit is contained in:
parent
fa65c1b5f7
commit
26bc5ab104
1 changed files with 0 additions and 76 deletions
|
@ -608,82 +608,6 @@ func locateBirthdayBlock(chainClient chainConn,
|
|||
return birthdayBlock, nil
|
||||
}
|
||||
|
||||
// scanChain is a helper method that scans the chain from the starting height
|
||||
// until the tip of the chain. The onBlock callback can be used to perform
|
||||
// certain operations for every block that we process as we scan the chain.
|
||||
func (w *Wallet) scanChain(startHeight int32,
|
||||
onBlock func(int32, *chainhash.Hash, *wire.BlockHeader) error) error {
|
||||
|
||||
chainClient, err := w.requireChainClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// isCurrent is a helper function that we'll use to determine if the
|
||||
// chain backend is currently synced. When running with a btcd or
|
||||
// bitcoind backend, it will use the height of the latest checkpoint as
|
||||
// its lower bound.
|
||||
var latestCheckptHeight int32
|
||||
if len(w.chainParams.Checkpoints) > 0 {
|
||||
latestCheckptHeight = w.chainParams.
|
||||
Checkpoints[len(w.chainParams.Checkpoints)-1].Height
|
||||
}
|
||||
isCurrent := func(bestHeight int32) bool {
|
||||
// If the best height is zero, we assume the chain backend is
|
||||
// still looking for peers to sync to in the case of a global
|
||||
// network, e.g., testnet and mainnet.
|
||||
if bestHeight == 0 && !w.isDevEnv() {
|
||||
return false
|
||||
}
|
||||
|
||||
switch c := chainClient.(type) {
|
||||
case *chain.NeutrinoClient:
|
||||
return c.CS.IsCurrent()
|
||||
}
|
||||
return bestHeight >= latestCheckptHeight
|
||||
}
|
||||
|
||||
// Determine the latest height known to the chain backend and begin
|
||||
// scanning the chain from the start height up until this point.
|
||||
_, bestHeight, err := chainClient.GetBestBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for height := startHeight; height <= bestHeight; height++ {
|
||||
hash, err := chainClient.GetBlockHash(int64(height))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
header, err := chainClient.GetBlockHeader(hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := onBlock(height, hash, header); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If we've reached our best height, we'll wait for blocks at
|
||||
// tip to ensure we go through all existent blocks in the chain.
|
||||
// We'll update our bestHeight before checking if we're current
|
||||
// with the chain to ensure we process any additional blocks
|
||||
// that came in while we were scanning from our starting point.
|
||||
for height == bestHeight {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, bestHeight, err = chainClient.GetBestBlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isCurrent(bestHeight) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// recovery attempts to recover any unspent outputs that pay to any of our
|
||||
// addresses starting from our birthday, or the wallet's tip (if higher), which
|
||||
// would indicate resuming a recovery after a restart.
|
||||
|
|
Loading…
Reference in a new issue