diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -978,7 +978,7 @@ const CKeyStore &keystore = tempKeystore; #endif - int nHashType = SIGHASH_ALL | SIGHASH_FORKID; + SigHashType sigHashType = SigHashType().withForkId(true); if (request.params.size() > 3 && !request.params[3].isNull()) { static std::map mapSigHashValues = { {"ALL", SIGHASH_ALL}, @@ -1002,17 +1002,13 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid sighash param"); } - nHashType = mapSigHashValues[strHashType]; - if ((nHashType & SIGHASH_FORKID) == 0) { + sigHashType = SigHashType(mapSigHashValues[strHashType]); + if (!sigHashType.hasForkId()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Signature must use SIGHASH_FORKID"); } } - bool fHashSingle = - ((nHashType & ~(SIGHASH_ANYONECANPAY | SIGHASH_FORKID)) == - SIGHASH_SINGLE); - // Script verification errors. UniValue vErrors(UniValue::VARR); @@ -1033,9 +1029,11 @@ SignatureData sigdata; // Only sign SIGHASH_SINGLE if there's a corresponding output: - if (!fHashSingle || (i < mergedTx.vout.size())) { + if ((sigHashType.getBaseSigHashType() != BaseSigHashType::SINGLE) || + (i < mergedTx.vout.size())) { ProduceSignature(MutableTransactionSignatureCreator( - &keystore, &mergedTx, i, amount, nHashType), + &keystore, &mergedTx, i, amount, + sigHashType.getRawSigHashType()), prevPubKey, sigdata); }