Changeset View
Changeset View
Standalone View
Standalone View
src/test/sighash_tests.cpp
Show All 23 Lines | |||||
#include <iostream> | #include <iostream> | ||||
// Old script.cpp SignatureHash function | // Old script.cpp SignatureHash function | ||||
static uint256 SignatureHashOld(CScript scriptCode, const CTransaction &txTo, | static uint256 SignatureHashOld(CScript scriptCode, const CTransaction &txTo, | ||||
unsigned int nIn, uint32_t nHashType) { | unsigned int nIn, uint32_t nHashType) { | ||||
static const uint256 one(uint256S( | static const uint256 one(uint256S( | ||||
"0000000000000000000000000000000000000000000000000000000000000001")); | "0000000000000000000000000000000000000000000000000000000000000001")); | ||||
if (nIn >= txTo.vin.size()) { | if (nIn >= txTo.vin.size()) { | ||||
printf("ERROR: SignatureHash(): nIn=%d out of range\n", nIn); | |||||
return one; | return one; | ||||
} | } | ||||
CMutableTransaction txTmp(txTo); | CMutableTransaction txTmp(txTo); | ||||
// In case concatenating two scripts ends up with two codeseparators, or an | // In case concatenating two scripts ends up with two codeseparators, or an | ||||
// extra one at the end, this prevents all those possible incompatibilities. | // extra one at the end, this prevents all those possible incompatibilities. | ||||
scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR)); | scriptCode.FindAndDelete(CScript(OP_CODESEPARATOR)); | ||||
Show All 13 Lines | if ((nHashType & 0x1f) == SIGHASH_NONE) { | ||||
if (i != nIn) { | if (i != nIn) { | ||||
txTmp.vin[i].nSequence = 0; | txTmp.vin[i].nSequence = 0; | ||||
} | } | ||||
} | } | ||||
} else if ((nHashType & 0x1f) == SIGHASH_SINGLE) { | } else if ((nHashType & 0x1f) == SIGHASH_SINGLE) { | ||||
// Only lock-in the txout payee at same index as txin | // Only lock-in the txout payee at same index as txin | ||||
unsigned int nOut = nIn; | unsigned int nOut = nIn; | ||||
if (nOut >= txTmp.vout.size()) { | if (nOut >= txTmp.vout.size()) { | ||||
printf("ERROR: SignatureHash(): nOut=%d out of range\n", nOut); | |||||
return one; | return one; | ||||
} | } | ||||
txTmp.vout.resize(nOut + 1); | txTmp.vout.resize(nOut + 1); | ||||
for (size_t i = 0; i < nOut; i++) { | for (size_t i = 0; i < nOut; i++) { | ||||
txTmp.vout[i].SetNull(); | txTmp.vout[i].SetNull(); | ||||
} | } | ||||
// Let the others update at will | // Let the others update at will | ||||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |