initial merge

This commit is contained in:
Robert Habermeier
2018-02-06 14:12:54 +01:00
21 changed files with 839 additions and 191 deletions
+14 -8
View File
@@ -34,13 +34,14 @@ extern crate byteorder;
use std::collections::HashMap;
use std::fmt;
use primitives::contract::{CallData};
use primitives::contract::CallData;
pub mod backend;
mod ext;
mod testing;
pub use testing::TestExternalities;
pub use ext::Ext;
/// Updates to be committed to the state.
pub enum Update {
@@ -152,12 +153,17 @@ pub trait Externalities {
/// Get the current set of authorities from storage.
fn authorities(&self) -> Result<Vec<&[u8]>, ExternalitiesError> {
(0..self.storage(b"con:aut:len")?.into_iter()
(0..self.storage(b":auth:len")?.into_iter()
.rev()
.fold(0, |acc, &i| (acc << 8) + (i as u32)))
.map(|i| self.storage(&to_keyed_vec(i, b"con:aut:".to_vec())))
.map(|i| self.storage(&to_keyed_vec(i, b":auth:".to_vec())))
.collect()
}
/// Get the runtime code.
fn code(&self) -> Result<&[u8], ExternalitiesError> {
self.storage(b":code")
}
}
/// Code execution engine.
@@ -254,17 +260,17 @@ mod tests {
assert_eq!(ext.authorities(), Ok(vec![]));
ext.set_storage(b"con:aut:len".to_vec(), vec![0u8; 4]);
ext.set_storage(b":auth:len".to_vec(), vec![0u8; 4]);
assert_eq!(ext.authorities(), Ok(vec![]));
ext.set_storage(b"con:aut:len".to_vec(), vec![1u8, 0, 0, 0]);
ext.set_storage(b":auth:len".to_vec(), vec![1u8, 0, 0, 0]);
assert_eq!(ext.authorities(), Ok(vec![&[][..]]));
ext.set_storage(b"con:aut:\0\0\0\0".to_vec(), b"first".to_vec());
ext.set_storage(b":auth:\0\0\0\0".to_vec(), b"first".to_vec());
assert_eq!(ext.authorities(), Ok(vec![&b"first"[..]]));
ext.set_storage(b"con:aut:len".to_vec(), vec![2u8, 0, 0, 0]);
ext.set_storage(b"con:aut:\x01\0\0\0".to_vec(), b"second".to_vec());
ext.set_storage(b":auth:len".to_vec(), vec![2u8, 0, 0, 0]);
ext.set_storage(b":auth:\x01\0\0\0".to_vec(), b"second".to_vec());
assert_eq!(ext.authorities(), Ok(vec![&b"first"[..], &b"second"[..]]));
}