Add support for SIGHASH_DEFAULT in RPCs, and make it default

For non-Taproot signatures, this is interpreted as SIGHASH_ALL.
This commit is contained in:
Pieter Wuille
2021-03-04 14:27:20 -08:00
parent c0f0c8eccb
commit 458a345b05
6 changed files with 18 additions and 10 deletions

View File

@@ -44,10 +44,13 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
// Signing without known amount does not work in witness scripts.
if (sigversion == SigVersion::WITNESS_V0 && !MoneyRange(amount)) return false;
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, m_txdata);
// BASE/WITNESS_V0 signatures don't support explicit SIGHASH_DEFAULT, use SIGHASH_ALL instead.
const int hashtype = nHashType == SIGHASH_DEFAULT ? SIGHASH_ALL : nHashType;
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, hashtype, amount, sigversion, m_txdata);
if (!key.Sign(hash, vchSig))
return false;
vchSig.push_back((unsigned char)nHashType);
vchSig.push_back((unsigned char)hashtype);
return true;
}