Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Aug 4, 2022
1 parent eaa1ddf commit 5287b0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions slither/tools/read_storage/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parse_args() -> argparse.Namespace:
+ "To retrieve a contract's storage layout:\n"
+ "\tslither-read-storage $TARGET address --contract-name $NAME --layout\n"
+ "To retrieve a contract's storage layout and values:\n"
+ "\tslither-read-storage $TARGET address --contract-name $NAME --layout --values\n"
+ "\tslither-read-storage $TARGET address --contract-name $NAME --layout --value\n"
+ "TARGET can be a contract address or project directory"
),
)
Expand Down Expand Up @@ -73,9 +73,9 @@ def parse_args() -> argparse.Namespace:
)

parser.add_argument(
"--layout",
action="store_true",
help="Toggle used to write a JSON file with the entire storage layout.",
"--json",
action="store",
help="Save the result in a JSON file.",
)

parser.add_argument(
Expand Down Expand Up @@ -132,15 +132,14 @@ def main() -> None:

srs.rpc = args.rpc_url

if args.layout:
srs.get_all_storage_variables()
srs.get_storage_layout()
else:
assert args.variable_name
if args.variable_name:
# Use a lambda func to only return variables that have same name as target.
# x is a tuple (`Contract`, `StateVariable`).
srs.get_all_storage_variables(lambda x: bool(x[1].name == args.variable_name))
srs.get_target_variables(**vars(args))
else:
srs.get_all_storage_variables()
srs.get_storage_layout()

# To retrieve slot values an rpc url is required.
if args.value:
Expand All @@ -150,9 +149,9 @@ def main() -> None:
if args.table:
srs.walk_slot_info(srs.convert_slot_info_to_rows)
print(srs.table)
# Only write file if storage layout is used. TODO add flag for file
elif len(srs.slot_info) > 1:
with open("storage_layout.json", "w", encoding="utf-8") as file:

if args.json:
with open(args.json, "w", encoding="utf-8") as file:
slot_infos_json = srs.to_json()
json.dump(slot_infos_json, file, indent=4)

Expand Down
2 changes: 1 addition & 1 deletion slither/tools/read_storage/read_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def slot_info(self) -> Dict[str, SlotInfo]:

def get_storage_layout(self) -> None:
"""Retrieves the storage layout of entire contract."""
tmp = {}
tmp: Dict[str, SlotInfo] = {}
for contract, var in self.target_variables:
type_ = var.type
info = self.get_storage_slot(var, contract)
Expand Down

0 comments on commit 5287b0a

Please sign in to comment.