diff --git a/substrate/executor/src/wasm_executor.rs b/substrate/executor/src/wasm_executor.rs index 41029424fa..580da80772 100644 --- a/substrate/executor/src/wasm_executor.rs +++ b/substrate/executor/src/wasm_executor.rs @@ -137,7 +137,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, } else { 0 } }, ext_chain_id() -> u64 => { - 42u64 + this.ext.chain_id() } => <'e, E: Externalities + 'e> ); diff --git a/substrate/native-runtime/support/src/lib.rs b/substrate/native-runtime/support/src/lib.rs index 9ec5f77bdd..498081cd33 100644 --- a/substrate/native-runtime/support/src/lib.rs +++ b/substrate/native-runtime/support/src/lib.rs @@ -70,8 +70,9 @@ pub fn set_storage(_key: &[u8], _value: &[u8]) { /// The current relay chain identifier. pub fn chain_id() -> u64 { - // TODO: fetch from Externalities. - 42u64 + ext::with(|holder| + holder.ext.chain_id() + ).unwrap_or(0) } /// Execute the given closure with global function available whose functionality routes into the @@ -105,6 +106,8 @@ mod tests { fn set_storage(&mut self, key: Vec, value: Vec) { self.storage.insert(key, value); } + + fn chain_id(&self) -> u64 { 42 } } macro_rules! map { diff --git a/substrate/state_machine/src/ext.rs b/substrate/state_machine/src/ext.rs index ce7b9a0268..1452558ccd 100644 --- a/substrate/state_machine/src/ext.rs +++ b/substrate/state_machine/src/ext.rs @@ -73,4 +73,8 @@ impl<'a, B: 'a> Externalities for Ext<'a, B> fn set_storage(&mut self, key: Vec, value: Vec) { self.overlay.set_storage(key, value); } + + fn chain_id(&self) -> u64 { + 42 + } } diff --git a/substrate/state_machine/src/lib.rs b/substrate/state_machine/src/lib.rs index 38c481113f..3ff3b69469 100644 --- a/substrate/state_machine/src/lib.rs +++ b/substrate/state_machine/src/lib.rs @@ -130,7 +130,10 @@ pub trait Externalities { /// Set storage of current contract being called (effective immediately). fn set_storage(&mut self, key: Vec, value: Vec); - /// Get the current set of authorities. + /// Get the identity of the chain. + fn chain_id(&self) -> u64 { 42 } // TODO: remove implementation and fix resulting errors. + + /// Get the current set of authorities from storage. fn authorities(&self) -> Result, Self::Error> { (0..self.storage(b"con\0aut\0len")?.into_iter() .rev()