forked from ethereum/execution-specs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
52 lines (40 loc) · 1.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# flake8: noqa
import argparse
import json
from . import spec, trie
from .eth_types import Address, Uint
def main() -> None:
parser = argparse.ArgumentParser(description="Run a state transition.")
parser.add_argument("--input.alloc", dest="alloc", action="store")
parser.add_argument("--input.env", dest="env", action="store")
parser.add_argument("--input.txs", dest="txs", action="store")
args = parser.parse_args()
with open(args.alloc) as f:
alloc = json.load(f)
with open(args.env) as f:
env = json.load(f)
state = {}
for (addr, vals) in alloc.items():
account = spec.Account(
nonce=vals.get("nonce", Uint(0)),
balance=Uint(int(vals.get("balance", Uint(0)))),
code=bytes.fromhex(vals.get("code", "")),
storage={}, # TODO: support storage
)
addr = bytes.fromhex(addr)
state[addr] = account
gas_used, receipts, state = spec.apply_body(
state,
Address(bytes.fromhex(env["currentCoinbase"][2:])),
Uint(int(env["currentNumber"], 16)),
Uint(int(env["currentGasLimit"], 16)),
Uint(int(env["currentTimestamp"], 16)),
Uint(int(env["currentDifficulty"], 16)),
[],
[],
)
print(gas_used)
print(receipts.hex())
print(trie.TRIE(trie.y(state)).hex())
if __name__ == "__main__":
main()