nimbus-eth1/premix/prestate.nim

34 lines
990 B
Nim
Raw Normal View History

2019-01-09 08:46:19 +00:00
import
2019-02-05 19:15:50 +00:00
json, downloader, stint, eth/trie/db, byteutils,
../nimbus/db/[db_chain, storage_types], eth/[rlp, common],
2019-01-09 08:46:19 +00:00
../nimbus/p2p/chain, ../nimbus/tracer
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)
chainDB.setHead(parent, true)
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())