From 6a4bd809d3d79209ef43ee55304e744d23409582 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Wed, 16 Jul 2014 03:26:55 +0400 Subject: [PATCH] Replace VerifyScript with CScriptCheck CScriptCheck is a closure representing a script check. --- src/main.cpp | 18 ++++++++---------- src/main.h | 29 +++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 48b9d30..a0d3531 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1458,18 +1458,16 @@ unsigned int CTransaction::GetP2SHSigOpCount(const MapPrevTx& inputs) const return nSigOps; } +bool CScriptCheck::operator()() const { + const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; + if (!VerifyScript(scriptSig, scriptPubKey, *ptxTo, nIn, nFlags, nHashType)) + return error("CScriptCheck() : %s VerifySignature failed", ptxTo->GetHash().ToString().substr(0,10).c_str()); + return true; +} + bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType) { - assert(nIn < txTo.vin.size()); - const CTxIn& txin = txTo.vin[nIn]; - if (txin.prevout.n >= txFrom.vout.size()) - return false; - const CTxOut& txout = txFrom.vout[txin.prevout.n]; - - if (txin.prevout.hash != txFrom.GetHash()) - return false; - - return VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, flags, nHashType); + return CScriptCheck(txFrom, txTo, nIn, flags, nHashType)(); } bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs, map& mapTestPool, const CDiskTxPos& posThisTx, diff --git a/src/main.h b/src/main.h index 081661e..dc8499a 100644 --- a/src/main.h +++ b/src/main.h @@ -132,8 +132,6 @@ bool VerifySignature(const CTransaction& txFrom, const CTransaction& txTo, unsig - - bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut); /** Position on disk for a particular transaction. */ @@ -707,6 +705,33 @@ protected: const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const; }; +/** Closure representing one script verification + * Note that this stores references to the spending transaction */ +class CScriptCheck +{ +private: + CScript scriptPubKey; + const CTransaction *ptxTo; + unsigned int nIn; + unsigned int nFlags; + int nHashType; + +public: + CScriptCheck() {} + CScriptCheck(const CTransaction& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, int nHashTypeIn) : + scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey), + ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), nHashType(nHashTypeIn) { } + + bool operator()() const; + + void swap(CScriptCheck &check) { + scriptPubKey.swap(check.scriptPubKey); + std::swap(ptxTo, check.ptxTo); + std::swap(nIn, check.nIn); + std::swap(nFlags, check.nFlags); + std::swap(nHashType, check.nHashType); + } +}; -- 1.7.1