@@ -1032,7 +1032,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
1032
1032
CSHA256 ()
1033
1033
.Write (vchMessage.data (), vchMessage.size ())
1034
1034
.Finalize (vchHash.data ());
1035
- fSuccess = checker. VerifySignature (vchSig, CPubKey (vchPubKey), uint256 (vchHash));
1035
+ fSuccess = CPubKey (vchPubKey). Verify ( uint256 (vchHash), vchSig );
1036
1036
}
1037
1037
1038
1038
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && vchSig.size ()) {
@@ -1308,17 +1308,19 @@ namespace {
1308
1308
* Wrapper that serializes like CTransaction, but with the modifications
1309
1309
* required for the signature hash done in-place
1310
1310
*/
1311
- class CTransactionSignatureSerializer {
1311
+ template <class T >
1312
+ class CTransactionSignatureSerializer
1313
+ {
1312
1314
private:
1313
- const CTransaction & txTo; // !< reference to the spending transaction (the one being serialized)
1315
+ const T & txTo; // !< reference to the spending transaction (the one being serialized)
1314
1316
const CScript& scriptCode; // !< output script being consumed
1315
1317
const unsigned int nIn; // !< input index of txTo being signed
1316
1318
const bool fAnyoneCanPay ; // !< whether the hashtype has the SIGHASH_ANYONECANPAY flag set
1317
1319
const bool fHashSingle ; // !< whether the hashtype is SIGHASH_SINGLE
1318
1320
const bool fHashNone ; // !< whether the hashtype is SIGHASH_NONE
1319
1321
1320
1322
public:
1321
- CTransactionSignatureSerializer (const CTransaction & txToIn, const CScript & scriptCodeIn, unsigned int nInIn, int nHashTypeIn) :
1323
+ CTransactionSignatureSerializer (const T& txToIn, const CScript& scriptCodeIn, unsigned int nInIn, int nHashTypeIn) :
1322
1324
txTo (txToIn), scriptCode(scriptCodeIn), nIn(nInIn),
1323
1325
fAnyoneCanPay (!!(nHashTypeIn & SIGHASH_ANYONECANPAY)),
1324
1326
fHashSingle ((nHashTypeIn & 0x1f ) == SIGHASH_SINGLE),
@@ -1402,23 +1404,29 @@ class CTransactionSignatureSerializer {
1402
1404
}
1403
1405
};
1404
1406
1405
- uint256 GetPrevoutHash (const CTransaction& txTo) {
1407
+ template <class T >
1408
+ uint256 GetPrevoutHash (const T& txTo)
1409
+ {
1406
1410
CHashWriter ss (SER_GETHASH, 0 );
1407
1411
for (const auto & txin : txTo.vin ) {
1408
1412
ss << txin.prevout ;
1409
1413
}
1410
1414
return ss.GetHash ();
1411
1415
}
1412
1416
1413
- uint256 GetSequenceHash (const CTransaction& txTo) {
1417
+ template <class T >
1418
+ uint256 GetSequenceHash (const T& txTo)
1419
+ {
1414
1420
CHashWriter ss (SER_GETHASH, 0 );
1415
1421
for (const auto & txin : txTo.vin ) {
1416
1422
ss << txin.nSequence ;
1417
1423
}
1418
1424
return ss.GetHash ();
1419
1425
}
1420
1426
1421
- uint256 GetOutputsHash (const CTransaction& txTo) {
1427
+ template <class T >
1428
+ uint256 GetOutputsHash (const T& txTo)
1429
+ {
1422
1430
CHashWriter ss (SER_GETHASH, 0 );
1423
1431
for (const auto & txout : txTo.vout ) {
1424
1432
ss << txout;
@@ -1428,14 +1436,20 @@ uint256 GetOutputsHash(const CTransaction& txTo) {
1428
1436
1429
1437
} // namespace
1430
1438
1431
- PrecomputedTransactionData::PrecomputedTransactionData (const CTransaction& txTo)
1439
+ template <class T >
1440
+ PrecomputedTransactionData::PrecomputedTransactionData (const T& txTo)
1432
1441
{
1433
1442
hashPrevouts = GetPrevoutHash (txTo);
1434
1443
hashSequence = GetSequenceHash (txTo);
1435
1444
hashOutputs = GetOutputsHash (txTo);
1436
1445
}
1437
1446
1438
- uint256 SignatureHash (const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
1447
+ // explicit instantiation
1448
+ template PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo);
1449
+ template PrecomputedTransactionData::PrecomputedTransactionData(const CMutableTransaction& txTo);
1450
+
1451
+ template <class T >
1452
+ uint256 SignatureHash (const CScript& scriptCode, const T& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
1439
1453
{
1440
1454
assert (nIn < txTo.vin .size ());
1441
1455
@@ -1450,20 +1464,22 @@ uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsig
1450
1464
}
1451
1465
1452
1466
// Wrapper to serialize only the necessary parts of the transaction being signed
1453
- CTransactionSignatureSerializer txTmp (txTo, scriptCode, nIn, nHashType);
1467
+ CTransactionSignatureSerializer<T> txTmp (txTo, scriptCode, nIn, nHashType);
1454
1468
1455
1469
// Serialize and hash
1456
1470
CHashWriter ss (SER_GETHASH, 0 );
1457
1471
ss << txTmp << nHashType;
1458
1472
return ss.GetHash ();
1459
1473
}
1460
1474
1461
- bool BaseSignatureChecker::VerifySignature (const std::vector<uint8_t >& vchSig, const CPubKey& pubkey, const uint256& sighash) const
1475
+ template <class T >
1476
+ bool GenericTransactionSignatureChecker<T>::VerifySignature(const std::vector<unsigned char >& vchSig, const CPubKey& pubkey, const uint256& sighash) const
1462
1477
{
1463
1478
return pubkey.Verify (sighash, vchSig);
1464
1479
}
1465
1480
1466
- bool TransactionSignatureChecker::CheckSig (const std::vector<unsigned char >& vchSigIn, const std::vector<unsigned char >& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
1481
+ template <class T >
1482
+ bool GenericTransactionSignatureChecker<T>::CheckSig(const std::vector<unsigned char >& vchSigIn, const std::vector<unsigned char >& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
1467
1483
{
1468
1484
CPubKey pubkey (vchPubKey);
1469
1485
if (!pubkey.IsValid ())
@@ -1484,7 +1500,8 @@ bool TransactionSignatureChecker::CheckSig(const std::vector<unsigned char>& vch
1484
1500
return true ;
1485
1501
}
1486
1502
1487
- bool TransactionSignatureChecker::CheckLockTime (const CScriptNum& nLockTime) const
1503
+ template <class T >
1504
+ bool GenericTransactionSignatureChecker<T>::CheckLockTime(const CScriptNum& nLockTime) const
1488
1505
{
1489
1506
// There are two kinds of nLockTime: lock-by-blockheight
1490
1507
// and lock-by-blocktime, distinguished by whether
@@ -1520,7 +1537,8 @@ bool TransactionSignatureChecker::CheckLockTime(const CScriptNum& nLockTime) con
1520
1537
return true ;
1521
1538
}
1522
1539
1523
- bool TransactionSignatureChecker::CheckSequence (const CScriptNum& nSequence) const
1540
+ template <class T >
1541
+ bool GenericTransactionSignatureChecker<T>::CheckSequence(const CScriptNum& nSequence) const
1524
1542
{
1525
1543
// Relative lock times are supported by comparing the passed
1526
1544
// in operand to the sequence number of the input.
@@ -1566,6 +1584,10 @@ bool TransactionSignatureChecker::CheckSequence(const CScriptNum& nSequence) con
1566
1584
return true ;
1567
1585
}
1568
1586
1587
+ // explicit instantiation
1588
+ template class GenericTransactionSignatureChecker <CTransaction>;
1589
+ template class GenericTransactionSignatureChecker <CMutableTransaction>;
1590
+
1569
1591
bool VerifyScript (const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
1570
1592
{
1571
1593
set_error (serror, SCRIPT_ERR_UNKNOWN_ERROR);
0 commit comments