From 0d2fa14a3434fb259319aedec0124df305e652c0 Mon Sep 17 00:00:00 2001 From: jtimon Date: Fri, 29 Aug 2014 22:07:39 +0200 Subject: [PATCH 1/3] Move scriptutils.o to wallet --- src/Makefile.am | 2 +- src/test/multisig_tests.cpp | 13 ++++++++++++- src/test/script_P2SH_tests.cpp | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 9b7e99861..27bcdc7bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -173,6 +173,7 @@ libbitcoin_wallet_a_SOURCES = \ crypter.cpp \ rpcdump.cpp \ rpcwallet.cpp \ + scriptutils.cpp \ wallet.cpp \ walletdb.cpp \ $(BITCOIN_CORE_H) @@ -216,7 +217,6 @@ libbitcoin_common_a_SOURCES = \ script/script.cpp \ script/sign.cpp \ script/standard.cpp \ - scriptutils.cpp \ $(BITCOIN_CORE_H) # util: shared between all executables. diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index 6c5afa130..427477edc 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -8,9 +8,12 @@ #include "script/script.h" #include "script/interpreter.h" #include "script/sign.h" -#include "scriptutils.h" #include "uint256.h" +#ifdef ENABLE_WALLET +#include "scriptutils.h" +#endif + #include #include #include @@ -195,8 +198,10 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) CTxDestination addr; BOOST_CHECK(ExtractDestination(s, addr)); BOOST_CHECK(addr == keyaddr[0]); +#ifdef ENABLE_WALLET BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); +#endif } { vector solutions; @@ -208,8 +213,10 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) CTxDestination addr; BOOST_CHECK(ExtractDestination(s, addr)); BOOST_CHECK(addr == keyaddr[0]); +#ifdef ENABLE_WALLET BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); +#endif } { vector solutions; @@ -220,9 +227,11 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK_EQUAL(solutions.size(), 4U); CTxDestination addr; BOOST_CHECK(!ExtractDestination(s, addr)); +#ifdef ENABLE_WALLET BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); BOOST_CHECK(!IsMine(partialkeystore, s)); +#endif } { vector solutions; @@ -237,9 +246,11 @@ BOOST_AUTO_TEST_CASE(multisig_Solver1) BOOST_CHECK(addrs[0] == keyaddr[0]); BOOST_CHECK(addrs[1] == keyaddr[1]); BOOST_CHECK(nRequired == 1); +#ifdef ENABLE_WALLET BOOST_CHECK(IsMine(keystore, s)); BOOST_CHECK(!IsMine(emptykeystore, s)); BOOST_CHECK(!IsMine(partialkeystore, s)); +#endif } { vector solutions; diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp index b7e7487bb..b1c1052de 100644 --- a/src/test/script_P2SH_tests.cpp +++ b/src/test/script_P2SH_tests.cpp @@ -7,7 +7,10 @@ #include "main.h" #include "script/script.h" #include "script/sign.h" + +#ifdef ENABLE_WALLET #include "scriptutils.h" +#endif #include @@ -95,7 +98,9 @@ BOOST_AUTO_TEST_CASE(sign) txTo[i].vin[0].prevout.n = i; txTo[i].vin[0].prevout.hash = txFrom.GetHash(); txTo[i].vout[0].nValue = 1; +#ifdef ENABLE_WALLET BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), strprintf("IsMine %d", i)); +#endif } for (int i = 0; i < 8; i++) { @@ -189,7 +194,9 @@ BOOST_AUTO_TEST_CASE(set) txTo[i].vin[0].prevout.hash = txFrom.GetHash(); txTo[i].vout[0].nValue = 1*CENT; txTo[i].vout[0].scriptPubKey = inner[i]; +#ifdef ENABLE_WALLET BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), strprintf("IsMine %d", i)); +#endif } for (int i = 0; i < 4; i++) { From 8b59a3d36626085db79db2874ae76272b2b42f25 Mon Sep 17 00:00:00 2001 From: jtimon Date: Wed, 27 Aug 2014 17:46:30 +0200 Subject: [PATCH 2/3] Move CAffectedKeysVisitor to wallet.cpp (remove ExtractAffectedKeys) --- src/scriptutils.cpp | 36 ------------------------------------ src/scriptutils.h | 1 - src/wallet.cpp | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/scriptutils.cpp b/src/scriptutils.cpp index a636eeeda..5099d7515 100644 --- a/src/scriptutils.cpp +++ b/src/scriptutils.cpp @@ -89,39 +89,3 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) return ISMINE_WATCH_ONLY; return ISMINE_NO; } - -class CAffectedKeysVisitor : public boost::static_visitor { -private: - const CKeyStore &keystore; - std::vector &vKeys; - -public: - CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {} - - void Process(const CScript &script) { - txnouttype type; - std::vector 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 ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector &vKeys) { - CAffectedKeysVisitor(keystore, vKeys).Process(scriptPubKey); -} diff --git a/src/scriptutils.h b/src/scriptutils.h index 98080fc45..4e98a1f74 100644 --- a/src/scriptutils.h +++ b/src/scriptutils.h @@ -24,6 +24,5 @@ typedef uint8_t isminefilter; isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey); isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest); -void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector &vKeys); #endif // H_BITCOIN_SCRIPT diff --git a/src/wallet.cpp b/src/wallet.cpp index 218a13796..52660be9a 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2086,6 +2086,39 @@ void CWallet::ListLockedCoins(std::vector& vOutpts) } } + +class CAffectedKeysVisitor : public boost::static_visitor { +private: + const CKeyStore &keystore; + std::vector &vKeys; + +public: + CAffectedKeysVisitor(const CKeyStore &keystoreIn, std::vector &vKeysIn) : keystore(keystoreIn), vKeys(vKeysIn) {} + + void Process(const CScript &script) { + txnouttype type; + std::vector 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 &mapKeyBirth) const { AssertLockHeld(cs_wallet); // mapKeyMetadata mapKeyBirth.clear(); @@ -2121,7 +2154,7 @@ void CWallet::GetKeyBirthTimes(std::map &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::iterator rit = mapKeyFirstBlock.find(keyid); From c1e433b717fbc26a74ca395771076b203630a5a2 Mon Sep 17 00:00:00 2001 From: jtimon Date: Sat, 30 Aug 2014 13:40:37 +0200 Subject: [PATCH 3/3] Rename scriptutils.o to wallet_ismine.o --- src/Makefile.am | 4 ++-- src/test/multisig_tests.cpp | 2 +- src/test/script_P2SH_tests.cpp | 2 +- src/wallet.h | 2 +- src/{scriptutils.cpp => wallet_ismine.cpp} | 2 +- src/{scriptutils.h => wallet_ismine.h} | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) rename src/{scriptutils.cpp => wallet_ismine.cpp} (98%) rename src/{scriptutils.h => wallet_ismine.h} (91%) diff --git a/src/Makefile.am b/src/Makefile.am index 27bcdc7bc..b2071f49e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -103,7 +103,7 @@ BITCOIN_CORE_H = \ script/script.h \ script/sign.h \ script/standard.h \ - scriptutils.h \ + wallet_ismine.h \ serialize.h \ sync.h \ threadsafety.h \ @@ -173,7 +173,7 @@ libbitcoin_wallet_a_SOURCES = \ crypter.cpp \ rpcdump.cpp \ rpcwallet.cpp \ - scriptutils.cpp \ + wallet_ismine.cpp \ wallet.cpp \ walletdb.cpp \ $(BITCOIN_CORE_H) diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index 427477edc..91dfa3950 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -11,7 +11,7 @@ #include "uint256.h" #ifdef ENABLE_WALLET -#include "scriptutils.h" +#include "wallet_ismine.h" #endif #include diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp index b1c1052de..f99002017 100644 --- a/src/test/script_P2SH_tests.cpp +++ b/src/test/script_P2SH_tests.cpp @@ -9,7 +9,7 @@ #include "script/sign.h" #ifdef ENABLE_WALLET -#include "scriptutils.h" +#include "wallet_ismine.h" #endif #include diff --git a/src/wallet.h b/src/wallet.h index 6788986f8..5c2618673 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -11,7 +11,7 @@ #include "key.h" #include "keystore.h" #include "main.h" -#include "scriptutils.h" +#include "wallet_ismine.h" #include "ui_interface.h" #include "walletdb.h" diff --git a/src/scriptutils.cpp b/src/wallet_ismine.cpp similarity index 98% rename from src/scriptutils.cpp rename to src/wallet_ismine.cpp index 5099d7515..1c2c117fa 100644 --- a/src/scriptutils.cpp +++ b/src/wallet_ismine.cpp @@ -3,7 +3,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "scriptutils.h" +#include "wallet_ismine.h" #include "key.h" #include "keystore.h" diff --git a/src/scriptutils.h b/src/wallet_ismine.h similarity index 91% rename from src/scriptutils.h rename to src/wallet_ismine.h index 4e98a1f74..9915e9f7b 100644 --- a/src/scriptutils.h +++ b/src/wallet_ismine.h @@ -3,8 +3,8 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef H_BITCOIN_SCRIPTUTILS -#define H_BITCOIN_SCRIPTUTILS +#ifndef H_BITCOIN_WALLET_ISMINE +#define H_BITCOIN_WALLET_ISMINE #include "key.h" #include "script/script.h"