MCPcopy Create free account
hub / github.com/LUX-Core/lux / ScanForWalletTransactions

Method ScanForWalletTransactions

src/wallet.cpp:1633–1704  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1631 * exist in the wallet will be updated.
1632 */
1633int 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

Callers 7

AppInit2Function · 0.80
importprivkeyFunction · 0.80
importaddressFunction · 0.80
importpubkeyFunction · 0.80
importwalletFunction · 0.80
bip38decryptFunction · 0.80

Calls 10

GetTimeFunction · 0.85
_Function · 0.85
maxFunction · 0.85
ReadBlockFromDiskFunction · 0.85
HeightMethod · 0.80
ShutdownRequestedFunction · 0.70
ParamsClass · 0.70
ShowProgressFunction · 0.50
GetBlockTimeMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected