use externalities for chain_id

This commit is contained in:
Gav
2018-01-16 19:04:13 +01:00
parent dc6ebf71cf
commit 74d5be0e80
4 changed files with 14 additions and 4 deletions
+1 -1
View File
@@ -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>
);
+5 -2
View File
@@ -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<u8>, value: Vec<u8>) {
self.storage.insert(key, value);
}
fn chain_id(&self) -> u64 { 42 }
}
macro_rules! map {
+4
View File
@@ -73,4 +73,8 @@ impl<'a, B: 'a> Externalities for Ext<'a, B>
fn set_storage(&mut self, key: Vec<u8>, value: Vec<u8>) {
self.overlay.set_storage(key, value);
}
fn chain_id(&self) -> u64 {
42
}
}
+4 -1
View File
@@ -130,7 +130,10 @@ pub trait Externalities {
/// Set storage of current contract being called (effective immediately).
fn set_storage(&mut self, key: Vec<u8>, value: Vec<u8>);
/// 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<Vec<&[u8]>, Self::Error> {
(0..self.storage(b"con\0aut\0len")?.into_iter()
.rev()