| 329 | } |
| 330 | |
| 331 | bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey& pubkey) |
| 332 | { |
| 333 | AssertLockHeld(cs_wallet); // mapKeyMetadata |
| 334 | if (!CCryptoKeyStore::AddKeyPubKey(secret, pubkey)) |
| 335 | return false; |
| 336 | |
| 337 | // check if we need to remove from watch-only |
| 338 | CScript script; |
| 339 | script = GetScriptForDestination(pubkey.GetID()); |
| 340 | if (HaveWatchOnly(script)) |
| 341 | RemoveWatchOnly(script); |
| 342 | |
| 343 | if (!fFileBacked) |
| 344 | return true; |
| 345 | if (!IsCrypted()) { |
| 346 | return CWalletDB(strWalletFile).WriteKey(pubkey, secret.GetPrivKey(), mapKeyMetadata[pubkey.GetID()]); |
| 347 | } |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | bool CWallet::AddCryptedKey(const CPubKey& vchPubKey, |
| 352 | const vector<unsigned char>& vchCryptedSecret) |