| 612 | } |
| 613 | |
| 614 | DBErrors CWalletDB::LoadWallet(CWallet* pwallet) |
| 615 | { |
| 616 | pwallet->vchDefaultKey = CPubKey(); |
| 617 | CWalletScanState wss; |
| 618 | bool fNoncriticalErrors = false; |
| 619 | DBErrors result = DB_LOAD_OK; |
| 620 | |
| 621 | try { |
| 622 | LOCK(pwallet->cs_wallet); |
| 623 | int nMinVersion = 0; |
| 624 | if (Read((string)"minversion", nMinVersion)) |
| 625 | { |
| 626 | if (nMinVersion > CLIENT_VERSION) |
| 627 | return DB_TOO_NEW; |
| 628 | pwallet->LoadMinVersion(nMinVersion); |
| 629 | } |
| 630 | |
| 631 | // Get cursor |
| 632 | Dbc* pcursor = GetCursor(); |
| 633 | if (!pcursor) |
| 634 | { |
| 635 | LogPrintf("Error getting wallet database cursor\n"); |
| 636 | return DB_CORRUPT; |
| 637 | } |
| 638 | |
| 639 | while (true) |
| 640 | { |
| 641 | // Read next record |
| 642 | CDataStream ssKey(SER_DISK, CLIENT_VERSION); |
| 643 | CDataStream ssValue(SER_DISK, CLIENT_VERSION); |
| 644 | int ret = ReadAtCursor(pcursor, ssKey, ssValue); |
| 645 | if (ret == DB_NOTFOUND) |
| 646 | break; |
| 647 | else if (ret != 0) |
| 648 | { |
| 649 | LogPrintf("Error reading next record from wallet database\n"); |
| 650 | return DB_CORRUPT; |
| 651 | } |
| 652 | |
| 653 | // Try to be tolerant of single corrupt records: |
| 654 | string strType, strErr; |
| 655 | if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) |
| 656 | { |
| 657 | // losing keys is considered a catastrophic error, anything else |
| 658 | // we assume the user can live with: |
| 659 | if (IsKeyType(strType)) |
| 660 | result = DB_CORRUPT; |
| 661 | else |
| 662 | { |
| 663 | // Leave other errors alone, if we try to fix them we might make things worse. |
| 664 | fNoncriticalErrors = true; // ... but do warn the user there is something wrong. |
| 665 | if (strType == "tx") |
| 666 | // Rescan if there is a bad transaction record: |
| 667 | SoftSetBoolArg("-rescan", true); |
| 668 | } |
| 669 | } |
| 670 | if (!strErr.empty()) |
| 671 | LogPrintf("%s\n", strErr); |
nothing calls this directly
no test coverage detected