Skip to content

Commit aeed345

Browse files
committed
Merge #10953: [Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheck
3a131b7 Rename out to m_tx_out in CScriptCheck (Johnson Lau) e912118 [Refactor] Combine scriptPubKey and amount as CTxOut in CScriptCheck (Johnson Lau) Pull request description: This simplifies CScriptCheck by combining scriptPubKey and amount Tree-SHA512: 6422363cf5394c6cfefb30c1709db6def63230b809cc7697887e4a2e8c684149208edf91dd139e031b9fe732776b2db59305f77c3cba6f333b11cceb39ef0cc2
2 parents c6223b3 + 3a131b7 commit aeed345

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
@@ -1203,7 +1203,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
12031203
bool CScriptCheck::operator()() {
12041204
const CScript &scriptSig = ptxTo->vin[nIn].scriptSig;
12051205
const CScriptWitness *witness = &ptxTo->vin[nIn].scriptWitness;
1206-
return VerifyScript(scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, amount, cacheStore, *txdata), &error);
1206+
return VerifyScript(scriptSig, m_tx_out.scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker(ptxTo, nIn, m_tx_out.nValue, cacheStore, *txdata), &error);
12071207
}
12081208

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

12911289
// Verify signature
1292-
CScriptCheck check(scriptPubKey, amount, tx, i, flags, cacheSigStore, &txdata);
1290+
CScriptCheck check(coin.out, tx, i, flags, cacheSigStore, &txdata);
12931291
if (pvChecks) {
12941292
pvChecks->push_back(CScriptCheck());
12951293
check.swap(pvChecks->back());
@@ -1301,7 +1299,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
13011299
// arguments; if so, don't trigger DoS protection to
13021300
// avoid splitting the network between upgraded and
13031301
// non-upgraded nodes.
1304-
CScriptCheck check2(scriptPubKey, amount, tx, i,
1302+
CScriptCheck check2(coin.out, tx, i,
13051303
flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheSigStore, &txdata);
13061304
if (check2())
13071305
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
@@ -357,8 +357,7 @@ bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = null
357357
class CScriptCheck
358358
{
359359
private:
360-
CScript scriptPubKey;
361-
CAmount amount;
360+
CTxOut m_tx_out;
362361
const CTransaction *ptxTo;
363362
unsigned int nIn;
364363
unsigned int nFlags;
@@ -367,17 +366,15 @@ class CScriptCheck
367366
PrecomputedTransactionData *txdata;
368367

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

375373
bool operator()();
376374

377375
void swap(CScriptCheck &check) {
378-
scriptPubKey.swap(check.scriptPubKey);
379376
std::swap(ptxTo, check.ptxTo);
380-
std::swap(amount, check.amount);
377+
std::swap(m_tx_out, check.m_tx_out);
381378
std::swap(nIn, check.nIn);
382379
std::swap(nFlags, check.nFlags);
383380
std::swap(cacheStore, check.cacheStore);

0 commit comments

Comments
 (0)