MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetCache

Method SetCache

src/wallet/scriptpubkeyman.cpp:2243–2271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2241}
2242
2243void DescriptorScriptPubKeyMan::SetCache(const DescriptorCache& cache)
2244{
2245 LOCK(cs_desc_man);
2246 m_wallet_descriptor.cache = cache;
2247 for (int32_t i = m_wallet_descriptor.range_start; i < m_wallet_descriptor.range_end; ++i) {
2248 FlatSigningProvider out_keys;
2249 std::vector<CScript> scripts_temp;
2250 if (!m_wallet_descriptor.descriptor->ExpandFromCache(i, m_wallet_descriptor.cache, scripts_temp, out_keys)) {
2251 throw std::runtime_error("Error: Unable to expand wallet descriptor from cache");
2252 }
2253 // Add all of the scriptPubKeys to the scriptPubKey set
2254 for (const CScript& script : scripts_temp) {
2255 if (m_map_script_pub_keys.count(script) != 0) {
2256 throw std::runtime_error(strprintf("Error: Already loaded script at index %d as being at index %d", i, m_map_script_pub_keys[script]));
2257 }
2258 m_map_script_pub_keys[script] = i;
2259 }
2260 for (const auto& pk_pair : out_keys.pubkeys) {
2261 const CPubKey& pubkey = pk_pair.second;
2262 if (m_map_pubkeys.count(pubkey) != 0) {
2263 // We don't need to give an error here.
2264 // It doesn't matter which of many valid indexes the pubkey has, we just need an index where we can derive it and it's private key
2265 continue;
2266 }
2267 m_map_pubkeys[pubkey] = i;
2268 }
2269 m_max_cached_index++;
2270 }
2271}
2272
2273bool DescriptorScriptPubKeyMan::AddKey(const CKeyID& key_id, const CKey& key)
2274{

Callers 1

LoadWalletMethod · 0.80

Calls 2

ExpandFromCacheMethod · 0.80
countMethod · 0.80

Tested by

no test coverage detected