| 762 | } |
| 763 | |
| 764 | DBErrors CWalletDB::LoadWallet(CWallet* pwallet) |
| 765 | { |
| 766 | pwallet->vchDefaultKey = CPubKey(); |
| 767 | CWalletScanState wss; |
| 768 | bool fNoncriticalErrors = false; |
| 769 | DBErrors result = DB_LOAD_OK; |
| 770 | |
| 771 | try { |
| 772 | LOCK(pwallet->cs_wallet); |
| 773 | int nMinVersion = 0; |
| 774 | if (Read((string) "minversion", nMinVersion)) { |
| 775 | if (nMinVersion > CLIENT_VERSION) |
| 776 | return DB_TOO_NEW; |
| 777 | pwallet->LoadMinVersion(nMinVersion); |
| 778 | } |
| 779 | |
| 780 | // Get cursor |
| 781 | Dbc* pcursor = GetCursor(); |
| 782 | if (!pcursor) { |
| 783 | LogPrintf("Error getting wallet database cursor\n"); |
| 784 | return DB_CORRUPT; |
| 785 | } |
| 786 | |
| 787 | while (true) { |
| 788 | // Read next record |
| 789 | CDataStream ssKey(SER_DISK, CLIENT_VERSION); |
| 790 | CDataStream ssValue(SER_DISK, CLIENT_VERSION); |
| 791 | int ret = ReadAtCursor(pcursor, ssKey, ssValue); |
| 792 | if (ret == DB_NOTFOUND) |
| 793 | break; |
| 794 | else if (ret != 0) { |
| 795 | LogPrintf("Error reading next record from wallet database\n"); |
| 796 | return DB_CORRUPT; |
| 797 | } |
| 798 | |
| 799 | // Try to be tolerant of single corrupt records: |
| 800 | string strType, strErr; |
| 801 | if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) { |
| 802 | // losing keys is considered a catastrophic error, anything else |
| 803 | // we assume the user can live with: |
| 804 | if (IsKeyType(strType)) |
| 805 | result = DB_CORRUPT; |
| 806 | else { |
| 807 | // Leave other errors alone, if we try to fix them we might make things worse. |
| 808 | fNoncriticalErrors = true; // ... but do warn the user there is something wrong. |
| 809 | if (strType == "tx") |
| 810 | // Rescan if there is a bad transaction record: |
| 811 | SoftSetBoolArg("-rescan", true); |
| 812 | } |
| 813 | } |
| 814 | if (!strErr.empty()) |
| 815 | LogPrintf("%s\n", strErr); |
| 816 | } |
| 817 | pcursor->close(); |
| 818 | // Store initial external keypool size since we mostly use external keys in mixing |
| 819 | pwallet->nKeysLeftSinceAutoBackup = pwallet->KeypoolCountExternalKeys(); |
| 820 | LogPrintf("nKeysLeftSinceAutoBackup: %d\n", pwallet->nKeysLeftSinceAutoBackup); |
| 821 | } catch (boost::thread_interrupted) { |
nothing calls this directly
no test coverage detected