Genesis creation utilities.

This commit is contained in:
Gav
2018-02-02 22:17:16 +01:00
parent bcb2fd0c10
commit 248f27c976
16 changed files with 201 additions and 100 deletions
+37
View File
@@ -0,0 +1,37 @@
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! Tool for creating the genesis block.
use std::collections::HashMap;
use native_runtime::primitives::{Block, Header};
use triehash::trie_root;
/// Create a genesis block, given the initial storage.
pub fn construct_genesis_block(storage: &HashMap<Vec<u8>, Vec<u8>>) -> Block {
let state_root = trie_root(storage.clone().into_iter()).0;
let header = Header {
parent_hash: Default::default(),
number: 0,
state_root,
transaction_root: trie_root(vec![].into_iter()).0,
digest: Default::default(),
};
Block {
header,
transactions: vec![],
}
}