From 630795b10eda0a2367f16aad0cacee21ef59ee73 Mon Sep 17 00:00:00 2001 From: jouzo Date: Wed, 14 Jun 2023 12:35:11 +0200 Subject: [PATCH] Make genesis.json field optional --- lib/ain-evm/src/block.rs | 16 ++++++++-------- lib/ain-evm/src/genesis.rs | 16 +++++++++------- lib/ain-evm/src/trie.rs | 36 +++++++++++++++++++----------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index 1055a8b9855..c6009e527db 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -272,18 +272,18 @@ pub fn new_block_from_json(path: PathBuf, state_root: H256) -> Result, - pub gas_limit: U256, - pub nonce: H64, - pub timestamp: u64, - pub alloc: HashMap, + pub coinbase: Option, + pub difficulty: Option, + pub extra_data: Option>, + pub gas_limit: Option, + pub nonce: Option, + pub timestamp: Option, + pub alloc: Option>, + pub parent_hash: Option, + pub mix_hash: Option, } diff --git a/lib/ain-evm/src/trie.rs b/lib/ain-evm/src/trie.rs index 3a78a56a5ea..527154ecbf0 100644 --- a/lib/ain-evm/src/trie.rs +++ b/lib/ain-evm/src/trie.rs @@ -71,24 +71,26 @@ impl TrieDBStore { let reader = BufReader::new(file); let genesis: GenesisData = serde_json::from_reader(reader)?; - for (address, data) in genesis.alloc { - debug!("Setting data {:#?} for address {:x?}", data, address); - let basic = backend.basic(address); + if let Some(alloc) = genesis.alloc { + for (address, data) in alloc { + debug!("Setting data {:#?} for address {:x?}", data, address); + let basic = backend.basic(address); - let new_basic = Basic { - balance: data.balance, - ..basic - }; - backend - .apply( - address, - new_basic, - data.code, - data.storage.unwrap_or_default(), - false, - ) - .expect("Could not set account data"); - backend.commit(); + let new_basic = Basic { + balance: data.balance, + ..basic + }; + backend + .apply( + address, + new_basic, + data.code, + data.storage.unwrap_or_default(), + false, + ) + .expect("Could not set account data"); + backend.commit(); + } } let state_root = backend.commit();