Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 8c740e3

Browse files
authored
Remove unwraps (#1137)
1 parent 677a657 commit 8c740e3

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/execution/execution_entry_point.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use cairo_vm::{
4040
relocatable::{MaybeRelocatable, Relocatable},
4141
},
4242
vm::{
43+
errors::runner_errors::RunnerError,
4344
runners::cairo_runner::{CairoArg, CairoRunner, ExecutionResources, RunResources},
4445
vm_core::VirtualMachine,
4546
},
@@ -469,24 +470,24 @@ impl ExecutionEntryPoint {
469470

470471
/// Returns the hash of the executed contract class.
471472
fn get_code_class_hash<S: State>(&self, state: &mut S) -> Result<[u8; 32], TransactionError> {
472-
if self.class_hash.is_some() {
473+
if let Some(class_hash) = self.class_hash {
473474
match self.call_type {
474-
CallType::Delegate => return Ok(self.class_hash.unwrap()),
475+
CallType::Delegate => return Ok(class_hash),
475476
_ => return Err(TransactionError::CallTypeIsNotDelegate),
476477
}
477478
}
478479
let code_address = match self.call_type {
479-
CallType::Call => Some(self.contract_address.clone()),
480+
CallType::Call => &self.contract_address,
480481
CallType::Delegate => {
481-
if self.code_address.is_some() {
482-
self.code_address.clone()
482+
if let Some(ref code_address) = self.code_address {
483+
code_address
483484
} else {
484485
return Err(TransactionError::AttempToUseNoneCodeAddress);
485486
}
486487
}
487488
};
488489

489-
get_deployed_address_class_hash_at_address(state, &code_address.unwrap())
490+
get_deployed_address_class_hash_at_address(state, code_address)
490491
}
491492

492493
fn _execute_version0_class<S: StateReader>(
@@ -653,7 +654,6 @@ impl ExecutionEntryPoint {
653654
);
654655
let mut runner = StarknetRunner::new(cairo_runner, vm, hint_processor);
655656

656-
// TODO: handle error cases
657657
// Load builtin costs
658658
let builtin_costs: Vec<MaybeRelocatable> =
659659
vec![0.into(), 0.into(), 0.into(), 0.into(), 0.into()];
@@ -664,14 +664,16 @@ impl ExecutionEntryPoint {
664664
.into();
665665

666666
// Load extra data
667-
let core_program_end_ptr =
668-
(runner.cairo_runner.program_base.unwrap() + program.data_len()).unwrap();
667+
let core_program_end_ptr = (runner
668+
.cairo_runner
669+
.program_base
670+
.ok_or(RunnerError::NoProgBase)?
671+
+ program.data_len())?;
669672
let program_extra_data: Vec<MaybeRelocatable> =
670673
vec![0x208B7FFF7FFF7FFE.into(), builtin_costs_ptr];
671674
runner
672675
.vm
673-
.load_data(core_program_end_ptr, &program_extra_data)
674-
.unwrap();
676+
.load_data(core_program_end_ptr, &program_extra_data)?;
675677

676678
// Positional arguments are passed to *args in the 'run_from_entrypoint' function.
677679
let data = self.calldata.iter().map(|d| d.into()).collect();
@@ -687,7 +689,7 @@ impl ExecutionEntryPoint {
687689
.collect();
688690
entrypoint_args.push(CairoArg::Single(alloc_pointer.clone()));
689691
entrypoint_args.push(CairoArg::Single(
690-
alloc_pointer.add_usize(self.calldata.len()).unwrap(),
692+
alloc_pointer.add_usize(self.calldata.len())?,
691693
));
692694

693695
let ref_vec: Vec<&CairoArg> = entrypoint_args.iter().collect();
@@ -711,11 +713,11 @@ impl ExecutionEntryPoint {
711713
.get_initial_fp()
712714
.ok_or(TransactionError::MissingInitialFp)?;
713715

714-
let args_ptr = initial_fp - (entrypoint_args.len() + 2);
716+
let args_ptr = (initial_fp - (entrypoint_args.len() + 2))?;
715717

716718
runner
717719
.vm
718-
.mark_address_range_as_accessed(args_ptr.unwrap(), entrypoint_args.len())?;
720+
.mark_address_range_as_accessed(args_ptr, entrypoint_args.len())?;
719721

720722
*resources_manager = runner
721723
.hint_processor

0 commit comments

Comments
 (0)