Last active
November 29, 2018 18:46
-
-
Save jl2012/a06f6921c149f359b0c8a8fce37e6280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int inputtype = nHashType & SIGHASH2_INPUT_MASK; | |
const int outputtype = nHashType & SIGHASH2_OUTPUT_MASK; | |
CHashWriter ss(); | |
ss << static_cast<uint8_t>(nHashType); | |
// tx-level data | |
ss << txTo.nVersion; | |
if (inputtype == SIGHASH2_ALL) { | |
ss << single_sha256_prevouts; | |
ss << single_sha256_amounts; | |
ss << single_sha256_sequence; | |
} | |
// else { do nothing } | |
if (outputtype == SIGHASH2_ALLOUTPUT) { | |
ss << single_sha256_outputs; | |
} | |
else if (outputtype == SIGHASH2_SINGLEOUTPUT) { | |
assert(nIn < txTo.vout.size()); | |
ss << txTo.vout[nIn]; | |
} | |
// else if (outputtype == SIGHASH2_NOOUTPUT) { do nothing } | |
else if (outputtype != SIGHASH2_NOOUTPUT) { | |
assert(!"invalid SIGHASH2"); | |
} | |
ss << txTo.nLockTime; | |
// input-level data | |
if (inputtype == SIGHASH2_ALL) { | |
ss << static_cast<uint16_t>(nIn); | |
} | |
else { | |
if (inputtype == SIGHASH2_SINGLEINPUT) { | |
ss << txTo.vin[nIn].prevout; | |
} | |
ss << amount; | |
ss << txTo.vin[nIn].nSequence; | |
} | |
if (inputtype == SIGHASH2_NOINPUT_MASKEDSCRIPT) { | |
ss << static_cast<uint8_t>(scriptPubKey.IsPayToScriptHash()); | |
} | |
else { | |
ss << scriptPubKey; | |
} | |
// script-level data | |
if (is_direct_spending) { | |
assert(inputtype != SIGHASH2_NOINPUT_MASKEDSCRIPT); | |
} | |
else { | |
if (inputtype == SIGHASH2_NOINPUT_MASKEDSCRIPT) { | |
ss << single_sha256_masked_scriptcode; | |
} | |
else { | |
ss << single_sha256_scriptcode; | |
} | |
ss << static_cast<uint8_t>(codeseparator_position); | |
} | |
return ss.GetSingleSHA256(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment