2019-01-09 08:46:19 +00:00
|
|
|
import
|
2023-08-04 11:10:09 +00:00
|
|
|
json, stint, stew/byteutils,
|
|
|
|
../nimbus/db/[core_db, 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
|
2019-01-14 11:49:18 +00:00
|
|
|
state = nimbus["state"]
|
|
|
|
headerHash = rlpHash(header)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
|
|
|
var
|
2023-08-04 11:10:09 +00:00
|
|
|
chainDB = newCoreDbRef(LegacyDbMemory)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
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)
|
2019-01-14 11:49:18 +00:00
|
|
|
discard chainDB.persistUncles(body.uncles)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
chainDB.kvt.put(genericHashKey(headerHash).toOpenArray, rlp.encode(header))
|
2019-01-14 11:49:18 +00:00
|
|
|
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())
|
2023-08-04 11:10:09 +00:00
|
|
|
chainDB.kvt.put(key, value)
|
2019-01-09 08:46:19 +00:00
|
|
|
|
|
|
|
var metaData = %{
|
2019-01-14 11:49:18 +00:00
|
|
|
"blockNumber": %blockNumber.toHex,
|
|
|
|
"geth": geth
|
2019-01-09 08:46:19 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 11:10:09 +00:00
|
|
|
metaData.dumpMemoryDB(chainDB)
|
2019-01-09 08:46:19 +00:00
|
|
|
writeFile("block" & $blockNumber & ".json", metaData.pretty())
|