sui_adapter_latest/static_programmable_transactions/
mod.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4#![deny(clippy::arithmetic_side_effects)]
5#![deny(clippy::indexing_slicing)]
6#![deny(clippy::cast_possible_truncation)]
7
8use crate::{
9    data_store::cached_package_store::CachedPackageStore,
10    execution_mode::ExecutionMode,
11    execution_value::ExecutionState,
12    gas_charger::GasCharger,
13    static_programmable_transactions::{
14        env::Env, linkage::analysis::LinkageAnalyzer, metering::translation_meter,
15    },
16};
17use move_trace_format::format::MoveTraceBuilder;
18use move_vm_runtime::move_vm::MoveVM;
19use std::{cell::RefCell, rc::Rc, sync::Arc};
20use sui_protocol_config::ProtocolConfig;
21use sui_types::{
22    base_types::TxContext, error::ExecutionError, execution::ResultWithTimings,
23    metrics::LimitsMetrics, storage::BackingPackageStore, transaction::ProgrammableTransaction,
24};
25
26// TODO we might replace this with a new one
27pub use crate::data_store::legacy::linkage_view::LinkageView;
28
29pub mod env;
30pub mod execution;
31pub mod linkage;
32pub mod loading;
33pub mod metering;
34pub mod spanned;
35pub mod typing;
36
37pub fn execute<Mode: ExecutionMode>(
38    protocol_config: &ProtocolConfig,
39    metrics: Arc<LimitsMetrics>,
40    vm: &MoveVM,
41    state_view: &mut dyn ExecutionState,
42    package_store: &dyn BackingPackageStore,
43    tx_context: Rc<RefCell<TxContext>>,
44    gas_charger: &mut GasCharger,
45    // which inputs are withdrawals that need to be converted to coins
46    withdrawal_compatibility_inputs: Option<Vec<bool>>,
47    txn: ProgrammableTransaction,
48    trace_builder_opt: &mut Option<MoveTraceBuilder>,
49) -> ResultWithTimings<Mode::ExecutionResults, ExecutionError> {
50    let gas_coin = gas_charger.gas_coin();
51    let package_store = CachedPackageStore::new(Box::new(package_store));
52    let linkage_analysis =
53        LinkageAnalyzer::new::<Mode>(protocol_config).map_err(|e| (e, vec![]))?;
54
55    let mut env = Env::new(
56        protocol_config,
57        vm,
58        state_view,
59        &package_store,
60        &linkage_analysis,
61    );
62    let mut translation_meter =
63        translation_meter::TranslationMeter::new(protocol_config, gas_charger);
64
65    let txn = {
66        let tx_context_ref = tx_context.borrow();
67        loading::translate::transaction::<Mode>(
68            &mut translation_meter,
69            &env,
70            &tx_context_ref,
71            withdrawal_compatibility_inputs,
72            gas_coin,
73            txn,
74        )
75        .map_err(|e| (e, vec![]))?
76    };
77    let txn = typing::translate_and_verify::<Mode>(&mut translation_meter, &env, txn)
78        .map_err(|e| (e, vec![]))?;
79    execution::interpreter::execute::<Mode>(
80        &mut env,
81        metrics,
82        tx_context,
83        gas_charger,
84        txn,
85        trace_builder_opt,
86    )
87}