nimbus-eth1/premix/prestate.nim

34 lines
978 B
Nim
Raw Normal View History

2019-01-09 08:46:19 +00:00
import
2020-07-21 06:15:06 +00:00
json, stint, eth/trie/db, stew/byteutils,
2019-02-05 19:15:50 +00:00
../nimbus/db/[db_chain, storage_types], eth/[rlp, common],
2020-07-21 06:15:06 +00:00
../nimbus/tracer
2019-01-09 08:46:19 +00:00
2022-04-08 04:54:11 +00:00
proc generatePrestate*(nimbus, geth: JsonNode, blockNumber: UInt256, parent, header: BlockHeader, body: BlockBody) =
2019-01-09 08:46:19 +00:00
let
state = nimbus["state"]
headerHash = rlpHash(header)
2019-01-09 08:46:19 +00:00
var
memoryDB = newMemoryDB()
chainDB = newBaseChainDB(memoryDB, false)
2022-07-04 05:35:56 +00:00
discard chainDB.setHead(parent, true)
2020-07-29 05:42:32 +00:00
discard chainDB.persistTransactions(blockNumber, body.transactions)
discard chainDB.persistUncles(body.uncles)
2019-01-09 08:46:19 +00:00
memoryDB.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
chainDB.addBlockNumberToHashLookup(header)
2019-01-09 08:46:19 +00:00
for k, v in state:
let key = hexToSeqByte(k)
let value = hexToSeqByte(v.getStr())
memoryDB.put(key, value)
var metaData = %{
"blockNumber": %blockNumber.toHex,
"geth": geth
2019-01-09 08:46:19 +00:00
}
metaData.dumpMemoryDB(memoryDB)
writeFile("block" & $blockNumber & ".json", metaData.pretty())