| 258 | } |
| 259 | |
| 260 | bool CWallet::AddKeyPubKeyWithDB(WalletBatch &batch, const CKey& secret, const CPubKey &pubkey) |
| 261 | { |
| 262 | AssertLockHeld(cs_wallet); // mapKeyMetadata |
| 263 | |
| 264 | // CCryptoKeyStore has no concept of wallet databases, but calls AddCryptedKey |
| 265 | // which is overridden below. To avoid flushes, the database handle is |
| 266 | // tunneled through to it. |
| 267 | bool needsDB = !encrypted_batch; |
| 268 | if (needsDB) { |
| 269 | encrypted_batch = &batch; |
| 270 | } |
| 271 | if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) { |
| 272 | if (needsDB) encrypted_batch = nullptr; |
| 273 | return false; |
| 274 | } |
| 275 | if (needsDB) encrypted_batch = nullptr; |
| 276 | |
| 277 | // check if we need to remove from watch-only |
| 278 | CScript script; |
| 279 | script = GetScriptForDestination(pubkey.GetID()); |
| 280 | if (HaveWatchOnly(script)) { |
| 281 | RemoveWatchOnly(script); |
| 282 | } |
| 283 | script = GetScriptForRawPubKey(pubkey); |
| 284 | if (HaveWatchOnly(script)) { |
| 285 | RemoveWatchOnly(script); |
| 286 | } |
| 287 | |
| 288 | if (!IsCrypted()) { |
| 289 | return batch.WriteKey(pubkey, |
| 290 | secret.GetPrivKey(), |
| 291 | mapKeyMetadata[pubkey.GetID()]); |
| 292 | } |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey) |
| 297 | { |
nothing calls this directly
no test coverage detected