mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
Add CScriptCheck: a closure representing a script check
This commit is contained in:
parent
f1136200a6
commit
2800ce7367
2 changed files with 34 additions and 8 deletions
15
src/main.cpp
15
src/main.cpp
|
@ -1348,15 +1348,16 @@ bool CTransaction::HaveInputs(CCoinsViewCache &inputs) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType)
|
bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType)
|
||||||
{
|
{
|
||||||
assert(nIn < txTo.vin.size());
|
return CScriptCheck(txFrom, txTo, nIn, flags, nHashType)();
|
||||||
const CTxIn& txin = txTo.vin[nIn];
|
|
||||||
if (txin.prevout.n >= txFrom.vout.size())
|
|
||||||
return false;
|
|
||||||
const CTxOut& txout = txFrom.vout[txin.prevout.n];
|
|
||||||
|
|
||||||
return VerifyScript(txin.scriptSig, txout.scriptPubKey, txTo, nIn, flags, nHashType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CTransaction::CheckInputs(CCoinsViewCache &inputs, enum CheckSig_mode csmode, unsigned int flags) const
|
bool CTransaction::CheckInputs(CCoinsViewCache &inputs, enum CheckSig_mode csmode, unsigned int flags) const
|
||||||
|
|
27
src/main.h
27
src/main.h
|
@ -430,7 +430,6 @@ enum GetMinFee_mode
|
||||||
GMF_SEND,
|
GMF_SEND,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modes for script/signature checking
|
|
||||||
enum CheckSig_mode
|
enum CheckSig_mode
|
||||||
{
|
{
|
||||||
CS_NEVER, // never validate scripts
|
CS_NEVER, // never validate scripts
|
||||||
|
@ -1015,7 +1014,33 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 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 CCoins& 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** A transaction with a merkle branch linking it to the block chain. */
|
/** A transaction with a merkle branch linking it to the block chain. */
|
||||||
class CMerkleTx : public CTransaction
|
class CMerkleTx : public CTransaction
|
||||||
|
|
Loading…
Reference in a new issue