add premix and browser launcher code
This commit is contained in:
parent
2b66716d9c
commit
e104153379
|
@ -0,0 +1,40 @@
|
|||
import os, osproc, json
|
||||
|
||||
when defined(windows):
|
||||
const
|
||||
premixExecutable = "premix.exe"
|
||||
browserLauncher = "cmd /c start"
|
||||
elif defined(macos):
|
||||
const
|
||||
premixExecutable = "premix"
|
||||
browserLauncher = "open"
|
||||
else:
|
||||
const
|
||||
premixExecutable = "premix"
|
||||
browserLauncher = "xdg-open"
|
||||
|
||||
proc getPremixDir(): (bool, string) =
|
||||
var premixDir = [
|
||||
"." ,
|
||||
".." & DirSep & "premix"
|
||||
]
|
||||
|
||||
for c in premixDir:
|
||||
if fileExists(c & DirSep & premixExecutable):
|
||||
return (true, c)
|
||||
|
||||
result = (false, ".")
|
||||
|
||||
proc launchPremix*(fileName: string, metaData: JsonNode) =
|
||||
let
|
||||
(premixAvailable, premixDir) = getPremixDir()
|
||||
premixExe = premixDir & DirSep & premixExecutable
|
||||
|
||||
writeFile(premixDir & DirSep & fileName, metaData.pretty)
|
||||
|
||||
if premixAvailable:
|
||||
if execCmd(premixExe & " " & premixDir & DirSep & fileName) == 0:
|
||||
if execCmd(browserLauncher & " " & premixDir & DirSep & "index.html") != 0:
|
||||
echo "failed to launch default browser"
|
||||
else:
|
||||
echo "failed to execute premix debugging tool"
|
|
@ -2,7 +2,7 @@ import
|
|||
db/[db_chain, state_db, capturedb], eth_common, utils, json,
|
||||
constants, vm_state, vm_types, transaction, p2p/executor,
|
||||
eth_trie/db, nimcrypto, strutils, ranges, ./utils/addresses,
|
||||
chronicles, rpc/hexstrings
|
||||
chronicles, rpc/hexstrings, launcher
|
||||
|
||||
proc getParentHeader(self: BaseChainDB, header: BlockHeader): BlockHeader =
|
||||
self.getBlockHeader(header.parentHash)
|
||||
|
@ -230,7 +230,8 @@ proc traceTransactions*(chainDB: BaseChainDB, header: BlockHeader, blockBody: Bl
|
|||
for i in 0 ..< blockBody.transactions.len:
|
||||
result.add traceTransaction(chainDB, header, blockBody, i, {DisableState})
|
||||
|
||||
proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, blockBody: BlockBody, receipts: seq[Receipt]) =
|
||||
proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader,
|
||||
blockBody: BlockBody, receipts: seq[Receipt], launchDebugger = true) =
|
||||
let
|
||||
blockNumber = header.blockNumber
|
||||
|
||||
|
@ -249,5 +250,9 @@ proc dumpDebuggingMetaData*(chainDB: BaseChainDB, header: BlockHeader, blockBody
|
|||
}
|
||||
|
||||
metaData.dumpMemoryDB(memoryDB)
|
||||
# this is a placeholder until premix debugging tool is ready
|
||||
writeFile("debug" & $blockNumber & ".json", metaData.pretty())
|
||||
|
||||
let jsonFileName = "debug" & $blockNumber & ".json"
|
||||
if launchDebugger:
|
||||
launchPremix(jsonFileName, metaData)
|
||||
else:
|
||||
writeFile(jsonFileName, metaData.pretty())
|
||||
|
|
|
@ -26,7 +26,7 @@ proc dumpDebug(chainDB: BaseChainDB, blockNumber: Uint256) =
|
|||
|
||||
captureChainDB.setHead(parent, true)
|
||||
let validationResult = processBlock(captureChainDB, parent, header, body, vmState)
|
||||
dumpDebuggingMetaData(captureChainDB, header, body, vmState.receipts)
|
||||
dumpDebuggingMetaData(captureChainDB, header, body, vmState.receipts, false)
|
||||
|
||||
proc main() =
|
||||
let conf = getConfiguration()
|
||||
|
|
Loading…
Reference in New Issue