Skip to content

Commit

Permalink
Clean the code + add slot offset + left-aligned text
Browse files Browse the repository at this point in the history
  • Loading branch information
nisedo committed Feb 21, 2025
1 parent 02778e2 commit 394436b
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions slither/printers/summary/storage_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,33 @@ def output(self, _filename) -> Output:
),
key=lambda x: x.name,
):
storage_vars = [
v for v in contract.state_variables if not (v.is_constant or v.is_immutable)
]
storage_vars = contract.storage_variables_ordered

if not storage_vars:
continue

table = MyPrettyTable(["Variable", "Type", "Visibility", "Slot", "Inherited From"])
table = MyPrettyTable(
["Variable", "Type", "Visibility", "Slot", "Offset", "Inherited From"]
)
for field in table._field_names:

Check warning on line 42 in slither/printers/summary/storage_variables.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

W0212: Access to a protected member _field_names of a client class (protected-access)
table._options["set_alignment"] += [(field, "l")]

Check warning on line 43 in slither/printers/summary/storage_variables.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

W0212: Access to a protected member _options of a client class (protected-access)

contract_info = [
f"\nContract {Colors.BOLD}{Colors.YELLOW}{contract.name}{Colors.END}"
f" ({contract.source_mapping})"
]

storage_vars = sorted(
storage_vars,
key=lambda x, contract=contract: contract.compilation_unit.storage_layout_of(
contract, x
)[0],
)

for v in storage_vars:
slot = contract.compilation_unit.storage_layout_of(contract, v)[0]
slot, offset = contract.compilation_unit.storage_layout_of(contract, v)
inherited = v.contract.name if v.contract != contract else ""
table.add_row(
[
f"{Colors.BOLD}{Colors.RED}{v.name}{Colors.END}",
f"{Colors.GREEN}{str(v.type)}{Colors.END}",
f"{Colors.GREEN}{v.type}{Colors.END}",
f"{Colors.BLUE}{v.visibility}{Colors.END}",
str(slot),
f"{Colors.MAGENTA}{inherited}{Colors.END}" if inherited else "",
slot,
offset,
f"{Colors.MAGENTA}{inherited}{Colors.END}",
]
)

Expand Down

0 comments on commit 394436b

Please sign in to comment.