| 2241 | } |
| 2242 | |
| 2243 | void 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 | |
| 2273 | bool DescriptorScriptPubKeyMan::AddKey(const CKeyID& key_id, const CKey& key) |
| 2274 | { |
no test coverage detected