| 1151 | } |
| 1152 | |
| 1153 | bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey) |
| 1154 | { |
| 1155 | AssertLockHeld(cs_desc_man); |
| 1156 | assert(!m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)); |
| 1157 | |
| 1158 | // Check if provided key already exists |
| 1159 | if (m_map_keys.contains(pubkey.GetID()) || |
| 1160 | m_map_crypted_keys.contains(pubkey.GetID())) { |
| 1161 | return true; |
| 1162 | } |
| 1163 | |
| 1164 | if (m_storage.HasEncryptionKeys()) { |
| 1165 | if (m_storage.IsLocked()) { |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
| 1169 | std::vector<unsigned char> crypted_secret; |
| 1170 | CKeyingMaterial secret{UCharCast(key.begin()), UCharCast(key.end())}; |
| 1171 | if (!m_storage.WithEncryptionKey([&](const CKeyingMaterial& encryption_key) { |
| 1172 | return EncryptSecret(encryption_key, secret, pubkey.GetHash(), crypted_secret); |
| 1173 | })) { |
| 1174 | return false; |
| 1175 | } |
| 1176 | |
| 1177 | m_map_crypted_keys[pubkey.GetID()] = make_pair(pubkey, crypted_secret); |
| 1178 | return batch.WriteCryptedDescriptorKey(GetID(), pubkey, crypted_secret); |
| 1179 | } else { |
| 1180 | m_map_keys[pubkey.GetID()] = key; |
| 1181 | return batch.WriteDescriptorKey(GetID(), pubkey, key.GetPrivKey()); |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | void DescriptorScriptPubKeyMan::SetupDescriptorGeneration(WalletBatch& batch, const CExtKey& master_key, OutputType addr_type, bool internal) |
| 1186 | { |
nothing calls this directly
no test coverage detected