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

Commit dbf5906

Browse files
use Felt252 for chain ids (#847)
Co-authored-by: Juan Bono <juanbono94@gmail.com>
1 parent 0511707 commit dbf5906

File tree

11 files changed

+29
-29
lines changed

11 files changed

+29
-29
lines changed

src/bin/invoke_with_cachedstate.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ fn create_initial_state() -> CachedState<InMemoryStateReader> {
117117

118118
pub fn new_starknet_block_context_for_testing() -> BlockContext {
119119
BlockContext::new(
120-
StarknetOsConfig::new(StarknetChainId::TestNet, Address(Felt252::zero()), 0),
120+
StarknetOsConfig::new(
121+
StarknetChainId::TestNet.to_felt(),
122+
Address(Felt252::zero()),
123+
0,
124+
),
121125
0,
122126
0,
123127
Default::default(),

src/definitions/block_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl StarknetChainId {
6868
pub struct StarknetOsConfig {
6969
/// ID of the configured chain
7070
#[getset(get = "pub", get_mut = "pub")]
71-
pub(crate) chain_id: StarknetChainId,
71+
pub(crate) chain_id: Felt252,
7272
/// Address of the token used when paying fees
7373
#[get = "pub"]
7474
pub(crate) fee_token_address: Address,
@@ -81,10 +81,10 @@ impl StarknetOsConfig {
8181
///
8282
/// # Arguments
8383
///
84-
/// * `chain_id` - [`StarknetChainId`] of the configured chain.
84+
/// * `chain_id` - [`Felt252`] of the configured chain.
8585
/// * `fee_token_address` - Address of the token used when paying fees.
8686
/// * `gas_price` - Price of gas.
87-
pub fn new(chain_id: StarknetChainId, fee_token_address: Address, gas_price: u128) -> Self {
87+
pub fn new(chain_id: Felt252, fee_token_address: Address, gas_price: u128) -> Self {
8888
StarknetOsConfig {
8989
chain_id,
9090
fee_token_address,

src/definitions/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ lazy_static! {
6262
16
6363
));
6464
pub static ref DEFAULT_STARKNET_OS_CONFIG: StarknetOsConfig = StarknetOsConfig {
65-
chain_id: StarknetChainId::TestNet,
65+
chain_id: StarknetChainId::TestNet.to_felt(),
6666
fee_token_address: Address(felt_str!(
6767
"4c07059285c2607d528a4c5220ef1f64d8f01273c23cfd9dec68759f61b544",
6868
16

src/execution/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ pub mod os_usage;
55
use crate::definitions::constants::QUERY_VERSION_BASE;
66
use crate::services::api::contract_classes::deprecated_contract_class::EntryPointType;
77
use crate::{
8-
definitions::{
9-
block_context::StarknetChainId, constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR,
10-
transaction_type::TransactionType,
11-
},
8+
definitions::{constants::CONSTRUCTOR_ENTRY_POINT_SELECTOR, transaction_type::TransactionType},
129
state::state_cache::StorageEntry,
1310
syscalls::syscall_handler_errors::SyscallHandlerError,
1411
transaction::error::TransactionError,
@@ -370,7 +367,7 @@ impl TxInfoStruct {
370367
pub(crate) fn new(
371368
tx: TransactionExecutionContext,
372369
signature: Relocatable,
373-
chain_id: StarknetChainId,
370+
chain_id: Felt252,
374371
) -> TxInfoStruct {
375372
TxInfoStruct {
376373
version: tx.version,
@@ -379,7 +376,7 @@ impl TxInfoStruct {
379376
signature_len: tx.signature.len(),
380377
signature,
381378
transaction_hash: tx.transaction_hash,
382-
chain_id: chain_id.to_felt(),
379+
chain_id,
383380
nonce: tx.nonce,
384381
}
385382
}

src/syscalls/business_logic_syscall_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<'a, S: StateReader> BusinessLogicSyscallHandler<'a, S> {
644644
res_segment = (res_segment + 1)?;
645645
vm.insert_value::<Felt252>(
646646
res_segment,
647-
self.block_context.starknet_os_config.chain_id.to_felt(),
647+
self.block_context.starknet_os_config.chain_id.clone(),
648648
)?;
649649
res_segment = (res_segment + 1)?;
650650
vm.insert_value::<Felt252>(res_segment, tx_info.nonce.clone())?;

src/syscalls/deprecated_business_logic_syscall_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'a, S: StateReader> DeprecatedBLSyscallHandler<'a, S> {
554554
let tx_info = TxInfoStruct::new(
555555
tx,
556556
signature,
557-
self.block_context.starknet_os_config.chain_id,
557+
self.block_context.starknet_os_config.chain_id.clone(),
558558
);
559559

560560
let tx_info_ptr_temp = self.allocate_segment(vm, tx_info.to_vec())?;

src/syscalls/deprecated_syscall_handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ mod tests {
538538
.syscall_handler
539539
.block_context
540540
.starknet_os_config
541-
.chain_id
542-
.to_felt());
541+
.chain_id);
543542

544543
assert_matches!(
545544
get_big_int(&vm, relocatable!(4, 7)),

src/testing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ lazy_static! {
6464
pub fn new_starknet_block_context_for_testing() -> BlockContext {
6565
BlockContext::new(
6666
StarknetOsConfig::new(
67-
StarknetChainId::TestNet,
67+
StarknetChainId::TestNet.to_felt(),
6868
TEST_ERC20_CONTRACT_ADDRESS.clone(),
6969
1,
7070
),

src/testing/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl StarknetState {
180180
hash_value: Option<Felt252>,
181181
remaining_gas: u128,
182182
) -> Result<(Address, TransactionExecutionInfo), StarknetStateError> {
183-
let chain_id = self.block_context.starknet_os_config.chain_id.to_felt();
183+
let chain_id = self.block_context.starknet_os_config.chain_id.clone();
184184
let deploy = match hash_value {
185185
None => Deploy::new(
186186
contract_address_salt,
@@ -266,7 +266,7 @@ impl StarknetState {
266266
// ------------------------
267267

268268
fn chain_id(&self) -> Felt252 {
269-
self.block_context.starknet_os_config.chain_id.to_felt()
269+
self.block_context.starknet_os_config.chain_id.clone()
270270
}
271271

272272
#[allow(clippy::too_many_arguments)]

tests/internals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ lazy_static! {
102102
pub fn new_starknet_block_context_for_testing() -> BlockContext {
103103
BlockContext::new(
104104
StarknetOsConfig::new(
105-
StarknetChainId::TestNet,
105+
StarknetChainId::TestNet.to_felt(),
106106
TEST_ERC20_CONTRACT_ADDRESS.clone(),
107107
*GAS_PRICE,
108108
),

0 commit comments

Comments
 (0)