| 526 | } |
| 527 | |
| 528 | DBErrors WalletBatch::LoadWallet(CWallet* pwallet) |
| 529 | { |
| 530 | CWalletScanState wss; |
| 531 | bool fNoncriticalErrors = false; |
| 532 | DBErrors result = DBErrors::LOAD_OK; |
| 533 | |
| 534 | LOCK(pwallet->cs_wallet); |
| 535 | try { |
| 536 | int nMinVersion = 0; |
| 537 | if (m_batch.Read((std::string)"minversion", nMinVersion)) |
| 538 | { |
| 539 | if (nMinVersion > FEATURE_LATEST) |
| 540 | return DBErrors::TOO_NEW; |
| 541 | pwallet->LoadMinVersion(nMinVersion); |
| 542 | } |
| 543 | |
| 544 | // Get cursor |
| 545 | Dbc* pcursor = m_batch.GetCursor(); |
| 546 | if (!pcursor) |
| 547 | { |
| 548 | pwallet->WalletLogPrintf("Error getting wallet database cursor\n"); |
| 549 | return DBErrors::CORRUPT; |
| 550 | } |
| 551 | |
| 552 | while (true) |
| 553 | { |
| 554 | // Read next record |
| 555 | CDataStream ssKey(SER_DISK, CLIENT_VERSION); |
| 556 | CDataStream ssValue(SER_DISK, CLIENT_VERSION); |
| 557 | int ret = m_batch.ReadAtCursor(pcursor, ssKey, ssValue); |
| 558 | if (ret == DB_NOTFOUND) |
| 559 | break; |
| 560 | else if (ret != 0) |
| 561 | { |
| 562 | pwallet->WalletLogPrintf("Error reading next record from wallet database\n"); |
| 563 | return DBErrors::CORRUPT; |
| 564 | } |
| 565 | |
| 566 | // Try to be tolerant of single corrupt records: |
| 567 | std::string strType, strErr; |
| 568 | if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) |
| 569 | { |
| 570 | // losing keys is considered a catastrophic error, anything else |
| 571 | // we assume the user can live with: |
| 572 | if (IsKeyType(strType) || strType == "defaultkey") { |
| 573 | result = DBErrors::CORRUPT; |
| 574 | } else if(strType == "flags") { |
| 575 | // reading the wallet flags can only fail if unknown flags are present |
| 576 | result = DBErrors::TOO_NEW; |
| 577 | } else { |
| 578 | // Leave other errors alone, if we try to fix them we might make things worse. |
| 579 | fNoncriticalErrors = true; // ... but do warn the user there is something wrong. |
| 580 | if (strType == "tx") |
| 581 | // Rescan if there is a bad transaction record: |
| 582 | gArgs.SoftSetBoolArg("-rescan", true); |
| 583 | } |
| 584 | } |
| 585 | if (!strErr.empty()) |
nothing calls this directly
no test coverage detected