Mercurial > hg > bitcoin
diff src/script.cpp @ 813:62b46930aaa4 draft
get rid of mapPubKeys
Make CKeyStore's interface work on uint160's instead of pubkeys, so
no separate global mapPubKeys is necessary anymore.
author | Pieter Wuille <pieter.wuille@gmail.com> |
---|---|
date | Tue, 05 Jul 2011 16:42:32 +0200 |
parents | 2898aa13cfc0 |
children | 346b6b1b54f3 |
line wrap: on
line diff
--- a/src/script.cpp +++ b/src/script.cpp @@ -1041,7 +1041,9 @@ // 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 @@ 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 @@ 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 @@ { 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 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 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;