Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
implemented mp-chain-id crate
Browse files Browse the repository at this point in the history
  • Loading branch information
antiyro committed Sep 28, 2023
1 parent 3caab47 commit 57c9b7c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"crates/primitives/sequencer-address",
"crates/primitives/storage",
"crates/primitives/commitments",
"crates/primitives/chain-id",
"crates/client/block-proposer",
"crates/client/db",
"crates/client/rpc-core",
Expand Down Expand Up @@ -130,6 +131,7 @@ mp-state = { path = "crates/primitives/state", default-features = false }
mp-storage = { path = "crates/primitives/storage", default-features = false }
mp-transactions = { path = "crates/primitives/transactions", default-features = false }
mp-commitments = { path = "crates/primitives/commitments", default-features = false }
mp-chain-id = { path = "crates/primitives/chain-id", default-features = false }

# Madara client
mc-mapping-sync = { path = "crates/client/mapping-sync" }
Expand Down
1 change: 1 addition & 0 deletions crates/pallets/starknet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mp-sequencer-address = { workspace = true, features = ["parity-scale-codec"] }
mp-state = { workspace = true }
mp-storage = { workspace = true, features = ["parity-scale-codec"] }
mp-transactions = { workspace = true, features = ["scale-info"] }
mp-chain-id = { workspace = true }

blockifier = { workspace = true, features = [
"testing",
Expand Down
10 changes: 1 addition & 9 deletions crates/pallets/starknet/src/tests/mock/setup_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ use mp_felt::Felt252Wrapper;
use crate::genesis_loader::GenesisLoader;
use crate::{Config, GenesisConfig};

/// ChainId for Starknet Goerli testnet
pub const SN_GOERLI_CHAIN_ID: Felt252Wrapper = Felt252Wrapper(starknet_ff::FieldElement::from_mont([
3753493103916128178,
18446744073709548950,
18446744073709551615,
398700013197595345,
]));

// Configure a mock runtime to test the pallet.
macro_rules! mock_runtime {
($mock_runtime:ident, $disable_transaction_fee:expr, $disable_nonce_validation: expr) => {
Expand Down Expand Up @@ -87,7 +79,7 @@ macro_rules! mock_runtime {
pub const DisableTransactionFee: bool = $disable_transaction_fee;
pub const DisableNonceValidation: bool = $disable_nonce_validation;
pub const ProtocolVersion: u8 = 0;
pub const ChainId: Felt252Wrapper = crate::tests::mock::SN_GOERLI_CHAIN_ID;
pub const ChainId: Felt252Wrapper = mp_chain_id::SN_GOERLI_CHAIN_ID;
pub const MaxRecursionDepth: u32 = 50;
}

Expand Down
22 changes: 22 additions & 0 deletions crates/primitives/chain-id/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "mp-chain-id"
version.workspace = true
edition.workspace = true
license = "MIT"
description = "Primitives for Madara digest logs"
authors = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]

# Madara Primitives
mp-felt = { workspace = true }
mp-hashers = { workspace = true }
mp-transactions = { workspace = true }
# Starknet dependencies
blockifier = { workspace = true }
starknet-ff = { workspace = true }
starknet_api = { workspace = true }
20 changes: 20 additions & 0 deletions crates/primitives/chain-id/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Traits for chain ids.
#![cfg_attr(not(feature = "std"), no_std)]

use mp_felt::Felt252Wrapper;

/// ChainId for Starknet Goerli testnet
pub const SN_GOERLI_CHAIN_ID: Felt252Wrapper = Felt252Wrapper(starknet_ff::FieldElement::from_mont([
3753493103916128178,
18446744073709548950,
18446744073709551615,
398700013197595345,
]));

/// ChainId for Starknet Mainnet
pub const SN_MAIN_CHAIN_ID: Felt252Wrapper = Felt252Wrapper(starknet_ff::FieldElement::from_mont([
17696389056366564951,
18446744073709551615,
18446744073709551615,
502562008147966918,
]));
1 change: 1 addition & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pallet-starknet = { workspace = true }
mp-felt = { workspace = true }
mp-hashers = { workspace = true }
mp-transactions = { workspace = true }
mp-chain-id = { workspace = true }
# Starknet dependencies
blockifier = { workspace = true }
starknet-ff = { workspace = true }
Expand Down
17 changes: 1 addition & 16 deletions crates/runtime/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use frame_support::weights::constants::{
pub use frame_support::weights::{IdentityFee, Weight};
pub use frame_support::{construct_runtime, parameter_types, StorageValue};
pub use frame_system::Call as SystemCall;
pub use mp_chain_id::SN_GOERLI_CHAIN_ID;
/// Import the StarkNet pallet.
pub use pallet_starknet;
pub use pallet_timestamp::Call as TimestampCall;
Expand All @@ -23,22 +24,6 @@ use sp_std::marker::PhantomData;

use crate::*;

/// ChainId for Starknet Goerli testnet
pub const SN_GOERLI_CHAIN_ID: Felt252Wrapper = Felt252Wrapper(starknet_ff::FieldElement::from_mont([
3753493103916128178,
18446744073709548950,
18446744073709551615,
398700013197595345,
]));

/// ChainId for Starknet Mainnet
pub const SN_MAIN_CHAIN_ID: Felt252Wrapper = Felt252Wrapper(starknet_ff::FieldElement::from_mont([
17696389056366564951,
18446744073709551615,
18446744073709551615,
502562008147966918,
]));

// Configure FRAME pallets to include in runtime.

// --------------------------------------
Expand Down

0 comments on commit 57c9b7c

Please sign in to comment.