Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/walletdb.cpp
Show All 37 Lines | |||||
const std::string OLD_KEY{"wkey"}; | const std::string OLD_KEY{"wkey"}; | ||||
const std::string ORDERPOSNEXT{"orderposnext"}; | const std::string ORDERPOSNEXT{"orderposnext"}; | ||||
const std::string POOL{"pool"}; | const std::string POOL{"pool"}; | ||||
const std::string PURPOSE{"purpose"}; | const std::string PURPOSE{"purpose"}; | ||||
const std::string SETTINGS{"settings"}; | const std::string SETTINGS{"settings"}; | ||||
const std::string TX{"tx"}; | const std::string TX{"tx"}; | ||||
const std::string VERSION{"version"}; | const std::string VERSION{"version"}; | ||||
const std::string WALLETDESCRIPTOR{"walletdescriptor"}; | const std::string WALLETDESCRIPTOR{"walletdescriptor"}; | ||||
const std::string WALLETDESCRIPTORCACHE{"walletdescriptorcache"}; | |||||
const std::string WATCHMETA{"watchmeta"}; | const std::string WATCHMETA{"watchmeta"}; | ||||
const std::string WATCHS{"watchs"}; | const std::string WATCHS{"watchs"}; | ||||
} // namespace DBKeys | } // namespace DBKeys | ||||
// | // | ||||
// WalletBatch | // WalletBatch | ||||
// | // | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | public: | ||||
unsigned int nWatchKeys{0}; | unsigned int nWatchKeys{0}; | ||||
unsigned int nKeyMeta{0}; | unsigned int nKeyMeta{0}; | ||||
unsigned int m_unknown_records{0}; | unsigned int m_unknown_records{0}; | ||||
bool fIsEncrypted{false}; | bool fIsEncrypted{false}; | ||||
bool fAnyUnordered{false}; | bool fAnyUnordered{false}; | ||||
std::vector<TxId> vWalletUpgrade; | std::vector<TxId> vWalletUpgrade; | ||||
std::map<OutputType, uint256> m_active_external_spks; | std::map<OutputType, uint256> m_active_external_spks; | ||||
std::map<OutputType, uint256> m_active_internal_spks; | std::map<OutputType, uint256> m_active_internal_spks; | ||||
std::map<uint256, DescriptorCache> m_descriptor_caches; | |||||
CWalletScanState() {} | CWalletScanState() {} | ||||
}; | }; | ||||
static bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, | static bool ReadKeyValue(CWallet *pwallet, CDataStream &ssKey, | ||||
CDataStream &ssValue, CWalletScanState &wss, | CDataStream &ssValue, CWalletScanState &wss, | ||||
std::string &strType, std::string &strErr) | std::string &strType, std::string &strErr) | ||||
EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { | EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | try { | ||||
return false; | return false; | ||||
} | } | ||||
spk_mans[static_cast<OutputType>(type)] = id; | spk_mans[static_cast<OutputType>(type)] = id; | ||||
} else if (strType == DBKeys::WALLETDESCRIPTOR) { | } else if (strType == DBKeys::WALLETDESCRIPTOR) { | ||||
uint256 id; | uint256 id; | ||||
ssKey >> id; | ssKey >> id; | ||||
WalletDescriptor desc; | WalletDescriptor desc; | ||||
ssValue >> desc; | ssValue >> desc; | ||||
if (wss.m_descriptor_caches.count(id) == 0) { | |||||
wss.m_descriptor_caches[id] = DescriptorCache(); | |||||
} | |||||
pwallet->LoadDescriptorScriptPubKeyMan(id, desc); | pwallet->LoadDescriptorScriptPubKeyMan(id, desc); | ||||
} else if (strType == DBKeys::WALLETDESCRIPTORCACHE) { | |||||
bool parent = true; | |||||
uint256 desc_id; | |||||
uint32_t key_exp_index; | |||||
uint32_t der_index; | |||||
ssKey >> desc_id; | |||||
ssKey >> key_exp_index; | |||||
// if the der_index exists, it's a derived xpub | |||||
try { | |||||
ssKey >> der_index; | |||||
parent = false; | |||||
} catch (...) { | |||||
} | |||||
std::vector<uint8_t> ser_xpub(BIP32_EXTKEY_SIZE); | |||||
ssValue >> ser_xpub; | |||||
CExtPubKey xpub; | |||||
xpub.Decode(ser_xpub.data()); | |||||
if (wss.m_descriptor_caches.count(desc_id)) { | |||||
wss.m_descriptor_caches[desc_id] = DescriptorCache(); | |||||
} | |||||
if (parent) { | |||||
wss.m_descriptor_caches[desc_id].CacheParentExtPubKey( | |||||
key_exp_index, xpub); | |||||
} else { | |||||
wss.m_descriptor_caches[desc_id].CacheDerivedExtPubKey( | |||||
key_exp_index, der_index, xpub); | |||||
} | |||||
} else if (strType != DBKeys::BESTBLOCK && | } else if (strType != DBKeys::BESTBLOCK && | ||||
strType != DBKeys::BESTBLOCK_NOMERKLE && | strType != DBKeys::BESTBLOCK_NOMERKLE && | ||||
strType != DBKeys::MINVERSION && | strType != DBKeys::MINVERSION && | ||||
strType != DBKeys::ACENTRY && strType != DBKeys::VERSION && | strType != DBKeys::ACENTRY && strType != DBKeys::VERSION && | ||||
strType != DBKeys::SETTINGS) { | strType != DBKeys::SETTINGS) { | ||||
wss.m_unknown_records++; | wss.m_unknown_records++; | ||||
} | } | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | for (auto spk_man_pair : wss.m_active_external_spks) { | ||||
/* memonly */ true); | /* memonly */ true); | ||||
} | } | ||||
for (auto spk_man_pair : wss.m_active_internal_spks) { | for (auto spk_man_pair : wss.m_active_internal_spks) { | ||||
pwallet->SetActiveScriptPubKeyMan( | pwallet->SetActiveScriptPubKeyMan( | ||||
spk_man_pair.second, spk_man_pair.first, /* internal */ true, | spk_man_pair.second, spk_man_pair.first, /* internal */ true, | ||||
/* memonly */ true); | /* memonly */ true); | ||||
} | } | ||||
// Set the descriptor caches | |||||
for (auto desc_cache_pair : wss.m_descriptor_caches) { | |||||
auto spk_man = pwallet->GetScriptPubKeyMan(desc_cache_pair.first); | |||||
assert(spk_man); | |||||
((DescriptorScriptPubKeyMan *)spk_man) | |||||
->SetCache(desc_cache_pair.second); | |||||
} | |||||
if (fNoncriticalErrors && result == DBErrors::LOAD_OK) { | if (fNoncriticalErrors && result == DBErrors::LOAD_OK) { | ||||
result = DBErrors::NONCRITICAL_ERROR; | result = DBErrors::NONCRITICAL_ERROR; | ||||
} | } | ||||
// Any wallet corruption at all: skip any rewriting or upgrading, we don't | // Any wallet corruption at all: skip any rewriting or upgrading, we don't | ||||
// want to make it worse. | // want to make it worse. | ||||
if (result != DBErrors::LOAD_OK) { | if (result != DBErrors::LOAD_OK) { | ||||
return result; | return result; | ||||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |