[Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheck
This commit is contained in:
parent
a90e6d2bff
commit
e912118786
4 changed files with 10 additions and 17 deletions
|
@ -112,8 +112,7 @@ BOOST_AUTO_TEST_CASE(sign)
|
||||||
{
|
{
|
||||||
CScript sigSave = txTo[i].vin[0].scriptSig;
|
CScript sigSave = txTo[i].vin[0].scriptSig;
|
||||||
txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig;
|
txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig;
|
||||||
const CTxOut& output = txFrom.vout[txTo[i].vin[0].prevout.n];
|
bool sigOK = CScriptCheck(txFrom.vout[txTo[i].vin[0].prevout.n], txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &txdata)();
|
||||||
bool sigOK = CScriptCheck(output.scriptPubKey, output.nValue, txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &txdata)();
|
|
||||||
if (i == j)
|
if (i == j)
|
||||||
BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j));
|
BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j));
|
||||||
else
|
else
|
||||||
|
|
|
@ -480,8 +480,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
|
||||||
|
|
||||||
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
|
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
|
||||||
std::vector<CScriptCheck> vChecks;
|
std::vector<CScriptCheck> vChecks;
|
||||||
const CTxOut& output = coins[tx.vin[i].prevout.n].out;
|
CScriptCheck check(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
|
||||||
CScriptCheck check(output.scriptPubKey, output.nValue, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
|
|
||||||
vChecks.push_back(CScriptCheck());
|
vChecks.push_back(CScriptCheck());
|
||||||
check.swap(vChecks.back());
|
check.swap(vChecks.back());
|
||||||
control.Add(vChecks);
|
control.Add(vChecks);
|
||||||
|
|
|
@ -1202,7 +1202,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
|
||||||
bool CScriptCheck::operator()() {
|
bool CScriptCheck::operator()() {
|
||||||
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
|
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
|
||||||
const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness;
|
const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness;
|
||||||
return VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, cacheStore, *txdata), &error);
|
return VerifyScript(scriptSig, out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, out.nValue, cacheStore, *txdata), &error);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetSpendHeight(const CCoinsViewCache& inputs)
|
int GetSpendHeight(const CCoinsViewCache& inputs)
|
||||||
|
@ -1284,11 +1284,9 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
|
||||||
// a sanity check that our caching is not introducing consensus
|
// a sanity check that our caching is not introducing consensus
|
||||||
// failures through additional data in, eg, the coins being
|
// failures through additional data in, eg, the coins being
|
||||||
// spent being checked as a part of CScriptCheck.
|
// spent being checked as a part of CScriptCheck.
|
||||||
const CScript& scriptPubKey = coin.out.scriptPubKey;
|
|
||||||
const CAmount amount = coin.out.nValue;
|
|
||||||
|
|
||||||
// Verify signature
|
// Verify signature
|
||||||
CScriptCheck check(scriptPubKey, amount, tx, i, flags, cacheSigStore, &txdata);
|
CScriptCheck check(coin.out, tx, i, flags, cacheSigStore, &txdata);
|
||||||
if (pvChecks) {
|
if (pvChecks) {
|
||||||
pvChecks->push_back(CScriptCheck());
|
pvChecks->push_back(CScriptCheck());
|
||||||
check.swap(pvChecks->back());
|
check.swap(pvChecks->back());
|
||||||
|
@ -1300,7 +1298,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
|
||||||
// arguments; if so, don't trigger DoS protection to
|
// arguments; if so, don't trigger DoS protection to
|
||||||
// avoid splitting the network between upgraded and
|
// avoid splitting the network between upgraded and
|
||||||
// non-upgraded nodes.
|
// non-upgraded nodes.
|
||||||
CScriptCheck check2(scriptPubKey, amount, tx, i,
|
CScriptCheck check2(coin.out, tx, i,
|
||||||
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
|
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
|
||||||
if (check2())
|
if (check2())
|
||||||
return state.Invalid(false, REJECT_NONSTANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
|
return state.Invalid(false, REJECT_NONSTANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));
|
||||||
|
|
|
@ -355,8 +355,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = null
|
||||||
class CScriptCheck
|
class CScriptCheck
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CScript scriptPubKey;
|
CTxOut out;
|
||||||
CAmount amount;
|
|
||||||
const CTransaction *ptxTo;
|
const CTransaction *ptxTo;
|
||||||
unsigned int nIn;
|
unsigned int nIn;
|
||||||
unsigned int nFlags;
|
unsigned int nFlags;
|
||||||
|
@ -365,17 +364,15 @@ private:
|
||||||
PrecomputedTransactionData *txdata;
|
PrecomputedTransactionData *txdata;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CScriptCheck(): amount(0), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
|
CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
|
||||||
CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
|
CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
|
||||||
scriptPubKey(scriptPubKeyIn), amount(amountIn),
|
out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
|
||||||
ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
|
|
||||||
|
|
||||||
bool operator()();
|
bool operator()();
|
||||||
|
|
||||||
void swap(CScriptCheck &check) {
|
void swap(CScriptCheck &check) {
|
||||||
scriptPubKey.swap(check.scriptPubKey);
|
|
||||||
std::swap(ptxTo, check.ptxTo);
|
std::swap(ptxTo, check.ptxTo);
|
||||||
std::swap(amount, check.amount);
|
std::swap(out, check.out);
|
||||||
std::swap(nIn, check.nIn);
|
std::swap(nIn, check.nIn);
|
||||||
std::swap(nFlags, check.nFlags);
|
std::swap(nFlags, check.nFlags);
|
||||||
std::swap(cacheStore, check.cacheStore);
|
std::swap(cacheStore, check.cacheStore);
|
||||||
|
|
Loading…
Reference in a new issue