diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-10 12:51:56 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-10 12:54:03 +0200 |
commit | fd1caa0961d9a5ceef0b8b232f278c9c27605d63 (patch) | |
tree | c1c551df9c68b5c75d62629cd2554e661b3df113 /src/wallet.cpp | |
parent | 6a8d15cc16875a2dce3d944b46eb21b3f72bb33b (diff) | |
parent | c1e433b717fbc26a74ca395771076b203630a5a2 (diff) | |
download | bitcoin-fd1caa0961d9a5ceef0b8b232f278c9c27605d63.tar.xz |
Merge pull request #4755
c1e433b Rename scriptutils.o to wallet_ismine.o (jtimon)
8b59a3d Move CAffectedKeysVisitor to wallet.cpp (remove ExtractAffectedKeys) (jtimon)
0d2fa14 Move scriptutils.o to wallet (jtimon)
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index 218a137966..52660be9a0 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2086,6 +2086,39 @@ void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts) } } + +class CAffectedKeysVisitor : public boost::static_visitor<void> { +private: + const CKeyStore &keystore; + std::vector<CKeyID> &vKeys; + +public: + CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector<CKeyID> &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {} + + void Process(const CScript &script) { + txnouttype type; + std::vector<CTxDestination> vDest; + int nRequired; + if (ExtractDestinations(script, type, vDest, nRequired)) { + BOOST_FOREACH(const CTxDestination &dest, vDest) + boost::apply_visitor(*this, dest); + } + } + + void operator()(const CKeyID &keyId) { + if (keystore.HaveKey(keyId)) + vKeys.push_back(keyId); + } + + void operator()(const CScriptID &scriptId) { + CScript script; + if (keystore.GetCScript(scriptId, script)) + Process(script); + } + + void operator()(const CNoDestination &none) {} +}; + void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const { AssertLockHeld(cs_wallet); // mapKeyMetadata mapKeyBirth.clear(); @@ -2121,7 +2154,7 @@ void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const { int nHeight = blit->second->nHeight; BOOST_FOREACH(const CTxOut &txout, wtx.vout) { // iterate over all their outputs - ::ExtractAffectedKeys(*this, txout.scriptPubKey, vAffected); + CAffectedKeysVisitor(*this, vAffected).Process(txout.scriptPubKey); BOOST_FOREACH(const CKeyID &keyid, vAffected) { // ... and all their affected keys std::map<CKeyID, CBlockIndex*>::iterator rit = mapKeyFirstBlock.find(keyid); |