MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / AddKeyPubKeyWithDB

Method AddKeyPubKeyWithDB

src/wallet/wallet.cpp:260–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260bool 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
296bool CWallet::AddKeyPubKey(const CKey& secret, const CPubKey &pubkey)
297{

Callers

nothing calls this directly

Calls 5

GetScriptForDestinationFunction · 0.85
GetScriptForRawPubKeyFunction · 0.85
GetIDMethod · 0.80
WriteKeyMethod · 0.80
GetPrivKeyMethod · 0.80

Tested by

no test coverage detected