diff options
author | F. Eugene Aumson <feuGeneA@users.noreply.github.com> | 2018-11-14 23:41:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-14 23:41:52 +0800 |
commit | e1d64def2017ced0aba599b989ad42a51fdd46fe (patch) | |
tree | 3f1a0c101c6486998ffbc96e082f9772fad93f82 /python-packages/order_utils/src/zero_ex/dev_utils | |
parent | fe1b7f15e8531615a54e46581cb734e635d3c755 (diff) | |
download | dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar.gz dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar.bz2 dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar.lz dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar.xz dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.tar.zst dexon-sol-tools-e1d64def2017ced0aba599b989ad42a51fdd46fe.zip |
feat(order_utils.py): sign_hash() (#1254)
Also moved is_valid_signature() into main package module, for
simplicity.
Also consolidated a handul of in-line pylint disable directives into the
.pylintrc config file.
Diffstat (limited to 'python-packages/order_utils/src/zero_ex/dev_utils')
-rw-r--r-- | python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py | 1 | ||||
-rw-r--r-- | python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py | 31 |
2 files changed, 31 insertions, 1 deletions
diff --git a/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py b/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py index 9afeacfdf..3fec775b0 100644 --- a/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py +++ b/python-packages/order_utils/src/zero_ex/dev_utils/abi_utils.py @@ -84,7 +84,6 @@ def method_id(name: str, types: List[str]) -> str: def simple_encode(method: str, *args: Any) -> bytes: - # docstring considered all one line by pylint: disable=line-too-long r"""Encode a method ABI. >>> simple_encode("ERC20Token(address)", "0x1dc4c1cefef38a777b15aa20260a54e584b16c48") diff --git a/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py index 08c1b0ea5..1dcfb39a9 100644 --- a/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py +++ b/python-packages/order_utils/src/zero_ex/dev_utils/type_assertions.py @@ -2,6 +2,9 @@ from typing import Any +from eth_utils import is_address +from web3.providers.base import BaseProvider + def assert_is_string(value: Any, name: str) -> None: """If :param value: isn't of type str, raise a TypeError. @@ -56,3 +59,31 @@ def assert_is_hex_string(value: Any, name: str) -> None: """ assert_is_string(value, name) int(value, 16) # raises a ValueError if value isn't a base-16 str + + +def assert_is_address(value: Any, name: str) -> None: + """Assert that `value` is a valid Ethereum address. + + If `value` isn't a hex string, raise a TypeError. If it isn't a valid + Ethereum address, raise a ValueError. + """ + assert_is_hex_string(value, name) + if not is_address(value): + raise ValueError( + f"Expected variable '{name}' to be a valid Ethereum" + + " address, but it's not." + ) + + +def assert_is_provider(value: Any, name: str) -> None: + """Assert that `value` is a Web3 provider. + + If `value` isn't a Web3 provider, raise a TypeError. + """ + # TODO: make this provider check more flexible. + # https://app.asana.com/0/684263176955174/901300863045491/f + if not isinstance(value, BaseProvider): + raise TypeError( + f"Expected variable '{name}' to be an instance of a Web3 provider," + + " but it's not." + ) |