mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
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:
parent
c0f0c8eccb
commit
458a345b05
6 changed files with 18 additions and 10 deletions
|
@ -506,11 +506,12 @@ static void MutateTxDelOutput(CMutableTransaction& tx, const std::string& strOut
|
||||||
tx.vout.erase(tx.vout.begin() + outIdx);
|
tx.vout.erase(tx.vout.begin() + outIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const unsigned int N_SIGHASH_OPTS = 6;
|
static const unsigned int N_SIGHASH_OPTS = 7;
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *flagStr;
|
const char *flagStr;
|
||||||
int flags;
|
int flags;
|
||||||
} sighashOptions[N_SIGHASH_OPTS] = {
|
} sighashOptions[N_SIGHASH_OPTS] = {
|
||||||
|
{"DEFAULT", SIGHASH_DEFAULT},
|
||||||
{"ALL", SIGHASH_ALL},
|
{"ALL", SIGHASH_ALL},
|
||||||
{"NONE", SIGHASH_NONE},
|
{"NONE", SIGHASH_NONE},
|
||||||
{"SINGLE", SIGHASH_SINGLE},
|
{"SINGLE", SIGHASH_SINGLE},
|
||||||
|
|
|
@ -260,6 +260,7 @@ int ParseSighashString(const UniValue& sighash)
|
||||||
int hash_type = SIGHASH_ALL;
|
int hash_type = SIGHASH_ALL;
|
||||||
if (!sighash.isNull()) {
|
if (!sighash.isNull()) {
|
||||||
static std::map<std::string, int> map_sighash_values = {
|
static std::map<std::string, int> map_sighash_values = {
|
||||||
|
{std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
|
||||||
{std::string("ALL"), int(SIGHASH_ALL)},
|
{std::string("ALL"), int(SIGHASH_ALL)},
|
||||||
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
|
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
|
||||||
{std::string("NONE"), int(SIGHASH_NONE)},
|
{std::string("NONE"), int(SIGHASH_NONE)},
|
||||||
|
|
|
@ -753,7 +753,8 @@ static RPCHelpMan signrawtransactionwithkey()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"ALL"}, "The signature hash type. Must be one of:\n"
|
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"DEFAULT"}, "The signature hash type. Must be one of:\n"
|
||||||
|
" \"DEFAULT\"\n"
|
||||||
" \"ALL\"\n"
|
" \"ALL\"\n"
|
||||||
" \"NONE\"\n"
|
" \"NONE\"\n"
|
||||||
" \"SINGLE\"\n"
|
" \"SINGLE\"\n"
|
||||||
|
|
|
@ -44,10 +44,13 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
|
||||||
// Signing without known amount does not work in witness scripts.
|
// Signing without known amount does not work in witness scripts.
|
||||||
if (sigversion == SigVersion::WITNESS_V0 && !MoneyRange(amount)) return false;
|
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))
|
if (!key.Sign(hash, vchSig))
|
||||||
return false;
|
return false;
|
||||||
vchSig.push_back((unsigned char)nHashType);
|
vchSig.push_back((unsigned char)hashtype);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3320,7 +3320,8 @@ RPCHelpMan signrawtransactionwithwallet()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"ALL"}, "The signature hash type. Must be one of\n"
|
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"DEFAULT"}, "The signature hash type. Must be one of\n"
|
||||||
|
" \"DEFAULT\"\n"
|
||||||
" \"ALL\"\n"
|
" \"ALL\"\n"
|
||||||
" \"NONE\"\n"
|
" \"NONE\"\n"
|
||||||
" \"SINGLE\"\n"
|
" \"SINGLE\"\n"
|
||||||
|
@ -3542,7 +3543,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
|
||||||
} else {
|
} else {
|
||||||
PartiallySignedTransaction psbtx(mtx);
|
PartiallySignedTransaction psbtx(mtx);
|
||||||
bool complete = false;
|
bool complete = false;
|
||||||
const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_ALL, false /* sign */, true /* bip32derivs */);
|
const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, false /* sign */, true /* bip32derivs */);
|
||||||
CHECK_NONFATAL(err == TransactionError::OK);
|
CHECK_NONFATAL(err == TransactionError::OK);
|
||||||
CHECK_NONFATAL(!complete);
|
CHECK_NONFATAL(!complete);
|
||||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||||
|
@ -4175,8 +4176,8 @@ static RPCHelpMan send()
|
||||||
// First fill transaction with our data without signing,
|
// First fill transaction with our data without signing,
|
||||||
// so external signers are not asked sign more than once.
|
// so external signers are not asked sign more than once.
|
||||||
bool complete;
|
bool complete;
|
||||||
pwallet->FillPSBT(psbtx, complete, SIGHASH_ALL, false, true);
|
pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, false, true);
|
||||||
const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_ALL, true, false);
|
const TransactionError err = pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, true, false);
|
||||||
if (err != TransactionError::OK) {
|
if (err != TransactionError::OK) {
|
||||||
throw JSONRPCTransactionError(err);
|
throw JSONRPCTransactionError(err);
|
||||||
}
|
}
|
||||||
|
@ -4291,7 +4292,8 @@ static RPCHelpMan walletprocesspsbt()
|
||||||
{
|
{
|
||||||
{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction base64 string"},
|
{"psbt", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction base64 string"},
|
||||||
{"sign", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also sign the transaction when updating"},
|
{"sign", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also sign the transaction when updating"},
|
||||||
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"ALL"}, "The signature hash type to sign with if not specified by the PSBT. Must be one of\n"
|
{"sighashtype", RPCArg::Type::STR, RPCArg::Default{"DEFAULT"}, "The signature hash type to sign with if not specified by the PSBT. Must be one of\n"
|
||||||
|
" \"DEFAULT\"\n"
|
||||||
" \"ALL\"\n"
|
" \"ALL\"\n"
|
||||||
" \"NONE\"\n"
|
" \"NONE\"\n"
|
||||||
" \"SINGLE\"\n"
|
" \"SINGLE\"\n"
|
||||||
|
|
|
@ -1807,7 +1807,7 @@ bool CWallet::SignTransaction(CMutableTransaction& tx) const
|
||||||
coins[input.prevout] = Coin(wtx.tx->vout[input.prevout.n], wtx.m_confirm.block_height, wtx.IsCoinBase());
|
coins[input.prevout] = Coin(wtx.tx->vout[input.prevout.n], wtx.m_confirm.block_height, wtx.IsCoinBase());
|
||||||
}
|
}
|
||||||
std::map<int, std::string> input_errors;
|
std::map<int, std::string> input_errors;
|
||||||
return SignTransaction(tx, coins, SIGHASH_ALL, input_errors);
|
return SignTransaction(tx, coins, SIGHASH_DEFAULT, input_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const
|
bool CWallet::SignTransaction(CMutableTransaction& tx, const std::map<COutPoint, Coin>& coins, int sighash, std::map<int, std::string>& input_errors) const
|
||||||
|
|
Loading…
Add table
Reference in a new issue