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

Commit 0502bc8

Browse files
committed
minor code cleanup
1 parent 60a38cd commit 0502bc8

17 files changed

+40
-45
lines changed

src/core/contract_address/deprecated_contract_address.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ impl serde_json::ser::Formatter for PythonDefaultFormatter {
169169

170170
#[derive(serde::Deserialize, serde::Serialize)]
171171
#[serde(deny_unknown_fields)]
172-
173172
pub struct CairoContractDefinition<'a> {
174173
/// Contract ABI, which has no schema definition.
175174
pub abi: serde_json::Value,
@@ -257,7 +256,7 @@ pub(crate) fn compute_hinted_class_hash(
257256
None => {}
258257
}
259258
// We don't know what this type is supposed to be, but if its missing it is null.
260-
if let Some(serde_json::Value::Null) = vals.get_mut("flow_tracking_data") {
259+
if vals.get("flow_tracking_data") == Some(&serde_json::Value::Null) {
261260
vals.remove("flow_tracking_data");
262261
}
263262

src/definitions/block_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl StarknetOsConfig {
8585
/// * `chain_id` - [`Felt252`] of the configured chain.
8686
/// * `fee_token_address` - Address of the token used when paying fees.
8787
/// * `gas_price` - Price of gas.
88-
pub fn new(chain_id: Felt252, fee_token_address: Address, gas_price: u128) -> Self {
88+
pub const fn new(chain_id: Felt252, fee_token_address: Address, gas_price: u128) -> Self {
8989
StarknetOsConfig {
9090
chain_id,
9191
fee_token_address,
@@ -139,7 +139,7 @@ impl BlockContext {
139139
/// Example: for block number 6351, this includes the blocks 5327, 5328, ..., 6340, 6341.
140140
/// * `enforce_l1_handler_fee` - Whether to enforce the L1 handler fee.
141141
#[allow(clippy::too_many_arguments)]
142-
pub fn new(
142+
pub const fn new(
143143
starknet_os_config: StarknetOsConfig,
144144
contract_storage_commitment_tree_height: u64,
145145
global_state_commitment_tree_height: u64,

src/execution/gas_usage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn get_message_segment_lenght(
105105
/// # Returns:
106106
///
107107
/// The on-chain data segment length
108-
pub fn get_onchain_data_segment_length(
108+
pub const fn get_onchain_data_segment_length(
109109
n_modified_contracts: usize,
110110
n_storage_changes: usize,
111111
n_deployments: usize,
@@ -159,7 +159,7 @@ pub fn get_log_message_to_l1_emissions_cost(l2_to_l1_messages: &[L2toL1MessageIn
159159
/// # Returns:
160160
///
161161
/// The cost of event emissions.
162-
pub fn get_event_emission_cost(topics: usize, l1_handler_payload_size: usize) -> usize {
162+
pub const fn get_event_emission_cost(topics: usize, l1_handler_payload_size: usize) -> usize {
163163
GAS_PER_LOG
164164
+ (topics + N_DEFAULT_TOPICS) * GAS_PER_LOG_TOPIC
165165
+ l1_handler_payload_size * GAS_PER_LOG_DATA_WORD

src/execution/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ pub struct TransactionExecutionInfo {
494494
}
495495

496496
impl TransactionExecutionInfo {
497-
pub fn new(
497+
pub const fn new(
498498
validate_info: Option<CallInfo>,
499499
call_info: Option<CallInfo>,
500500
revert_error: Option<String>,
@@ -553,7 +553,7 @@ impl TransactionExecutionInfo {
553553
}
554554
}
555555

556-
pub fn new_without_fee_info(
556+
pub const fn new_without_fee_info(
557557
validate_info: Option<CallInfo>,
558558
call_info: Option<CallInfo>,
559559
revert_error: Option<String>,

src/hash_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ pub fn compute_hash_on_elements(vec: &[Felt252]) -> Result<Felt252, HashError> {
125125
let felt_result = felt_vec
126126
.into_iter()
127127
.reduce(|x, y| pedersen_hash(&x, &y))
128-
.ok_or(HashError::FailedToComputeHash(
129-
"Failed to compute Pedersen hash.".to_string(),
130-
))?;
128+
.ok_or_else(|| {
129+
HashError::FailedToComputeHash("Failed to compute Pedersen hash.".to_string())
130+
})?;
131131

132132
let result = Felt252::from_bytes_be(&felt_result.to_bytes_be());
133133
Ok(result)

src/runner/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<H> StarknetRunner<H>
6969
where
7070
H: HintProcessor + HintProcessorPostRun,
7171
{
72-
pub fn new(cairo_runner: CairoRunner, vm: VirtualMachine, hint_processor: H) -> Self {
72+
pub const fn new(cairo_runner: CairoRunner, vm: VirtualMachine, hint_processor: H) -> Self {
7373
StarknetRunner {
7474
cairo_runner,
7575
vm,

src/services/api/contract_classes/deprecated_contract_class.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct ContractEntryPoint {
3636
}
3737

3838
impl ContractEntryPoint {
39-
pub fn new(selector: Felt252, offset: usize) -> ContractEntryPoint {
39+
pub const fn new(selector: Felt252, offset: usize) -> ContractEntryPoint {
4040
ContractEntryPoint { selector, offset }
4141
}
4242
}

src/state/in_memory_state_reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::collections::HashMap;
1515
///
1616
/// This implementation is used for testing and debugging.
1717
/// It uses HashMaps to store the data.
18-
#[derive(Debug, MutGetters, Getters, PartialEq, Clone, Default)]
18+
#[derive(Debug, MutGetters, Getters, PartialEq, Eq, Clone, Default)]
1919
pub struct InMemoryStateReader {
2020
#[getset(get_mut = "pub")]
2121
pub address_to_class_hash: HashMap<Address, ClassHash>,
@@ -39,7 +39,7 @@ impl InMemoryStateReader {
3939
/// - `class_hash_to_contract_class` - A HashMap from class hashes to their contract classes.
4040
/// - `casm_contract_classes` - A [CasmClassCache].
4141
/// - `class_hash_to_compiled_class_hash` - A HashMap from class hashes to their compiled class hashes.
42-
pub fn new(
42+
pub const fn new(
4343
address_to_class_hash: HashMap<Address, ClassHash>,
4444
address_to_nonce: HashMap<Address, Felt252>,
4545
address_to_storage: HashMap<StorageEntry, Felt252>,

src/state/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct BlockInfo {
3535
}
3636

3737
impl BlockInfo {
38-
pub fn empty(sequencer_address: Address) -> Self {
38+
pub const fn empty(sequencer_address: Address) -> Self {
3939
BlockInfo {
4040
block_number: 0, // To do: In cairo-lang, this value is set to -1
4141
block_timestamp: 0,
@@ -44,7 +44,7 @@ impl BlockInfo {
4444
}
4545
}
4646

47-
pub fn validate_legal_progress(
47+
pub const fn validate_legal_progress(
4848
&self,
4949
next_block_info: &BlockInfo,
5050
) -> Result<(), TransactionError> {
@@ -102,7 +102,7 @@ impl ExecutionResourcesManager {
102102
}
103103
}
104104

105-
#[derive(Default, Clone, PartialEq, Debug, Getters)]
105+
#[derive(Default, Clone, PartialEq, Eq, Debug, Getters)]
106106
#[getset(get = "pub")]
107107
pub struct StateDiff {
108108
pub(crate) address_to_class_hash: HashMap<Address, ClassHash>,
@@ -112,7 +112,7 @@ pub struct StateDiff {
112112
}
113113

114114
impl StateDiff {
115-
pub fn new(
115+
pub const fn new(
116116
address_to_class_hash: HashMap<Address, ClassHash>,
117117
address_to_nonce: HashMap<Address, Felt252>,
118118
class_hash_to_compiled_class: HashMap<ClassHash, CompiledClass>,

src/state/state_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl StateCache {
4141
#[allow(clippy::too_many_arguments)]
4242

4343
/// Create a new StateCache with given initial and written values for testing
44-
pub fn new(
44+
pub const fn new(
4545
class_hash_initial_values: HashMap<Address, ClassHash>,
4646
compiled_class_hash_initial_values: HashMap<ClassHash, CompiledClass>,
4747
nonce_initial_values: HashMap<Address, Felt252>,
@@ -82,7 +82,7 @@ impl StateCache {
8282

8383
/// Creates a new instance of `StateCache` for testing purposes with the provided initial values and writes.
8484
#[allow(clippy::too_many_arguments)]
85-
pub fn new_for_testing(
85+
pub const fn new_for_testing(
8686
class_hash_initial_values: HashMap<Address, [u8; 32]>,
8787
compiled_class_hash_initial_values: HashMap<ClassHash, CompiledClass>,
8888
nonce_initial_values: HashMap<Address, Felt252>,

0 commit comments

Comments
 (0)