aboutsummaryrefslogtreecommitdiff
path: root/src/script.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-07-26 15:38:31 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-07-26 16:47:23 +0200
commit491ad6db507776054c38230387f384991f42ad29 (patch)
tree7d708a59cb5f61f9d970950c528889dec8fde8d5 /src/script.cpp
parentc0b892fee89cba7d1fda5fda2d2fc7e966643be1 (diff)
parenta9ba47101a46533ff0418d6868ebc9bf5c889818 (diff)
downloadbitcoin-491ad6db507776054c38230387f384991f42ad29.tar.xz
Merge remote branch 'upstream/master'
Conflicts: src/bitcoinrpc.cpp
Diffstat (limited to 'src/script.cpp')
-rw-r--r--src/script.cpp68
1 files changed, 16 insertions, 52 deletions
diff --git a/src/script.cpp b/src/script.cpp
index 654aaa10e3..d1e747251b 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -1041,7 +1041,9 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
// Sign
const valtype& vchPubKey = item.second;
CKey key;
- if (!keystore.GetPrivKey(vchPubKey, key))
+ if (!keystore.GetKey(Hash160(vchPubKey), key))
+ return false;
+ if (key.GetPubKey() != vchPubKey)
return false;
if (hash != 0)
{
@@ -1055,12 +1057,8 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
else if (item.first == OP_PUBKEYHASH)
{
// Sign and give pubkey
- map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
- if (mi == mapPubKeys.end())
- return false;
- const vector<unsigned char>& vchPubKey = (*mi).second;
CKey key;
- if (!keystore.GetPrivKey(vchPubKey, key))
+ if (!keystore.GetKey(uint160(item.second), key))
return false;
if (hash != 0)
{
@@ -1068,7 +1066,7 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
if (!key.Sign(hash, vchSig))
return false;
vchSig.push_back((unsigned char)nHashType);
- scriptSigRet << vchSig << vchPubKey;
+ scriptSigRet << vchSig << key.GetPubKey();
}
}
else
@@ -1102,19 +1100,16 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
{
if (item.first == OP_PUBKEY)
{
- // Sign
const valtype& vchPubKey = item.second;
- if (!keystore.HaveKey(vchPubKey))
+ vector<unsigned char> vchPubKeyFound;
+ if (!keystore.GetPubKey(Hash160(vchPubKey), vchPubKeyFound))
+ return false;
+ if (vchPubKeyFound != vchPubKey)
return false;
}
else if (item.first == OP_PUBKEYHASH)
{
- // Sign and give pubkey
- map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
- if (mi == mapPubKeys.end())
- return false;
- const vector<unsigned char>& vchPubKey = (*mi).second;
- if (!keystore.HaveKey(vchPubKey))
+ if (!keystore.HaveKey(uint160(item.second)))
return false;
}
else
@@ -1128,57 +1123,26 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
}
-bool ExtractPubKey(const CScript& scriptPubKey, const CKeyStore* keystore, vector<unsigned char>& vchPubKeyRet)
+bool ExtractAddress(const CScript& scriptPubKey, const CKeyStore* keystore, CBitcoinAddress& addressRet)
{
- vchPubKeyRet.clear();
-
vector<pair<opcodetype, valtype> > vSolution;
if (!Solver(scriptPubKey, vSolution))
return false;
- CRITICAL_BLOCK(cs_mapPubKeys)
+ CRITICAL_BLOCK(keystore->cs_KeyStore)
{
BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
{
- valtype vchPubKey;
+ uint160 hash160;
if (item.first == OP_PUBKEY)
- {
- vchPubKey = item.second;
- }
+ addressRet.SetPubKey(item.second);
else if (item.first == OP_PUBKEYHASH)
- {
- map<uint160, valtype>::iterator mi = mapPubKeys.find(uint160(item.second));
- if (mi == mapPubKeys.end())
- continue;
- vchPubKey = (*mi).second;
- }
- if (keystore == NULL || keystore->HaveKey(vchPubKey))
- {
- vchPubKeyRet = vchPubKey;
+ addressRet.SetHash160((uint160)item.second);
+ //if (keystore == NULL || keystore->HaveKey(addressRet))
return true;
- }
}
}
- return false;
-}
-
-
-bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret)
-{
- hash160Ret = 0;
- vector<pair<opcodetype, valtype> > vSolution;
- if (!Solver(scriptPubKey, vSolution))
- return false;
-
- BOOST_FOREACH(PAIRTYPE(opcodetype, valtype)& item, vSolution)
- {
- if (item.first == OP_PUBKEYHASH)
- {
- hash160Ret = uint160(item.second);
- return true;
- }
- }
return false;
}