Created
January 22, 2021 17:37
-
-
Save lightclient/cadbbb7ee72b5276f240512f94665e50 to your computer and use it in GitHub Desktop.
Trace runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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