mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
refactor: keep spent outputs in PrecomputedTransactionData
A BIP-341 signature message may commit to the scriptPubKeys and amounts of all spent outputs (including other ones than the input being signed for spends), so keep them available to signature hashing code.
This commit is contained in:
@@ -1294,10 +1294,12 @@ uint256 GetOutputsSHA256(const T& txTo)
|
||||
} // namespace
|
||||
|
||||
template <class T>
|
||||
void PrecomputedTransactionData::Init(const T& txTo)
|
||||
void PrecomputedTransactionData::Init(const T& txTo, std::vector<CTxOut>&& spent_outputs)
|
||||
{
|
||||
assert(!m_ready);
|
||||
|
||||
m_spent_outputs = std::move(spent_outputs);
|
||||
|
||||
// Cache is calculated only for transactions with witness
|
||||
if (txTo.HasWitness()) {
|
||||
hashPrevouts = SHA256Uint256(GetPrevoutsSHA256(txTo));
|
||||
@@ -1311,12 +1313,12 @@ void PrecomputedTransactionData::Init(const T& txTo)
|
||||
template <class T>
|
||||
PrecomputedTransactionData::PrecomputedTransactionData(const T& txTo)
|
||||
{
|
||||
Init(txTo);
|
||||
Init(txTo, {});
|
||||
}
|
||||
|
||||
// explicit instantiation
|
||||
template void PrecomputedTransactionData::Init(const CTransaction& txTo);
|
||||
template void PrecomputedTransactionData::Init(const CMutableTransaction& txTo);
|
||||
template void PrecomputedTransactionData::Init(const CTransaction& txTo, std::vector<CTxOut>&& spent_outputs);
|
||||
template void PrecomputedTransactionData::Init(const CMutableTransaction& txTo, std::vector<CTxOut>&& spent_outputs);
|
||||
template PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo);
|
||||
template PrecomputedTransactionData::PrecomputedTransactionData(const CMutableTransaction& txTo);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
class CPubKey;
|
||||
class CScript;
|
||||
class CTransaction;
|
||||
class CTxOut;
|
||||
class uint256;
|
||||
|
||||
/** Signature hash types/flags */
|
||||
@@ -122,11 +123,12 @@ struct PrecomputedTransactionData
|
||||
{
|
||||
uint256 hashPrevouts, hashSequence, hashOutputs;
|
||||
bool m_ready = false;
|
||||
std::vector<CTxOut> m_spent_outputs;
|
||||
|
||||
PrecomputedTransactionData() = default;
|
||||
|
||||
template <class T>
|
||||
void Init(const T& tx);
|
||||
void Init(const T& tx, std::vector<CTxOut>&& spent_outputs);
|
||||
|
||||
template <class T>
|
||||
explicit PrecomputedTransactionData(const T& tx);
|
||||
|
||||
Reference in New Issue
Block a user