Skip to content

Commit

Permalink
Merge with the master and apply the comment.
Browse files Browse the repository at this point in the history
Added an explicit `match` statement to not forget in the future to add handling of a new variants of the transactions.
  • Loading branch information
xgreenx committed Dec 2, 2024
1 parent 02f408a commit 4386bdd
Showing 1 changed file with 51 additions and 13 deletions.
64 changes: 51 additions & 13 deletions fuel-vm/src/interpreter/executors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ use fuel_tx::{
Input,
Receipt,
ScriptExecutionResult,
Transaction,
Upgrade,
UpgradeMetadata,
UpgradePurpose,
Expand Down Expand Up @@ -845,12 +846,59 @@ where
}

pub(crate) fn run(&mut self) -> Result<ProgramState, InterpreterError<S::DataError>> {
for input in self.transaction().inputs() {
if let Input::Contract(contract) = input {
if !self.check_contract_exists(&contract.contract_id)? {
return Err(InterpreterError::Panic(
PanicReason::InputContractDoesNotExist,
));
}
}
}

// TODO: Remove `Create`, `Upgrade`, and `Upload` from here
// https://github.com/FuelLabs/fuel-vm/issues/251
let gas_costs = self.gas_costs().clone();
let fee_params = *self.fee_params();
let base_asset_id = *self.base_asset_id();
let gas_price = self.gas_price();

#[cfg(debug_assertions)]
// The `match` statement exists to ensure that all variants of `Transaction`
// are handled below. If a new variant is added, the compiler will
// emit an error.
{
let mint: Transaction = Transaction::mint(
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
)
.into();
match mint {
Transaction::Create(_) => {
// Handled in the `self.tx.as_create_mut()` branch.
}
Transaction::Upgrade(_) => {
// Handled in the `self.tx.as_upgrade_mut()` branch.
}
Transaction::Upload(_) => {
// Handled in the `self.tx.as_upload_mut()` branch.
}
Transaction::Blob(_) => {
// Handled in the `self.tx.as_blob_mut()` branch.
}
Transaction::Script(_) => {
// Handled in the `else` branch.
}
Transaction::Mint(_) => {
// The `Mint` transaction doesn't implement `ExecutableTransaction`.
}
};
}

let state = if let Some(create) = self.tx.as_create_mut() {
Self::deploy_inner(
create,
Expand Down Expand Up @@ -896,25 +944,15 @@ where
)?;
ProgramState::Return(1)
} else {
if self.transaction().inputs().iter().any(|input| {
if let Input::Contract(contract) = input {
!self
.check_contract_exists(&contract.contract_id)
.unwrap_or(false)
} else {
false
}
}) {
return Err(InterpreterError::Panic(PanicReason::InputContractDoesNotExist));
}

let gas_limit;
let is_empty_script;
if let Some(script) = self.transaction().as_script() {
gas_limit = *script.script_gas_limit();
is_empty_script = script.script().is_empty();
} else {
unreachable!("Only `Create` and `Script` transactions can be executed inside of the VM")
unreachable!(
"Only `Script` transactions can be executed inside of the VM"
)
}

// TODO set tree balance
Expand Down

0 comments on commit 4386bdd

Please sign in to comment.