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

Commit 8f9b552

Browse files
authored
Move Address to transaction module + add utility impls (#1227)
* Move Address to transaction module * Fix imports + Implement conversions to and from Felt * Impl from_hex_string * Fix * Fix
1 parent 9c8bbe9 commit 8f9b552

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+187
-144
lines changed

bench/internals.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ use starknet_in_rust::{
1414
services::api::contract_classes::{
1515
compiled_class::CompiledClass, deprecated_contract_class::ContractClass,
1616
},
17-
state::{cached_state::CachedState, state_api::State},
1817
state::{
19-
contract_class_cache::PermanentContractClassCache,
20-
in_memory_state_reader::InMemoryStateReader,
18+
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
19+
in_memory_state_reader::InMemoryStateReader, state_api::State,
2120
},
22-
transaction::{declare::Declare, Deploy, DeployAccount, InvokeFunction},
23-
utils::{Address, ClassHash},
21+
transaction::{declare::Declare, Address, Deploy, DeployAccount, InvokeFunction},
22+
utils::ClassHash,
2423
};
2524
use std::{hint::black_box, sync::Arc};
2625

bench/yas.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use starknet_in_rust::{
2323
state::{
2424
cached_state::CachedState, contract_class_cache::ContractClassCache, state_api::StateReader,
2525
},
26+
transaction::Address,
2627
transaction::{DeclareV2, InvokeFunction},
27-
utils::Address,
2828
};
2929
use std::time::{Duration, Instant};
3030
use tracing::{debug, info};
@@ -988,7 +988,8 @@ mod utils {
988988
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
989989
in_memory_state_reader::InMemoryStateReader, state_api::State,
990990
},
991-
utils::{Address, ClassHash},
991+
transaction::Address,
992+
utils::ClassHash,
992993
CasmContractClass, ContractClass as SierraContractClass,
993994
};
994995
use std::{fs, path::Path, sync::Arc};

examples/contract_execution/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use starknet_in_rust::{
2020
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
2121
in_memory_state_reader::InMemoryStateReader, state_api::State,
2222
},
23-
transaction::{DeclareV2, DeployAccount, InvokeFunction},
24-
utils::{calculate_sn_keccak, felt_to_hash, Address},
23+
transaction::{Address, DeclareV2, DeployAccount, InvokeFunction},
24+
utils::{calculate_sn_keccak, felt_to_hash},
2525
CasmContractClass, SierraContractClass,
2626
};
2727
use std::{fs::File, io::BufReader, path::Path, str::FromStr, sync::Arc};

examples/lru_cache/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use starknet_in_rust::{
1212
contract_class_cache::{ContractClassCache, PermanentContractClassCache},
1313
in_memory_state_reader::InMemoryStateReader,
1414
},
15-
transaction::{Declare, Deploy, InvokeFunction},
16-
utils::{calculate_sn_keccak, Address, ClassHash},
15+
transaction::{Address, Declare, Deploy, InvokeFunction},
16+
utils::{calculate_sn_keccak, ClassHash},
1717
};
1818
use std::{
1919
num::NonZeroUsize,

fuzzer/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use starknet_in_rust::{
2121
in_memory_state_reader::InMemoryStateReader,
2222
ExecutionResourcesManager,
2323
},
24-
utils::{calculate_sn_keccak, Address},
24+
transaction::Address,
25+
utils::calculate_sn_keccak,
2526
};
2627
use std::{
2728
collections::HashSet, fs, path::PathBuf, process::Command, sync::Arc, thread, time::Duration,

replay/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use starknet_in_rust::{
2323
state::{
2424
cached_state::CachedState, contract_class_cache::PermanentContractClassCache, BlockInfo,
2525
},
26-
utils::Address,
26+
transaction::Address,
2727
Felt252,
2828
};
2929
#[cfg(feature = "benchmark")]

rpc_state_reader/src/sir_state_reader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ use starknet_in_rust::{
2828
BlockInfo,
2929
},
3030
transaction::{
31-
declare_tx_from_sn_api_transaction, error::TransactionError, DeployAccount, InvokeFunction,
32-
L1Handler,
31+
declare_tx_from_sn_api_transaction, error::TransactionError, Address, DeployAccount,
32+
InvokeFunction, L1Handler,
3333
},
34-
utils::{Address, ClassHash},
34+
utils::ClassHash,
3535
};
3636

