aboutsummaryrefslogtreecommitdiff
path: root/src/script.cpp
diff options
context:
space:
mode:
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;
}