Add chain RPCs and getHeader. (#124)

* Add chain RPCs and getHeader.

Also:
- finish renaming transaction -> extrinsic;
- rejig development chain spec to be more useful.

* Fix.

* Remove invalid comments.

* Fix.
This commit is contained in:
Gav Wood
2018-04-13 14:21:32 +02:00
committed by Tomasz Drwięga
parent e9cdd45145
commit 808d762158
12 changed files with 79 additions and 60 deletions
@@ -55,7 +55,7 @@ impl<B, E> BlockBuilder<B, E> where
number: client.block_number_from_id(block_id)?.ok_or(error::ErrorKind::UnknownBlock(*block_id))? + 1,
parent_hash: client.block_hash_from_id(block_id)?.ok_or(error::ErrorKind::UnknownBlock(*block_id))?,
state_root: Default::default(),
transaction_root: Default::default(),
extrinsics_root: Default::default(),
digest: Default::default(),
},
transactions: Default::default(),
@@ -78,7 +78,7 @@ impl<B, E> BlockBuilder<B, E> where
/// Consume the builder to return a valid `Block` containing all pushed transactions.
pub fn bake(mut self) -> error::Result<Block> {
self.header.transaction_root = ordered_trie_root(self.transactions.iter().map(Slicable::encode)).0.into();
self.header.extrinsics_root = ordered_trie_root(self.transactions.iter().map(Slicable::encode)).0.into();
let output = state_machine::execute(&self.state, &mut self.changes, &self.executor, "finalise_block",
&self.header.encode())?;
self.header = Header::decode(&mut &output[..]).expect("Header came straight out of runtime so must be valid");
+3 -3
View File
@@ -27,7 +27,7 @@ pub fn construct_genesis_block(storage: &HashMap<Vec<u8>, Vec<u8>>) -> Block {
parent_hash: Default::default(),
number: 0,
state_root,
transaction_root: trie_root(vec![].into_iter()).0.into(),
extrinsics_root: trie_root(vec![].into_iter()).0.into(),
digest: Default::default(),
};
Block {
@@ -62,13 +62,13 @@ mod tests {
UncheckedTransaction { tx, signature }
}).collect::<Vec<_>>();
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::encode)).0.into();
let extrinsics_root = ordered_trie_root(transactions.iter().map(Slicable::encode)).0.into();
let mut header = Header {
parent_hash,
number,
state_root,
transaction_root,
extrinsics_root,
digest: Digest { logs: vec![], },
};
let hash = header.blake2_256();