| 1100 | } |
| 1101 | |
| 1102 | DBErrors WalletBatch::LoadWallet(CWallet* pwallet) |
| 1103 | { |
| 1104 | DBErrors result = DBErrors::LOAD_OK; |
| 1105 | bool any_unordered = false; |
| 1106 | |
| 1107 | LOCK(pwallet->cs_wallet); |
| 1108 | |
| 1109 | // Last client version to open this wallet |
| 1110 | int last_client = CLIENT_VERSION; |
| 1111 | bool has_last_client = m_batch->Read(DBKeys::VERSION, last_client); |
| 1112 | if (has_last_client) pwallet->WalletLogPrintf("Last client version = %d\n", last_client); |
| 1113 | |
| 1114 | try { |
| 1115 | // Load wallet flags, so they are known when processing other records. |
| 1116 | // The FLAGS key is absent during wallet creation. |
| 1117 | if ((result = LoadWalletFlags(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result; |
| 1118 | |
| 1119 | #ifndef ENABLE_EXTERNAL_SIGNER |
| 1120 | if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) { |
| 1121 | pwallet->WalletLogPrintf("Error: External signer wallet being loaded without external signer support compiled\n"); |
| 1122 | return DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED; |
| 1123 | } |
| 1124 | #endif |
| 1125 | |
| 1126 | // Load legacy wallet keys |
| 1127 | result = std::max(LoadLegacyWalletRecords(pwallet, *m_batch, last_client), result); |
| 1128 | |
| 1129 | // Load descriptors |
| 1130 | result = std::max(LoadDescriptorWalletRecords(pwallet, *m_batch, last_client), result); |
| 1131 | // Early return if there are unknown descriptors. Later loading of ACTIVEINTERNALSPK and ACTIVEEXTERNALEXPK |
| 1132 | // may reference the unknown descriptor's ID which can result in a misleading corruption error |
| 1133 | // when in reality the wallet is simply too new. |
| 1134 | if (result == DBErrors::UNKNOWN_DESCRIPTOR) return result; |
| 1135 | |
| 1136 | // Load address book |
| 1137 | result = std::max(LoadAddressBookRecords(pwallet, *m_batch), result); |
| 1138 | |
| 1139 | // Load SPKMs |
| 1140 | result = std::max(LoadActiveSPKMs(pwallet, *m_batch), result); |
| 1141 | |
| 1142 | // Load decryption keys |
| 1143 | result = std::max(LoadDecryptionKeys(pwallet, *m_batch), result); |
| 1144 | |
| 1145 | // Load tx records |
| 1146 | result = std::max(LoadTxRecords(pwallet, *m_batch, any_unordered), result); |
| 1147 | } catch (std::runtime_error& e) { |
| 1148 | // Exceptions that can be ignored or treated as non-critical are handled by the individual loading functions. |
| 1149 | // Any uncaught exceptions will be caught here and treated as critical. |
| 1150 | // Catch std::runtime_error specifically as many functions throw these and they at least have some message that |
| 1151 | // we can log |
| 1152 | pwallet->WalletLogPrintf("%s\n", e.what()); |
| 1153 | result = DBErrors::CORRUPT; |
| 1154 | } catch (...) { |
| 1155 | // All other exceptions are still problematic, but we can't log them |
| 1156 | result = DBErrors::CORRUPT; |
| 1157 | } |
| 1158 | |
| 1159 | // Any wallet corruption at all: skip any rewriting or |
no test coverage detected