fixes customNetPrealloc in genesis.nim: dealing with missing keys in genesis.json

This commit is contained in:
jangko 2021-03-31 13:11:09 +07:00
parent 2befeceeac
commit fb7d5b5319
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 12 additions and 4 deletions

View File

@ -35,14 +35,22 @@ func decodePrealloc(data: seq[byte]): GenesisAlloc =
proc customNetPrealloc(genesisBlock: JsonNode): GenesisAlloc = proc customNetPrealloc(genesisBlock: JsonNode): GenesisAlloc =
result = newTable[EthAddress, GenesisAccount]() result = newTable[EthAddress, GenesisAccount]()
for address, account in genesisBlock.pairs(): for address, account in genesisBlock.pairs():
let nonce = if "nonce" in account:
parseHexInt(account["nonce"].getStr).AccountNonce
else:
AccountNonce(0)
var acc = GenesisAccount( var acc = GenesisAccount(
balance: fromHex(UInt256, account["balance"].getStr), balance: fromHex(UInt256, account["balance"].getStr),
code: hexToSeqByte(account["code"].getStr), code: hexToSeqByte(account["code"].getStr),
nonce: parseHexInt(account["nonce"].getStr).AccountNonce nonce: nonce
) )
let storage = account["storage"]
for k, v in storage: if "storage" in account:
acc.storage[fromHex(UInt256, k)] = fromHex(UInt256, v.getStr) let storage = account["storage"]
for k, v in storage:
acc.storage[fromHex(UInt256, k)] = fromHex(UInt256, v.getStr)
result[parseAddress(address)] = acc result[parseAddress(address)] = acc
proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis = proc defaultGenesisBlockForNetwork*(id: PublicNetwork): Genesis =