Merge pull request #69 from ch4ot1c/fix/rawtransaction-forkid

[wallet] Add SIGHASH_FORKID where necessary
This commit is contained in:
Jon Layton 2018-10-12 22:48:50 -05:00 committed by GitHub
commit 82b9ea1cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 16 deletions

View File

@ -633,7 +633,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
const CKeyStore& keystore = tempKeystore;
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
bool fHashSingle = ((nHashType & ~(SIGHASH_ANYONECANPAY|SIGHASH_FORKID)) == SIGHASH_SINGLE);
// Sign what we can:
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {

View File

@ -62,12 +62,12 @@ std::string FormatScript(const CScript& script)
}
const std::map<unsigned char, std::string> mapSigHashTypes = {
{static_cast<unsigned char>(SIGHASH_ALL), std::string("ALL")},
{static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY), std::string("ALL|ANYONECANPAY")},
{static_cast<unsigned char>(SIGHASH_NONE), std::string("NONE")},
{static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY), std::string("NONE|ANYONECANPAY")},
{static_cast<unsigned char>(SIGHASH_SINGLE), std::string("SINGLE")},
{static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")},
{static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_FORKID), std::string("ALL|FORKID")},
{static_cast<unsigned char>(SIGHASH_ALL|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("ALL|ANYONECANPAY|FORKID")},
{static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_FORKID), std::string("NONE|FORKID")},
{static_cast<unsigned char>(SIGHASH_NONE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("NONE|ANYONECANPAY|FORKID")},
{static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_FORKID), std::string("SINGLE|FORKID")},
{static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID), std::string("SINGLE|ANYONECANPAY|FORKID")},
};
/**

View File

@ -838,15 +838,15 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
}
}
int nHashType = SIGHASH_ALL;
int nHashType = SIGHASH_ALL | SIGHASH_FORKID;
if (!hashType.isNull()) {
static std::map<std::string, int> mapSigHashValues = {
{std::string("ALL"), int(SIGHASH_ALL)},
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
{std::string("NONE"), int(SIGHASH_NONE)},
{std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
{std::string("SINGLE"), int(SIGHASH_SINGLE)},
{std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
{std::string("ALL|FORKID"), int(SIGHASH_ALL|SIGHASH_FORKID)},
{std::string("ALL|ANYONECANPAY|FORKID"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)},
{std::string("NONE|FORKID"), int(SIGHASH_NONE|SIGHASH_FORKID)},
{std::string("NONE|ANYONECANPAY|FORKID"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)},
{std::string("SINGLE|FORKID"), int(SIGHASH_SINGLE|SIGHASH_FORKID)},
{std::string("SINGLE|ANYONECANPAY|FORKID"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY|SIGHASH_FORKID)},
};
std::string strHashType = hashType.get_str();
if (mapSigHashValues.count(strHashType)) {
@ -856,7 +856,7 @@ UniValue SignTransaction(CMutableTransaction& mtx, const UniValue& prevTxsUnival
}
}
bool fHashSingle = ((nHashType & ~SIGHASH_ANYONECANPAY) == SIGHASH_SINGLE);
bool fHashSingle = ((nHashType & ~(SIGHASH_ANYONECANPAY|SIGHASH_FORKID)) == SIGHASH_SINGLE);
// Script verification errors
UniValue vErrors(UniValue::VARR);

View File

@ -45,7 +45,7 @@ class MutableTransactionSignatureCreator : public BaseSignatureCreator {
const MutableTransactionSignatureChecker checker;
public:
MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL|SIGHASH_FORKID);
MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL | SIGHASH_FORKID);
const BaseSignatureChecker& Checker() const override { return checker; }
bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
};