@@ -2020,7 +2020,12 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
2020
2020
}
2021
2021
case OP_TXWEIGHT:
2022
2022
{
2023
- push8_le (stack, checker.GetTxWeight ());
2023
+ const PrecomputedTransactionData *cache = checker.GetPrecomputedTransactionData ();
2024
+ // Return error if the evaluation context is unavailable
2025
+ // TODO: Handle accoding to MissingDataBehavior
2026
+ if (!cache || !cache->m_bip341_taproot_ready )
2027
+ return set_error (serror, SCRIPT_ERR_INTROSPECT_CONTEXT_UNAVAILABLE);
2028
+ push8_le (stack, cache->m_tx_weight );
2024
2029
break ;
2025
2030
}
2026
2031
default : assert (!" invalid opcode" ); break ;
@@ -2581,6 +2586,9 @@ void PrecomputedTransactionData::Init(const T& txTo, std::vector<CTxOut>&& spent
2581
2586
m_bip143_segwit_ready = true ;
2582
2587
}
2583
2588
if (uses_bip341_taproot) {
2589
+ // line copied from GetTransactionWeight() in src/consensus/validation.h
2590
+ // (we cannot directly use that function for type reasons)
2591
+ m_tx_weight = ::GetSerializeSize (txTo, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1 ) + ::GetSerializeSize (txTo, PROTOCOL_VERSION);
2584
2592
m_outpoints_flag_single_hash = GetOutpointFlagsSHA256 (txTo);
2585
2593
m_spent_asset_amounts_single_hash = GetSpentAssetsAmountsSHA256 (m_spent_outputs);
2586
2594
m_issuance_rangeproofs_single_hash = GetIssuanceRangeproofsSHA256 (txTo);
@@ -2993,13 +3001,6 @@ const std::vector<CTxOut>* GenericTransactionSignatureChecker<T>::GetTxvOut() co
2993
3001
return &(txTo->vout );
2994
3002
}
2995
3003
2996
- template <class T >
2997
- uint64_t GenericTransactionSignatureChecker<T>::GetTxWeight() const
2998
- {
2999
- // line copied from GetTransactionWeight() in src/consensus/validation.h
3000
- return ::GetSerializeSize (*txTo, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1 ) + ::GetSerializeSize (*txTo, PROTOCOL_VERSION);
3001
- }
3002
-
3003
3004
template <class T >
3004
3005
const PrecomputedTransactionData* GenericTransactionSignatureChecker<T>::GetPrecomputedTransactionData() const
3005
3006
{
0 commit comments