aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-09-10 12:51:56 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-09-10 12:54:03 +0200
commitfd1caa0961d9a5ceef0b8b232f278c9c27605d63 (patch)
treec1c551df9c68b5c75d62629cd2554e661b3df113 /src
parent6a8d15cc16875a2dce3d944b46eb21b3f72bb33b (diff)
parentc1e433b717fbc26a74ca395771076b203630a5a2 (diff)
downloadbitcoin-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')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/test/multisig_tests.cpp13
-rw-r--r--src/test/script_P2SH_tests.cpp9
-rw-r--r--src/wallet.cpp35
-rw-r--r--src/wallet.h2
-rw-r--r--src/wallet_ismine.cpp (renamed from src/scriptutils.cpp)38
-rw-r--r--src/wallet_ismine.h (renamed from src/scriptutils.h)5
7 files changed, 60 insertions, 46 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 9b7e99861d..b2071f49e2 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,6 +173,7 @@ libbitcoin_wallet_a_SOURCES = \
crypter.cpp \
rpcdump.cpp \
rpcwallet.cpp \
+ wallet_ismine.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 6c5afa130c..91dfa39505 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 "wallet_ismine.h"
+#endif
+
#include <boost/assign/std/vector.hpp>
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>
@@ -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<valtype> 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<valtype> 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<valtype> 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<valtype> solutions;
diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp
index b7e7487bb2..f99002017f 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"
-#include "scriptutils.h"
+
+#ifdef ENABLE_WALLET
+#include "wallet_ismine.h"
+#endif
#include <vector>
@@ -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++)
{
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);
diff --git a/src/wallet.h b/src/wallet.h
index 6788986f88..5c26186730 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
index a636eeedab..1c2c117fad 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"
@@ -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<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 ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector<CKeyID> &vKeys) {
- CAffectedKeysVisitor(keystore, vKeys).Process(scriptPubKey);
-}
diff --git a/src/scriptutils.h b/src/wallet_ismine.h
index 98080fc456..9915e9f7bb 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"
@@ -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<CKeyID> &vKeys);
#endif // H_BITCOIN_SCRIPT