-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (47 loc) · 1.72 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
53
54
55
56
57
58
59
60
import argparse
from itertools import zip_longest
from environs import Env
from hexbytes import HexBytes
env = Env()
env.read_env()
# Importing these after loading .env so it picks up the right settings
from eth_permissions.graph import build_graph # noqa: E402
from eth_permissions.roles import Component, Role, get_registry # noqa: E402
KNOWN_ROLES = env.list("KNOWN_ROLES", ["GUARDIAN_ROLE", "LEVEL1_ROLE", "LEVEL2_ROLE", "LEVEL3_ROLE"])
KNOWN_COMPONENTS = env.list("KNOWN_COMPONENTS", [])
KNOWN_COMPONENT_NAMES = env.list("KNOWN_COMPONENT_NAMES", [])
parser = argparse.ArgumentParser(
prog="eth-permissions", description="Command line tool for auditing smart contract permissions"
)
parser.add_argument("-o", "--output", required=True, help="Output file")
parser.add_argument(
"-f",
"--format",
required=False,
default=None,
help="Output format. If ommitted it will be determined from the output file name extension",
)
parser.add_argument(
"-v",
"--view",
action="store_true",
required=False,
help="If specified, the rendered file image will be opened with the default viewer.",
)
parser.add_argument("address", help="The contract's address")
def load_registry():
get_registry().add_roles([Role(name) for name in KNOWN_ROLES])
get_registry().add_components(
[
Component(HexBytes(address), name)
for address, name in zip_longest(KNOWN_COMPONENTS, KNOWN_COMPONENT_NAMES)
]
)
def main():
args = parser.parse_args()
load_registry()
graph = build_graph("IAccessControl", args.address)
kwargs = {}
if args.format:
kwargs["format"] = args.format
graph.render(outfile=args.output, cleanup=True, view=args.view, **kwargs)