Skip to content

Commit

Permalink
Only specify encoding if data is a string
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev authored and antazoey committed Jul 24, 2023
1 parent 4a510ab commit df472fc
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/ape/api/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,23 @@ def __repr__(self) -> str:
def __str__(self) -> str:
data = self.dict()
if len(data["data"]) > 9:
data["data"] = (
"0x"
+ bytes(data["data"][:3], encoding="utf8").hex()
+ "..."
+ bytes(data["data"][-3:], encoding="utf8").hex()
)
# only want to specify encoding if data["data"] is a string
if isinstance(data["data"], str):
data["data"] = (
"0x"
+ bytes(data["data"][:3], encoding="utf8").hex()
+ "..."
+ bytes(data["data"][-3:], encoding="utf8").hex()
)
else:
data["data"] = (
"0x" + bytes(data["data"][:3]).hex() + "..." + bytes(data["data"][-3:]).hex()
)
else:
data["data"] = "0x" + bytes(data["data"], encoding="utf8").hex()
if isinstance(data["data"], str):
data["data"] = "0x" + bytes(data["data"], encoding="utf8").hex()
else:
data["data"] = "0x" + bytes(data["data"]).hex()
params = "\n ".join(f"{k}: {v}" for k, v in data.items())
return f"{self.__class__.__name__}:\n {params}"

Expand Down

0 comments on commit df472fc

Please sign in to comment.