Skip to content

Commit e912118

Browse files
committed
[Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheck
1 parent a90e6d2 commit e912118

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

src/test/script_P2SH_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ BOOST_AUTO_TEST_CASE(sign)
112112
{
113113
CScript sigSave = txTo[i].vin[0].scriptSig;
114114
txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig;
115-
const CTxOut& output = txFrom.vout[txTo[i].vin[0].prevout.n];
116-
bool sigOK = CScriptCheck(output.scriptPubKey, output.nValue, txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &txdata)();
115+
bool sigOK = CScriptCheck(txFrom.vout[txTo[i].vin[0].prevout.n], txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &txdata)();
117116
if (i == j)
118117
BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j));
119118
else

src/test/transaction_tests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
480480

481481
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
482482
std::vector<CScriptCheck> vChecks;
483-
const CTxOut& output = coins[tx.vin[i].prevout.n].out;
484-
CScriptCheck check(output.scriptPubKey, output.nValue, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
483+
CScriptCheck check(coins[tx.vin[i].prevout.n].out, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
485484
vChecks.push_back(CScriptCheck());
486485
check.swap(vChecks.back());
487486
control.Add(vChecks);

src/validation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
12021202
bool CScriptCheck::operator()() {
12031203
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
12041204
const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness;
1205-
return VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, cacheStore, *txdata), &error);
1205+
return VerifyScript(scriptSig, out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, out.nValue, cacheStore, *txdata), &error);
12061206
}
12071207

12081208
int GetSpendHeight(const CCoinsViewCache& inputs)
@@ -1284,11 +1284,9 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
12841284
// a sanity check that our caching is not introducing consensus
12851285
// failures through additional data in, eg, the coins being
12861286
// spent being checked as a part of CScriptCheck.
1287-
const CScript& scriptPubKey = coin.out.scriptPubKey;
1288-
const CAmount amount = coin.out.nValue;
12891287

12901288
// Verify signature
1291-
CScriptCheck check(scriptPubKey, amount, tx, i, flags, cacheSigStore, &txdata);
1289+
CScriptCheck check(coin.out, tx, i, flags, cacheSigStore, &txdata);
12921290
if (pvChecks) {
12931291
pvChecks->push_back(CScriptCheck());
12941292
check.swap(pvChecks->back());
@@ -1300,7 +1298,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
13001298
// arguments; if so, don't trigger DoS protection to
13011299
// avoid splitting the network between upgraded and
13021300
// non-upgraded nodes.
1303-
CScriptCheck check2(scriptPubKey, amount, tx, i,
1301+
CScriptCheck check2(coin.out, tx, i,
13041302
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
13051303
if (check2())
13061304
return state.Invalid(false, REJECT_NONSTANDARD, strprintf("non-mandatory-script-verify-flag (%s)", ScriptErrorString(check.GetScriptError())));

src/validation.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = null
355355
class CScriptCheck
356356
{
357357
private:
358-
CScript scriptPubKey;
359-
CAmount amount;
358+
CTxOut out;
360359
const CTransaction *ptxTo;
361360
unsigned int nIn;
362361
unsigned int nFlags;
@@ -365,17 +364,15 @@ class CScriptCheck
365364
PrecomputedTransactionData *txdata;
366365

367366
public:
368-
CScriptCheck(): amount(0), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
369-
CScriptCheck(const CScript& scriptPubKeyIn, const CAmount amountIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
370-
scriptPubKey(scriptPubKeyIn), amount(amountIn),
371-
ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
367+
CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
368+
CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
369+
out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
372370

373371
bool operator()();
374372

375373
void swap(CScriptCheck &check) {
376-
scriptPubKey.swap(check.scriptPubKey);
377374
std::swap(ptxTo, check.ptxTo);
378-
std::swap(amount, check.amount);
375+
std::swap(out, check.out);
379376
std::swap(nIn, check.nIn);
380377
std::swap(nFlags, check.nFlags);
381378
std::swap(cacheStore, check.cacheStore);

0 commit comments

Comments
 (0)