From 70768a234b5ed9f68d85138be626f349e718b7c7 Mon Sep 17 00:00:00 2001 From: aashutoshrathi Date: Sat, 10 Nov 2018 00:00:59 +0530 Subject: [PATCH] Migrated encode and decode hex --- eth/beacon/types/active_states.py | 2 +- eth/beacon/types/blocks.py | 2 +- eth/beacon/types/crystallized_states.py | 2 +- eth/chains/base.py | 2 +- eth/consensus/pow.py | 16 ++++++++-------- eth/db/__init__.py | 14 ++++++-------- eth/db/chain.py | 6 ++---- eth/estimators/__init__.py | 15 +++++---------- eth/rlp/headers.py | 12 ++++++------ eth/utils/hexadecimal.py | 12 ------------ eth/vm/computation.py | 4 ++-- eth/vm/forks/constantinople/storage.py | 2 +- eth/vm/forks/frontier/computation.py | 2 +- eth/vm/forks/frontier/state.py | 2 +- eth/vm/forks/homestead/computation.py | 2 +- eth/vm/forks/spurious_dragon/computation.py | 2 +- eth/vm/forks/spurious_dragon/state.py | 2 +- eth/vm/logic/storage.py | 2 +- eth/vm/logic/system.py | 2 +- scripts/benchmark/utils/format.py | 2 +- .../hexadecimal-utils/test_encode_and_decode.py | 2 +- tests/core/vm/test_modexp_precompile.py | 2 +- tests/fillers/build_json.py | 2 +- 23 files changed, 45 insertions(+), 66 deletions(-) delete mode 100644 eth/utils/hexadecimal.py diff --git a/eth/beacon/types/active_states.py b/eth/beacon/types/active_states.py index 7516539422..bc639048ad 100644 --- a/eth/beacon/types/active_states.py +++ b/eth/beacon/types/active_states.py @@ -13,7 +13,7 @@ from eth.rlp.sedes import ( hash32 ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.utils.blake import ( diff --git a/eth/beacon/types/blocks.py b/eth/beacon/types/blocks.py index 3eaee398a4..bcaa021c1e 100644 --- a/eth/beacon/types/blocks.py +++ b/eth/beacon/types/blocks.py @@ -19,7 +19,7 @@ int64, hash32, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/beacon/types/crystallized_states.py b/eth/beacon/types/crystallized_states.py index 5abbe6e884..189701e4fb 100644 --- a/eth/beacon/types/crystallized_states.py +++ b/eth/beacon/types/crystallized_states.py @@ -16,7 +16,7 @@ int64, hash32, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.utils.blake import ( diff --git a/eth/chains/base.py b/eth/chains/base.py index 512a6f1113..bda216e01e 100644 --- a/eth/chains/base.py +++ b/eth/chains/base.py @@ -82,7 +82,7 @@ from eth.utils.headers import ( compute_gas_limit_bounds, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.utils.rlp import ( diff --git a/eth/consensus/pow.py b/eth/consensus/pow.py index 3815f541cb..be8199e53d 100644 --- a/eth/consensus/pow.py +++ b/eth/consensus/pow.py @@ -4,25 +4,25 @@ Tuple ) -from pyethash import ( - EPOCH_LENGTH, - hashimoto_light, - mkcache_bytes, -) - from eth_typing import ( Hash32 ) + from eth_utils import ( big_endian_to_int, ValidationError, + encode_hex, ) from eth_hash.auto import keccak -from eth.utils.hexadecimal import ( - encode_hex, +from pyethash import ( + EPOCH_LENGTH, + hashimoto_light, + mkcache_bytes, ) + + from eth.validation import ( validate_length, validate_lte, diff --git a/eth/db/__init__.py b/eth/db/__init__.py index 9211a0b37f..bb4e7c8e34 100644 --- a/eth/db/__init__.py +++ b/eth/db/__init__.py @@ -1,16 +1,14 @@ import os from typing import ( Any, - cast, - Type + Type, + cast ) -from eth.utils.module_loading import ( - import_string, -) -from eth.db.backends.base import ( - BaseAtomicDB, -) +from eth_utils import import_string + +from eth.db.backends.base import BaseAtomicDB + DEFAULT_DB_BACKEND = 'eth.db.atomic.AtomicDB' diff --git a/eth/db/chain.py b/eth/db/chain.py index a50535c955..3911c89e0d 100644 --- a/eth/db/chain.py +++ b/eth/db/chain.py @@ -39,7 +39,7 @@ from eth.rlp.receipts import ( Receipt ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.validation import ( @@ -59,9 +59,7 @@ if TYPE_CHECKING: from eth.rlp.blocks import ( # noqa: F401 - BaseBlock - ) - from eth.rlp.transactions import ( # noqa: F401 + BaseBlock, BaseTransaction ) diff --git a/eth/estimators/__init__.py b/eth/estimators/__init__.py index 1ce66ac7a0..64347a412c 100644 --- a/eth/estimators/__init__.py +++ b/eth/estimators/__init__.py @@ -1,18 +1,13 @@ import os from typing import ( Callable, - cast, + cast ) -from eth.rlp.transactions import ( - BaseTransaction, -) -from eth.utils.module_loading import ( - import_string, -) -from eth.vm.state import ( - BaseState, -) + +from eth_utils import import_string +from eth.rlp.transactions import BaseTransaction +from eth.vm.state import BaseState def get_gas_estimator() -> Callable[[BaseState, BaseTransaction], int]: diff --git a/eth/rlp/headers.py b/eth/rlp/headers.py index a1be902d22..6382582c47 100644 --- a/eth/rlp/headers.py +++ b/eth/rlp/headers.py @@ -20,6 +20,10 @@ from eth_hash.auto import keccak +from eth_utils import ( + encode_hex, +) + from eth.constants import ( ZERO_ADDRESS, ZERO_HASH32, @@ -29,8 +33,8 @@ BLANK_ROOT_HASH, ) -from eth.utils.hexadecimal import ( - encode_hex, +from eth.vm.execution_context import ( + ExecutionContext, ) from .sedes import ( @@ -40,10 +44,6 @@ trie_root, ) -from eth.vm.execution_context import ( - ExecutionContext, -) - class MiningHeader(rlp.Serializable): fields = [ diff --git a/eth/utils/hexadecimal.py b/eth/utils/hexadecimal.py deleted file mode 100644 index 912ae4a67c..0000000000 --- a/eth/utils/hexadecimal.py +++ /dev/null @@ -1,12 +0,0 @@ -from __future__ import unicode_literals - -import codecs - - -def encode_hex(value: bytes) -> str: - return '0x' + codecs.decode(codecs.encode(value, 'hex'), 'utf8') # type: ignore - - -def decode_hex(value: str) -> bytes: - _, _, hex_part = value.rpartition('x') - return codecs.decode(hex_part, 'hex') # type: ignore diff --git a/eth/vm/computation.py b/eth/vm/computation.py index 86bdf912cc..5d415cfba3 100644 --- a/eth/vm/computation.py +++ b/eth/vm/computation.py @@ -33,7 +33,7 @@ from eth.utils.datatypes import ( Configurable, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.utils.numeric import ( @@ -292,7 +292,7 @@ def refund_gas(self, amount: int) -> None: """ return self._gas_meter.refund_gas(amount) - def stack_pop(self, num_items: int=1, type_hint: str=None) -> Any: + def stack_pop(self, num_items: int = 1, type_hint: str = None) -> Any: # TODO: Needs to be replaced with # `Union[int, bytes, Tuple[Union[int, bytes], ...]]` if done properly """ diff --git a/eth/vm/forks/constantinople/storage.py b/eth/vm/forks/constantinople/storage.py index 61e96875e6..923aa67e79 100644 --- a/eth/vm/forks/constantinople/storage.py +++ b/eth/vm/forks/constantinople/storage.py @@ -7,7 +7,7 @@ constants ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/vm/forks/frontier/computation.py b/eth/vm/forks/frontier/computation.py index 08fdc618a4..7ba1f78ef8 100644 --- a/eth/vm/forks/frontier/computation.py +++ b/eth/vm/forks/frontier/computation.py @@ -16,7 +16,7 @@ from eth.utils.address import ( force_bytes_to_address, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/vm/forks/frontier/state.py b/eth/vm/forks/frontier/state.py index 19a996df04..c4aac5ad06 100644 --- a/eth/vm/forks/frontier/state.py +++ b/eth/vm/forks/frontier/state.py @@ -18,7 +18,7 @@ from eth.utils.address import ( generate_contract_address, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/vm/forks/homestead/computation.py b/eth/vm/forks/homestead/computation.py index ee745a7b9e..97697de9fc 100644 --- a/eth/vm/forks/homestead/computation.py +++ b/eth/vm/forks/homestead/computation.py @@ -4,7 +4,7 @@ from eth.exceptions import ( OutOfGas, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.vm.computation import BaseComputation diff --git a/eth/vm/forks/spurious_dragon/computation.py b/eth/vm/forks/spurious_dragon/computation.py index a053b3bd74..06d4f3efb6 100644 --- a/eth/vm/forks/spurious_dragon/computation.py +++ b/eth/vm/forks/spurious_dragon/computation.py @@ -4,7 +4,7 @@ from eth.exceptions import ( OutOfGas, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.vm.computation import BaseComputation diff --git a/eth/vm/forks/spurious_dragon/state.py b/eth/vm/forks/spurious_dragon/state.py index be0019c0b9..8bc01fd903 100644 --- a/eth/vm/forks/spurious_dragon/state.py +++ b/eth/vm/forks/spurious_dragon/state.py @@ -1,6 +1,6 @@ from eth.rlp.transactions import BaseTransaction -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/vm/logic/storage.py b/eth/vm/logic/storage.py index 42609092be..bb4c6fc703 100644 --- a/eth/vm/logic/storage.py +++ b/eth/vm/logic/storage.py @@ -1,6 +1,6 @@ from eth import constants -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/eth/vm/logic/system.py b/eth/vm/logic/system.py index 6c2cb7c14b..60c6cf86f7 100644 --- a/eth/vm/logic/system.py +++ b/eth/vm/logic/system.py @@ -14,7 +14,7 @@ generate_contract_address, generate_safe_contract_address, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) from eth.utils.numeric import ( diff --git a/scripts/benchmark/utils/format.py b/scripts/benchmark/utils/format.py index fed23af02e..30897ad079 100644 --- a/scripts/benchmark/utils/format.py +++ b/scripts/benchmark/utils/format.py @@ -1,5 +1,5 @@ from eth.rlp.blocks import BaseBlock -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, ) diff --git a/tests/core/hexadecimal-utils/test_encode_and_decode.py b/tests/core/hexadecimal-utils/test_encode_and_decode.py index eef3756f00..85229bca6a 100644 --- a/tests/core/hexadecimal-utils/test_encode_and_decode.py +++ b/tests/core/hexadecimal-utils/test_encode_and_decode.py @@ -7,7 +7,7 @@ strategies as st, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, decode_hex, ) diff --git a/tests/core/vm/test_modexp_precompile.py b/tests/core/vm/test_modexp_precompile.py index 3d8f32af65..c8a91e8090 100644 --- a/tests/core/vm/test_modexp_precompile.py +++ b/tests/core/vm/test_modexp_precompile.py @@ -4,7 +4,7 @@ _modexp, _compute_modexp_gas_fee, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( decode_hex, ) diff --git a/tests/fillers/build_json.py b/tests/fillers/build_json.py index d92e0a08cd..5b27f853dd 100644 --- a/tests/fillers/build_json.py +++ b/tests/fillers/build_json.py @@ -13,7 +13,7 @@ filler_formatter, ) -from eth.utils.hexadecimal import ( +from eth_utils import ( encode_hex, )