Allow contract constructors in chain spec (#3932)

* constructor spec

* execute under wrong address

* create under correct address

* revert

* move genesis block lookup

* remove env_logger
This commit is contained in:
keorn
2016-12-23 18:44:39 +01:00
committed by Gav Wood
parent 5a3c3bcb45
commit afc4cd2785
14 changed files with 161 additions and 78 deletions

View File

@@ -32,8 +32,10 @@ pub struct Account {
pub nonce: Option<Uint>,
/// Code.
pub code: Option<Bytes>,
/// Storage
/// Storage.
pub storage: Option<BTreeMap<Uint, Uint>>,
/// Constructor.
pub constructor: Option<Bytes>,
}
impl Account {

View File

@@ -18,6 +18,7 @@
use std::collections::BTreeMap;
use hash::Address;
use bytes::Bytes;
use spec::{Account, Builtin};
/// Blockchain test state deserializer.
@@ -29,7 +30,15 @@ impl State {
pub fn builtins(&self) -> BTreeMap<Address, Builtin> {
self.0
.iter()
.filter_map(|ref pair| pair.1.builtin.clone().map(|b| (pair.0.clone(), b.clone())))
.filter_map(|(add, ref acc)| acc.builtin.clone().map(|b| (add.clone(), b)))
.collect()
}
/// Returns all constructors.
pub fn constructors(&self) -> BTreeMap<Address, Bytes> {
self.0
.iter()
.filter_map(|(add, ref acc)| acc.constructor.clone().map(|b| (add.clone(), b)))
.collect()
}
}