MCPcopy Create free account
hub / github.com/ElementsProject/elements / ReserveKeyFromKeyPool

Method ReserveKeyFromKeyPool

src/wallet/scriptpubkeyman.cpp:1413–1457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1411}
1412
1413bool LegacyScriptPubKeyMan::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool, bool fRequestedInternal)
1414{
1415 nIndex = -1;
1416 keypool.vchPubKey = CPubKey();
1417 {
1418 LOCK(cs_KeyStore);
1419
1420 bool fReturningInternal = fRequestedInternal;
1421 fReturningInternal &= (IsHDEnabled() && m_storage.CanSupportFeature(FEATURE_HD_SPLIT)) || m_storage.IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
1422 bool use_split_keypool = set_pre_split_keypool.empty();
1423 std::set<int64_t>& setKeyPool = use_split_keypool ? (fReturningInternal ? setInternalKeyPool : setExternalKeyPool) : set_pre_split_keypool;
1424
1425 // Get the oldest key
1426 if (setKeyPool.empty()) {
1427 return false;
1428 }
1429
1430 WalletBatch batch(m_storage.GetDatabase());
1431
1432 auto it = setKeyPool.begin();
1433 nIndex = *it;
1434 setKeyPool.erase(it);
1435 if (!batch.ReadPool(nIndex, keypool)) {
1436 throw std::runtime_error(std::string(__func__) + ": read failed");
1437 }
1438 CPubKey pk;
1439 if (!GetPubKey(keypool.vchPubKey.GetID(), pk)) {
1440 throw std::runtime_error(std::string(__func__) + ": unknown key in key pool");
1441 }
1442 // If the key was pre-split keypool, we don't care about what type it is
1443 if (use_split_keypool && keypool.fInternal != fReturningInternal) {
1444 throw std::runtime_error(std::string(__func__) + ": keypool entry misclassified");
1445 }
1446 if (!keypool.vchPubKey.IsValid()) {
1447 throw std::runtime_error(std::string(__func__) + ": keypool entry invalid");
1448 }
1449
1450 assert(m_index_to_reserved_key.count(nIndex) == 0);
1451 m_index_to_reserved_key[nIndex] = keypool.vchPubKey.GetID();
1452 m_pool_key_to_index.erase(keypool.vchPubKey.GetID());
1453 WalletLogPrintf("keypool reserve %d\n", nIndex);
1454 }
1455 NotifyCanGetAddressesChanged();
1456 return true;
1457}
1458
1459void LegacyScriptPubKeyMan::LearnRelatedScripts(const CPubKey& key, OutputType type)
1460{

Callers

nothing calls this directly

Calls 11

GetPubKeyFunction · 0.85
IsWalletFlagSetMethod · 0.80
ReadPoolMethod · 0.80
countMethod · 0.80
CPubKeyClass · 0.50
emptyMethod · 0.45
beginMethod · 0.45
eraseMethod · 0.45
GetIDMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected