* Scan the block chain (starting in pindexStart) for transactions * from or to us. If fUpdate is true, found transactions that already * exist in the wallet will be updated. */
| 1631 | * exist in the wallet will be updated. |
| 1632 | */ |
| 1633 | int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) |
| 1634 | { |
| 1635 | int ret = 0; |
| 1636 | int64_t nNow = GetTime(); |
| 1637 | |
| 1638 | CBlockIndex* pindex = pindexStart; |
| 1639 | { |
| 1640 | //LOCK2(cs_main, cs_wallet); |
| 1641 | |
| 1642 | // no need to read and scan block, if block was created before |
| 1643 | // our wallet birthday (as adjusted for block time variability) |
| 1644 | while (pindex && nTimeFirstKey && (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) |
| 1645 | pindex = chainActive.Next(pindex); |
| 1646 | |
| 1647 | fAbortRescan = false; |
| 1648 | ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup |
| 1649 | |
| 1650 | int dProgressTip; |
| 1651 | { |
| 1652 | LOCK(cs_main); |
| 1653 | dProgressTip = chainActive.Height(); |
| 1654 | } |
| 1655 | |
| 1656 | int dProgressStart = pindex ? pindex->nHeight : 0; |
| 1657 | int dProgressCurrent = dProgressStart; |
| 1658 | int dProgressTotal = dProgressTip - dProgressStart; |
| 1659 | int dProgressShow = 0; |
| 1660 | int dProgressShowPrev = 0; |
| 1661 | |
| 1662 | while (pindex && !fAbortRescan && !ShutdownRequested()) { |
| 1663 | dProgressShow = std::min(99, (int) (((dProgressCurrent - dProgressStart) * 100) / dProgressTotal)); |
| 1664 | dProgressShow = std::max(1, dProgressShow); |
| 1665 | |
| 1666 | if ((pindex->nHeight % 100 == 0) && (dProgressTotal > 0)) |
| 1667 | { |
| 1668 | if (dProgressShowPrev != dProgressShow) |
| 1669 | { |
| 1670 | dProgressShowPrev = dProgressShow; |
| 1671 | ShowProgress(_("Rescanning..."), dProgressShow); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | if (GetTime() >= nNow + 60) { |
| 1676 | nNow = GetTime(); |
| 1677 | LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, dProgressShow); |
| 1678 | } |
| 1679 | |
| 1680 | CBlock block; |
| 1681 | ReadBlockFromDisk(block, pindex, Params().GetConsensus()); |
| 1682 | { |
| 1683 | LOCK(cs_wallet); |
| 1684 | for (CTransaction& tx : block.vtx) { |
| 1685 | SyncTransaction(tx, &block); |
| 1686 | } |
| 1687 | } |
| 1688 | |
| 1689 | pindex = chainActive.Next(pindex); |
| 1690 |
no test coverage detected