diff options
Diffstat (limited to 'src/script.cpp')
-rw-r--r-- | src/script.cpp | 64 |
1 files changed, 17 insertions, 47 deletions
diff --git a/src/script.cpp b/src/script.cpp index 654aaa10e3..b92f7b08b6 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,33 +1123,28 @@ bool IsMine(const CKeyStore &keystore, const CScript& scriptPubKey) } -bool ExtractPubKey(const CScript& scriptPubKey, const CKeyStore* keystore, vector<unsigned char>& vchPubKeyRet) +bool ExtractHash160(const CScript& scriptPubKey, const CKeyStore* keystore, uint160& hash160Ret) { - 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; + hash160 = Hash160(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; + hash160 = uint160(item.second); } - if (keystore == NULL || keystore->HaveKey(vchPubKey)) + if (keystore == NULL || keystore->HaveKey(hash160)) { - vchPubKeyRet = vchPubKey; + hash160Ret = hash160; return true; } } @@ -1163,26 +1153,6 @@ bool ExtractPubKey(const CScript& scriptPubKey, const CKeyStore* keystore, vecto } -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; -} - - bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn, int nHashType) { vector<vector<unsigned char> > stack; |