3737
use crate::{

src/bin/deploy_invoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use starknet_in_rust::{
1010
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
1111
in_memory_state_reader::InMemoryStateReader, state_api::State,
1212
},
13+
transaction::Address,
1314
transaction::{Deploy, InvokeFunction, Transaction},
14-
utils::Address,
1515
};
1616
use std::{path::PathBuf, sync::Arc};
1717

src/bin/fibonacci.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use starknet_in_rust::{
1515
contract_class_cache::PermanentContractClassCache,
1616
in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager,
1717
},
18-
utils::Address,
18+
transaction::Address,
1919
EntryPointType,
2020
};
2121
use std::{path::PathBuf, sync::Arc};

src/bin/invoke.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use starknet_in_rust::{
1010
cached_state::CachedState, contract_class_cache::PermanentContractClassCache,
1111
in_memory_state_reader::InMemoryStateReader,
1212
},
13-
transaction::{InvokeFunction, Transaction},
14-
utils::{Address, ClassHash},
13+
transaction::{Address, InvokeFunction, Transaction},
14+
utils::ClassHash,
1515
};
1616
use std::{path::PathBuf, sync::Arc};
1717

src/bin/invoke_with_cachedstate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use starknet_in_rust::{
1313
state::{
1414
cached_state::CachedState, contract_class_cache::PermanentContractClassCache, BlockInfo,
1515
},
16+
transaction::Address,
1617
transaction::{InvokeFunction, VersionSpecificAccountTxFields},
17-
utils::{Address, ClassHash},
18+
utils::ClassHash,
1819
};
1920
use std::{collections::HashMap, path::PathBuf, sync::Arc};
2021

src/bin/native_bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ use starknet_in_rust::{
3232
},
3333
state::cached_state::CachedState,
3434
state::{in_memory_state_reader::InMemoryStateReader, ExecutionResourcesManager},
35-
utils::{Address, ClassHash},
35+
transaction::Address,
36+
utils::ClassHash,
3637
};
3738
use std::cell::RefCell;
3839
use std::rc::Rc;

src/core/errors/state_errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
2-
services::api::contract_class_errors::ContractClassError,
3-
state::state_cache::StorageEntry,
4-
utils::{Address, ClassHash},
2+
services::api::contract_class_errors::ContractClassError, state::state_cache::StorageEntry,
3+
transaction::Address, utils::ClassHash,
54
};
65
use starknet::core::types::FromByteArrayError;
76
use thiserror::Error;

src/core/transaction_hash/current.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::str::FromStr;
22

3-
use crate::{
4-
transaction::{DataAvailabilityMode, ResourceBounds},
5-
utils::Address,
6-
};
3+
use crate::transaction::{Address, DataAvailabilityMode, ResourceBounds};
74
use cairo_vm::Felt252;
85
use lazy_static::lazy_static;
96
use num_bigint::BigUint;

src/core/transaction_hash/deprecated.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::transaction::error::TransactionError;
33
use crate::{
44
core::contract_address::compute_deprecated_class_hash,
55
definitions::constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR, hash_utils::compute_hash_on_elements,
6-
services::api::contract_classes::deprecated_contract_class::ContractClass, utils::Address,
6+
services::api::contract_classes::deprecated_contract_class::ContractClass,
7+
transaction::Address,
78
};
89
use cairo_vm::Felt252;
910
use num_traits::Zero;

src/core/transaction_hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use cairo_vm::Felt252;
44
use lazy_static::lazy_static;
55

66
use crate::{
7+
transaction::Address,
78
transaction::{error::TransactionError, VersionSpecificAccountTxFields},
8-
utils::Address,
99
};
1010

1111
use super::errors::hash_errors::HashError;

src/definitions/block_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! This module contains structs representing the context of a specific Starknet block.
44
5-
use crate::{state::BlockInfo, utils::Address};
5+
use crate::{state::BlockInfo, transaction::Address};
66
use cairo_vm::Felt252;
77
use core::fmt;
88
use getset::{CopyGetters, Getters, MutGetters};

src/definitions/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::block_context::{StarknetChainId, StarknetOsConfig};
2-
use crate::utils::Address;
2+
use crate::transaction::Address;
33
use cairo_vm::Felt252;
44
use lazy_static::lazy_static;
55

src/execution/execution_entry_point.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use crate::{
2121
deprecated_syscall_handler::DeprecatedSyscallHintProcessor,
2222
syscall_handler::SyscallHintProcessor,
2323
},
24-
transaction::error::TransactionError,
24+
transaction::{error::TransactionError, Address},
2525
utils::{
2626
get_deployed_address_class_hash_at_address, parse_builtin_names,
27-
validate_contract_deployed, Address, ClassHash,
27+
validate_contract_deployed, ClassHash,
2828
},
2929
};
3030
use cairo_lang_sierra::program::Program as SierraProgram;

src/execution/gas_usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub const fn get_event_emission_cost(topics: usize, l1_handler_payload_size: usi
172172
mod test {
173173
use super::get_event_emission_cost;
174174
use super::*;
175-
use crate::{execution::OrderedL2ToL1Message, utils::Address};
175+
use crate::{execution::OrderedL2ToL1Message, transaction::Address};
176176
use coverage_helper::test;
177177

178178
#[test]

src/execution/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::{
88
definitions::{constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR, transaction_type::TransactionType},
99
state::state_cache::StorageEntry,
1010
syscalls::syscall_handler_errors::SyscallHandlerError,
11-
transaction::error::TransactionError,
12-
utils::{get_big_int, get_integer, get_relocatable, Address, ClassHash},
11+
transaction::{error::TransactionError, Address},
12+
utils::{get_big_int, get_integer, get_relocatable, ClassHash},
1313
};
1414
use cairo_vm::Felt252;
1515
use cairo_vm::{
@@ -689,7 +689,7 @@ impl L2toL1MessageInfo {
689689
#[cfg(test)]
690690
mod tests {
691691
use super::*;
692-
use crate::utils::{string_to_hash, Address};
692+
use crate::utils::string_to_hash;
693693

694694
#[test]
695695
fn test_get_sorted_single_event() {

src/hash_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::core::errors::hash_errors::HashError;
2-
use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, utils::Address};
2+
use crate::{syscalls::syscall_handler_errors::SyscallHandlerError, transaction::Address};
33
use cairo_vm::Felt252;
44
use starknet_crypto::{pedersen_hash, FieldElement};
55
use std::vec;
@@ -32,7 +32,7 @@ use std::vec;
3232
/// # Examples
3333
///
3434
/// ```
35-
/// use starknet_in_rust::{hash_utils::calculate_contract_address, utils::Address, Felt252};
35+
/// use starknet_in_rust::{hash_utils::calculate_contract_address, transaction::Address, Felt252};
3636
///
3737
/// let salt = Felt252::from(123_u16);
3838
/// let class_hash = Felt252::from(456_u16);

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use crate::{
1414
state_api::{State, StateReader},
1515
ExecutionResourcesManager,
1616
},
17+
transaction::Address,
1718
transaction::{error::TransactionError, fee::calculate_tx_fee, L1Handler, Transaction},
18-
utils::Address,
1919
};
2020
pub use cairo_vm::Felt252;
2121
use definitions::block_context::FeeType;
@@ -273,16 +273,16 @@ mod test {
273273
ExecutionResourcesManager,
274274
},
275275
transaction::{
276-
Declare, DeclareV2, Deploy, DeployAccount, InvokeFunction, L1Handler, Transaction,
277-
VersionSpecificAccountTxFields,
276+
Address, Declare, DeclareV2, Deploy, DeployAccount, InvokeFunction, L1Handler,
277+
Transaction, VersionSpecificAccountTxFields,
278278
},
279279
utils::{
280280
felt_to_hash,
281281
test_utils::{
282282
create_account_tx_test_state, TEST_ACCOUNT_CONTRACT_ADDRESS,
283283
TEST_FIB_COMPILED_CONTRACT_CLASS_HASH,
284284
},
285-
Address, ClassHash,
285+
ClassHash,
286286
},
287287
};
288288
use cairo_lang_starknet::{

src/services/api/messages.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use cairo_vm::Felt252;
22
use num_traits::ToPrimitive;
33
use sha3::{Digest, Keccak256};
44

5-
use crate::utils::Address;
5+
use crate::transaction::Address;
66

77
/// A StarkNet Message from L2 to L1.
88
#[derive(Debug, Clone)]

src/state/cached_state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use crate::{
77
core::errors::state_errors::StateError,
88
services::api::contract_classes::compiled_class::CompiledClass,
99
state::StateDiff,
10+
transaction::Address,
1011
utils::{
1112
get_erc20_balance_var_addresses, subtract_mappings, subtract_mappings_keys,
12-
to_cache_state_storage_mapping, Address, ClassHash,
13+
to_cache_state_storage_mapping, ClassHash,
1314
},
1415
};
1516
use cairo_vm::Felt252;

src/state/contract_storage_state.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use super::{
33
contract_class_cache::ContractClassCache,
44
state_api::{State, StateReader},
55
};
6-
use crate::{
7-
core::errors::state_errors::StateError,
8-
utils::{Address, ClassHash},
9-
};
6+
use crate::{core::errors::state_errors::StateError, transaction::Address, utils::ClassHash};
107
use cairo_vm::Felt252;
118
use std::collections::HashSet;
129

src/state/in_memory_state_reader.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
state::{
55
cached_state::UNINITIALIZED_CLASS_HASH, state_api::StateReader, state_cache::StorageEntry,
66
},
7-
utils::{Address, ClassHash, CompiledClassHash},
7+
transaction::Address,
8+
utils::{ClassHash, CompiledClassHash},
89
};
910
use cairo_vm::Felt252;
1011
use getset::{Getters, MutGetters};

src/state/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use self::{
55
use crate::{
66
core::errors::state_errors::StateError,
77
definitions::block_context::GasPrices,
8-
transaction::error::TransactionError,
8+
transaction::{error::TransactionError, Address},
99
utils::{
10-
get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping, Address,
11-
ClassHash, CompiledClassHash,
10+
get_keys, to_cache_state_storage_mapping, to_state_diff_storage_mapping, ClassHash,
11+
CompiledClassHash,
1212
},
1313
};
1414
use cairo_vm::{vm::runners::cairo_runner::ExecutionResources, Felt252};
@@ -250,7 +250,8 @@ mod test {
250250
state_api::StateReader,
251251
state_cache::{StateCache, StorageEntry},
252252
},
253-
utils::{Address, ClassHash},
253+
transaction::Address,
254+
utils::ClassHash,
254255
};
255256
use cairo_vm::Felt252;
256257
use std::{collections::HashMap, sync::Arc};

src/state/state_api.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
definitions::block_context::{BlockContext, FeeType},
55
services::api::contract_classes::compiled_class::CompiledClass,
66
state::StateDiff,
7-
utils::{get_erc20_balance_var_addresses, Address, ClassHash, CompiledClassHash},
7+
transaction::Address,
8+
utils::{get_erc20_balance_var_addresses, ClassHash, CompiledClassHash},
89
};
910
use cairo_lang_utils::bigint::BigUintAsHex;
1011
use cairo_vm::Felt252;

src/state/state_cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{
22
core::errors::state_errors::StateError,
3-
utils::{Address, ClassHash, CompiledClassHash},
3+
transaction::Address,
4+
utils::{ClassHash, CompiledClassHash},
45
};
56
use cairo_vm::Felt252;
67
use getset::{Getters, MutGetters};

src/syscalls/business_logic_syscall_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use crate::{
3636
state_api::{State, StateReader},
3737
BlockInfo, ExecutionResourcesManager,
3838
},
39-
transaction::error::TransactionError,
40-
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range, Address, ClassHash},
39+
transaction::{error::TransactionError, Address},
40+
utils::{calculate_sn_keccak, felt_to_hash, get_big_int, get_felt_range, ClassHash},
4141
};
4242
use cairo_vm::Felt252;
4343
use cairo_vm::{

0 commit comments

Comments
 (0)