mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Genesis creation utilities.
This commit is contained in:
@@ -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![],
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
extern crate polkadot_primitives as primitives;
|
||||
extern crate polkadot_state_machine as state_machine;
|
||||
extern crate polkadot_serializer as ser;
|
||||
extern crate native_runtime;
|
||||
|
||||
extern crate triehash;
|
||||
extern crate parking_lot;
|
||||
#[macro_use] extern crate error_chain;
|
||||
#[macro_use] extern crate log;
|
||||
@@ -31,6 +33,10 @@ pub mod blockchain;
|
||||
pub mod backend;
|
||||
pub mod in_mem;
|
||||
|
||||
mod genesis;
|
||||
|
||||
pub use genesis::construct_genesis_block;
|
||||
|
||||
pub use blockchain::Info as ChainInfo;
|
||||
pub use blockchain::BlockId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user