Skip to content

Commit fe6b033

Browse files
committed
pallet-evm: customizable chain id (#6537)
1 parent 7fdd4b5 commit fe6b033

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/backend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use serde::{Serialize, Deserialize};
55
use codec::{Encode, Decode};
66
use sp_core::{U256, H256, H160};
77
use sp_runtime::traits::UniqueSaturatedInto;
8+
use frame_support::traits::Get;
89
use frame_support::storage::{StorageMap, StorageDoubleMap};
910
use sha3::{Keccak256, Digest};
1011
use evm::backend::{Backend as BackendT, ApplyBackend, Apply};
@@ -91,7 +92,7 @@ impl<'vicinity, T: Trait> BackendT for Backend<'vicinity, T> {
9192
}
9293

9394
fn chain_id(&self) -> U256 {
94-
U256::from(sp_io::misc::chain_id())
95+
U256::from(T::ChainId::get())
9596
}
9697

9798
fn exists(&self, _address: H160) -> bool {

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ impl Precompiles for () {
118118
}
119119
}
120120

121+
/// Substrate system chain ID.
122+
pub struct SystemChainId;
123+
124+
impl Get<u64> for SystemChainId {
125+
fn get() -> u64 {
126+
sp_io::misc::chain_id()
127+
}
128+
}
129+
121130
static ISTANBUL_CONFIG: Config = Config::istanbul();
122131

123132
/// EVM module trait
@@ -134,6 +143,8 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait {
134143
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
135144
/// Precompiles associated with this EVM engine.
136145
type Precompiles: Precompiles;
146+
/// Chain ID of EVM.
147+
type ChainId: Get<U256>;
137148

138149
/// EVM config used in the module.
139150
fn config() -> &'static Config {
@@ -159,7 +170,7 @@ decl_storage! {
159170
trait Store for Module<T: Trait> as EVM {
160171
Accounts get(fn accounts): map hasher(blake2_128_concat) H160 => Account;
161172
AccountCodes get(fn account_codes): map hasher(blake2_128_concat) H160 => Vec<u8>;
162-
AccountStorages get(fn account_storages):
173+
AccountStorages get(fn account_storages):
163174
double_map hasher(blake2_128_concat) H160, hasher(blake2_128_concat) H256 => H256;
164175
}
165176

0 commit comments

Comments
 (0)