Browse Source

keystore GetKeys(): return result instead of writing to reference

Issue: #10905

By returning the result, a few useless lines can be removed.

Return-value-optimization means there should be no copy.
0.16
Marko Bencun 8 years ago
parent
commit
5cb3da04b8
  1. 16
      src/keystore.h
  2. 21
      src/wallet/crypter.h
  3. 5
      src/wallet/wallet.cpp

16
src/keystore.h

@ -30,7 +30,7 @@ public:
//! Check whether a key corresponding to a given address is present in the store. //! Check whether a key corresponding to a given address is present in the store.
virtual bool HaveKey(const CKeyID &address) const =0; virtual bool HaveKey(const CKeyID &address) const =0;
virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0; virtual bool GetKey(const CKeyID &address, CKey& keyOut) const =0;
virtual void GetKeys(std::set<CKeyID> &setAddress) const =0; virtual std::set<CKeyID> GetKeys() const =0;
virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const =0; virtual bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const =0;
//! Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki //! Support for BIP 0013 : see https://github.com/bitcoin/bips/blob/master/bip-0013.mediawiki
@ -71,18 +71,14 @@ public:
} }
return result; return result;
} }
void GetKeys(std::set<CKeyID> &setAddress) const override std::set<CKeyID> GetKeys() const override
{
setAddress.clear();
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
KeyMap::const_iterator mi = mapKeys.begin(); std::set<CKeyID> set_address;
while (mi != mapKeys.end()) for (const auto& mi : mapKeys) {
{ set_address.insert(mi.first);
setAddress.insert((*mi).first);
mi++;
}
} }
return set_address;
} }
bool GetKey(const CKeyID &address, CKey &keyOut) const override bool GetKey(const CKeyID &address, CKey &keyOut) const override
{ {

21
src/wallet/crypter.h

@ -162,28 +162,25 @@ public:
{ {
{ {
LOCK(cs_KeyStore); LOCK(cs_KeyStore);
if (!IsCrypted()) if (!IsCrypted()) {
return CBasicKeyStore::HaveKey(address); return CBasicKeyStore::HaveKey(address);
}
return mapCryptedKeys.count(address) > 0; return mapCryptedKeys.count(address) > 0;
} }
return false; return false;
} }
bool GetKey(const CKeyID &address, CKey& keyOut) const override; bool GetKey(const CKeyID &address, CKey& keyOut) const override;
bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override; bool GetPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const override;
void GetKeys(std::set<CKeyID> &setAddress) const override std::set<CKeyID> GetKeys() const override
{ {
if (!IsCrypted()) if (!IsCrypted()) {
{ return CBasicKeyStore::GetKeys();
CBasicKeyStore::GetKeys(setAddress);
return;
} }
setAddress.clear(); std::set<CKeyID> set_address;
CryptedKeyMap::const_iterator mi = mapCryptedKeys.begin(); for (const auto& mi : mapCryptedKeys) {
while (mi != mapCryptedKeys.end()) set_address.insert(mi.first);
{
setAddress.insert((*mi).first);
mi++;
} }
return set_address;
} }
/** /**

5
src/wallet/wallet.cpp

@ -3660,13 +3660,10 @@ void CWallet::GetKeyBirthTimes(std::map<CTxDestination, int64_t> &mapKeyBirth) c
// map in which we'll infer heights of other keys // map in which we'll infer heights of other keys
CBlockIndex *pindexMax = chainActive[std::max(0, chainActive.Height() - 144)]; // the tip can be reorganized; use a 144-block safety margin CBlockIndex *pindexMax = chainActive[std::max(0, chainActive.Height() - 144)]; // the tip can be reorganized; use a 144-block safety margin
std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock; std::map<CKeyID, CBlockIndex*> mapKeyFirstBlock;
std::set<CKeyID> setKeys; for (const CKeyID &keyid : GetKeys()) {
GetKeys(setKeys);
for (const CKeyID &keyid : setKeys) {
if (mapKeyBirth.count(keyid) == 0) if (mapKeyBirth.count(keyid) == 0)
mapKeyFirstBlock[keyid] = pindexMax; mapKeyFirstBlock[keyid] = pindexMax;
} }
setKeys.clear();
// if there are no such keys, we're done // if there are no such keys, we're done
if (mapKeyFirstBlock.empty()) if (mapKeyFirstBlock.empty())

Loading…
Cancel
Save