From fb7d5b5319039907ade14951ae6a5d687ea9b792 Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 31 Mar 2021 13:11:09 +0700 Subject: [PATCH] fixes customNetPrealloc in genesis.nim: dealing with missing keys in genesis.json --- nimbus/genesis.nim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nimbus/genesis.nim b/nimbus/genesis.nim index c24338c8f..4f335c015 100644 --- a/nimbus/genesis.nim +++ b/nimbus/genesis.nim @@ -35,14 +35,22 @@ func decodePrealloc(data: seq[byte]): GenesisAlloc = proc customNetPrealloc(genesisBlock: JsonNode): GenesisAlloc = result = newTable[EthAddress, GenesisAccount]() for address, account in genesisBlock.pairs(): + let nonce = if "nonce" in account: + parseHexInt(account["nonce"].getStr).AccountNonce + else: + AccountNonce(0) + var acc = GenesisAccount( balance: fromHex(UInt256, account["balance"].getStr), code: hexToSeqByte(account["code"].getStr), - nonce: parseHexInt(account["nonce"].getStr).AccountNonce + nonce: nonce ) - let storage = account["storage"] - for k, v in storage: - acc.storage[fromHex(UInt256, k)] = fromHex(UInt256, v.getStr) + + if "storage" in account: + let storage = account["storage"] + for k, v in storage: + acc.storage[fromHex(UInt256, k)] = fromHex(UInt256, v.getStr) + result[parseAddress(address)] = acc proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis =