Skip to content

Commit

Permalink
Add wraps decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed May 17, 2021
1 parent 7aa4e79 commit dba79df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ens/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from functools import (
wraps,
)
from typing import (
TYPE_CHECKING,
Optional,
Expand Down Expand Up @@ -70,22 +73,27 @@ class ENS:
"""

@staticmethod
@wraps(label_to_hash)
def labelhash(label: str) -> HexBytes:
return label_to_hash(label)

@staticmethod
@wraps(raw_name_to_hash)
def namehash(name: str) -> HexBytes:
return raw_name_to_hash(name)

@staticmethod
@wraps(normalize_name)
def nameprep(name: str) -> str:
return normalize_name(name)

@staticmethod
@wraps(is_valid_name)
def is_valid_name(name: str) -> bool:
return is_valid_name(name)

@staticmethod
@wraps(address_to_reverse_domain)
def reverse_domain(address: ChecksumAddress) -> str:
return address_to_reverse_domain(address)

Expand Down
13 changes: 13 additions & 0 deletions web3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
to_text,
to_wei,
)
from functools import (
wraps,
)
from hexbytes import (
HexBytes,
)
Expand Down Expand Up @@ -155,52 +158,62 @@ class Web3:

# Encoding and Decoding
@staticmethod
@wraps(to_bytes)
def toBytes(
primitive: Primitives = None, hexstr: HexStr = None, text: str = None
) -> bytes:
return to_bytes(primitive, hexstr, text)

@staticmethod
@wraps(to_int)
def toInt(
primitive: Primitives = None, hexstr: HexStr = None, text: str = None
) -> int:
return to_int(primitive, hexstr, text)

@staticmethod
@wraps(to_hex)
def toHex(
primitive: Primitives = None, hexstr: HexStr = None, text: str = None
) -> HexStr:
return to_hex(primitive, hexstr, text)

@staticmethod
@wraps(to_text)
def toText(
primitive: Primitives = None, hexstr: HexStr = None, text: str = None
) -> str:
return to_text(primitive, hexstr, text)

@staticmethod
@wraps(to_json)
def toJSON(obj: Dict[Any, Any]) -> str:
return to_json(obj)

# Currency Utility
@staticmethod
@wraps(to_wei)
def toWei(number: Union[int, float, str, decimal.Decimal], unit: str) -> Wei:
return cast(Wei, to_wei(number, unit))

@staticmethod
@wraps(from_wei)
def fromWei(number: int, unit: str) -> Union[int, decimal.Decimal]:
return from_wei(number, unit)

# Address Utility
@staticmethod
@wraps(is_address)
def isAddress(value: Any) -> bool:
return is_address(value)

@staticmethod
@wraps(is_checksum_address)
def isChecksumAddress(value: Any) -> bool:
return is_checksum_address(value)

@staticmethod
@wraps(to_checksum_address)
def toChecksumAddress(value: Union[AnyAddress, str, bytes]) -> ChecksumAddress:
return to_checksum_address(value)

Expand Down

0 comments on commit dba79df

Please sign in to comment.