mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-09-06 21:01:40 +02:00
Add precomputed txdata support to MutableTransactionSignatureCreator
This provides a means to pass in a PrecomputedTransactionData object to the MutableTransactionSignatureCreator, allowing the prevout data to be passed into the signature hashers. It is also more efficient.
This commit is contained in:
@@ -14,7 +14,19 @@
|
|||||||
|
|
||||||
typedef std::vector<unsigned char> valtype;
|
typedef std::vector<unsigned char> valtype;
|
||||||
|
|
||||||
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn) : txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn, MissingDataBehavior::FAIL) {}
|
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn)
|
||||||
|
: txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn), checker(txTo, nIn, amountIn, MissingDataBehavior::FAIL),
|
||||||
|
m_txdata(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MutableTransactionSignatureCreator::MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData* txdata, int nHashTypeIn)
|
||||||
|
: txTo(txToIn), nIn(nInIn), nHashType(nHashTypeIn), amount(amountIn),
|
||||||
|
checker(txdata ? MutableTransactionSignatureChecker(txTo, nIn, amount, *txdata, MissingDataBehavior::FAIL) :
|
||||||
|
MutableTransactionSignatureChecker(txTo, nIn, amount, MissingDataBehavior::FAIL)),
|
||||||
|
m_txdata(txdata)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& address, const CScript& scriptCode, SigVersion sigversion) const
|
bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& address, const CScript& scriptCode, SigVersion sigversion) const
|
||||||
{
|
{
|
||||||
@@ -26,10 +38,10 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
|
|||||||
if (sigversion == SigVersion::WITNESS_V0 && !key.IsCompressed())
|
if (sigversion == SigVersion::WITNESS_V0 && !key.IsCompressed())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Signing for witness scripts needs the amount.
|
// Signing without known amount does not work in witness scripts.
|
||||||
if (sigversion == SigVersion::WITNESS_V0 && amount < 0) return false;
|
if (sigversion == SigVersion::WITNESS_V0 && !MoneyRange(amount)) return false;
|
||||||
|
|
||||||
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion);
|
uint256 hash = SignatureHash(scriptCode, *txTo, nIn, nHashType, 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)nHashType);
|
||||||
|
@@ -40,9 +40,11 @@ class MutableTransactionSignatureCreator : public BaseSignatureCreator {
|
|||||||
int nHashType;
|
int nHashType;
|
||||||
CAmount amount;
|
CAmount amount;
|
||||||
const MutableTransactionSignatureChecker checker;
|
const MutableTransactionSignatureChecker checker;
|
||||||
|
const PrecomputedTransactionData* m_txdata;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL);
|
MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, int nHashTypeIn = SIGHASH_ALL);
|
||||||
|
MutableTransactionSignatureCreator(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData* txdata, int nHashTypeIn = SIGHASH_ALL);
|
||||||
const BaseSignatureChecker& Checker() const override { return checker; }
|
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;
|
bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user