-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
set_storage
[APE-1093] (#55)
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Union | ||
|
||
from eth_utils import to_bytes, to_hex | ||
from ethpm_types import HexBytes | ||
|
||
|
||
# TODO: Upstream to ape core | ||
def to_bytes32(value: Union[int, str, bytes, HexBytes]) -> HexBytes: | ||
if isinstance(value, int): | ||
value = to_bytes(value) | ||
|
||
elif isinstance(value, str): | ||
if set(value.lower().replace("0x", "")) > set("0123456789abcdef"): | ||
raise TypeError(f"'{value}' not valid hexstr") | ||
|
||
value = to_bytes(hexstr=value) | ||
|
||
elif not isinstance(value, bytes): | ||
raise TypeError(f"Cannot convert type '{type(value)}' to 'bytes'") | ||
|
||
if len(value) > 32: | ||
raise ValueError(f"Value '{to_hex(value)}' must be <= 32 bytes") | ||
|
||
return HexBytes(value.rjust(32, b"\x00")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters