Skip to content

Instantly share code, notes, and snippets.

@lightclient
Created January 22, 2021 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightclient/cadbbb7ee72b5276f240512f94665e50 to your computer and use it in GitHub Desktop.
Save lightclient/cadbbb7ee72b5276f240512f94665e50 to your computer and use it in GitHub Desktop.
Trace runner
import json
import requests
import sys
headers = {
'Content-Type': 'application/json',
}
tracer = '{hist: {DIFFICULTY: {}, BLOCKHASH: {}, CALLCODE: {}}, found: false, fault: function(log) {}, step: function(log) {
var op = log.op.toString(); var addr = toHex(log.contract.getAddress()); if(op == "DIFFICULTY" || op == "BLOCKHASH" || op ==
"CALLCODE") { if(this.hist[op][addr]) { this.hist[op][addr]++; } else { this.hist[op][addr] = 1; } this.found = true;}}, resu
lt: function() { if (this.found) { return this.hist; } else { return "" }}}'
def data(i):
return '{"id": 1, "method": "debug_traceBlockByNumber", "params": ["%s", {"tracer": "%s"}]}' % (hex(i), tracer.replace('"
', '\\"'))
f = open(f"out.txt", "x")
f.write("[")
start = 11706600
end = 11706612
for i in range(start, end):
response = requests.post("http://localhost:8545", headers=headers, data=data(i))
if "result" not in response.json():
print(f"unexpected response at block {i}: {response.text}")
sys.exit(1)
results = response.json()["result"]
out = []
for result in results:
if ("result" in result and result["result"] != "") or "error" in result:
out.append(result)
if len(out) > 0:
f.write(json.dumps({i: out}))
if i != (end - 1):
f.write(",")
f.write("]")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment