@@ -2020,7 +2020,12 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
20202020 }
20212021 case OP_TXWEIGHT:
20222022 {
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 );
20242029 break ;
20252030 }
20262031 default : assert (!" invalid opcode" ); break ;
@@ -2581,6 +2586,9 @@ void PrecomputedTransactionData::Init(const T& txTo, std::vector<CTxOut>&& spent
25812586 m_bip143_segwit_ready = true ;
25822587 }
25832588 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);
25842592 m_outpoints_flag_single_hash = GetOutpointFlagsSHA256 (txTo);
25852593 m_spent_asset_amounts_single_hash = GetSpentAssetsAmountsSHA256 (m_spent_outputs);
25862594 m_issuance_rangeproofs_single_hash = GetIssuanceRangeproofsSHA256 (txTo);
@@ -3010,13 +3018,6 @@ const std::vector<CTxOut>* GenericTransactionSignatureChecker<T>::GetTxvOut() co
30103018 return &(txTo->vout );
30113019}
30123020
3013- template <class T >
3014- uint64_t GenericTransactionSignatureChecker<T>::GetTxWeight() const
3015- {
3016- // line copied from GetTransactionWeight() in src/consensus/validation.h
3017- return ::GetSerializeSize (*txTo, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * (WITNESS_SCALE_FACTOR - 1 ) + ::GetSerializeSize (*txTo, PROTOCOL_VERSION);
3018- }
3019-
30203021template <class T >
30213022const PrecomputedTransactionData* GenericTransactionSignatureChecker<T>::GetPrecomputedTransactionData() const
30223023{
0 commit comments