Old script.cpp SignatureHash function
| 25 | |
| 26 | // Old script.cpp SignatureHash function |
| 27 | uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType) |
| 28 | { |
| 29 | if (nIn >= txTo.vin.size()) |
| 30 | { |
| 31 | return uint256::ONE; |
| 32 | } |
| 33 | CMutableTransaction txTmp(txTo); |
| 34 | |
| 35 | // In case concatenating two scripts ends up with two codeseparators, |
| 36 | // or an extra one at the end, this prevents all those possible incompatibilities. |
| 37 | FindAndDelete(scriptCode, CScript(OP_CODESEPARATOR)); |
| 38 | |
| 39 | // Blank out other inputs' signatures |
| 40 | for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
| 41 | txTmp.vin[i].scriptSig = CScript(); |
| 42 | txTmp.vin[nIn].scriptSig = scriptCode; |
| 43 | |
| 44 | // Blank out some of the outputs |
| 45 | if ((nHashType & 0x1f) == SIGHASH_NONE) |
| 46 | { |
| 47 | // Wildcard payee |
| 48 | txTmp.vout.clear(); |
| 49 | |
| 50 | // Let the others update at will |
| 51 | for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
| 52 | if (i != nIn) |
| 53 | txTmp.vin[i].nSequence = 0; |
| 54 | } |
| 55 | else if ((nHashType & 0x1f) == SIGHASH_SINGLE) |
| 56 | { |
| 57 | // Only lock-in the txout payee at same index as txin |
| 58 | unsigned int nOut = nIn; |
| 59 | if (nOut >= txTmp.vout.size()) |
| 60 | { |
| 61 | return uint256::ONE; |
| 62 | } |
| 63 | txTmp.vout.resize(nOut+1); |
| 64 | for (unsigned int i = 0; i < nOut; i++) |
| 65 | txTmp.vout[i].SetNull(); |
| 66 | |
| 67 | // Let the others update at will |
| 68 | for (unsigned int i = 0; i < txTmp.vin.size(); i++) |
| 69 | if (i != nIn) |
| 70 | txTmp.vin[i].nSequence = 0; |
| 71 | } |
| 72 | |
| 73 | // Blank out other inputs completely, not recommended for open transactions |
| 74 | if (nHashType & SIGHASH_ANYONECANPAY) |
| 75 | { |
| 76 | txTmp.vin[0] = txTmp.vin[nIn]; |
| 77 | txTmp.vin.resize(1); |
| 78 | } |
| 79 | |
| 80 | // Serialize and hash |
| 81 | CHashWriter ss(SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS); |
| 82 | ss << txTmp << nHashType; |
| 83 | return ss.GetHash(); |
| 84 | } |
no test coverage detected