Skip to content

Commit

Permalink
Move abi formatters to _utils.method_formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjw committed Jan 17, 2019
1 parent 43b4084 commit c9bc02b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
24 changes: 22 additions & 2 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
is_array_of_strings,
remove_key_if,
)
from web3._utils.normalizers import (
abi_address_to_hex,
abi_bytes_to_hex,
abi_int_to_hex,
abi_string_to_hex,
)
from web3._utils.rpc_abi import (
RPC_ABIS,
abi_request_formatters,
)
from web3._utils.toolz.curried import (
keymap,
valmap,
Expand Down Expand Up @@ -387,6 +397,17 @@ def is_attrdict(val):
}


STANDARD_NORMALIZERS = [
abi_bytes_to_hex,
abi_int_to_hex,
abi_string_to_hex,
abi_address_to_hex,
]


ABI_REQUEST_FORMATTERS = abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS)


@curry
def method_filter(formatter_dict, method):
if method in formatter_dict:
Expand All @@ -398,6 +419,7 @@ def method_filter(formatter_dict, method):
REQUEST_FORMATTER_MAPS = (
method_filter(METHOD_NORMALIZERS),
method_filter(PYTHONIC_RESULT_FORMATTERS),
method_filter(ABI_REQUEST_FORMATTERS),
)


Expand All @@ -406,10 +428,8 @@ def method_filter(formatter_dict, method):
method_filter(ATTRDICT_FORMATTER),
)


# Note error formatters work on the full response dict
ERROR_FORMATTER_MAPS = (

)


Expand Down
4 changes: 2 additions & 2 deletions web3/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def default_middlewares(web3):
(attrdict_middleware, 'attrdict'), # Delete
(pythonic_middleware, 'pythonic'), # Delete
(normalize_errors_middleware, 'normalize_errors'), # Add async
(validation_middleware, 'validation'), # Migrate
(abi_middleware, 'abi'), # Migrate
(validation_middleware, 'validation'), # Add async
(abi_middleware, 'abi'), # Delete
]

#
Expand Down
21 changes: 3 additions & 18 deletions web3/middleware/abi.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
from web3._utils.normalizers import (
abi_address_to_hex,
abi_bytes_to_hex,
abi_int_to_hex,
abi_string_to_hex,
)
from web3._utils.rpc_abi import (
RPC_ABIS,
abi_request_formatters,
from web3._utils.method_formatters import (
ABI_REQUEST_FORMATTERS,
)

from .formatting import (
construct_formatting_middleware,
)

STANDARD_NORMALIZERS = [
abi_bytes_to_hex,
abi_int_to_hex,
abi_string_to_hex,
abi_address_to_hex,
]


abi_middleware = construct_formatting_middleware(
request_formatters=abi_request_formatters(STANDARD_NORMALIZERS, RPC_ABIS)
request_formatters=ABI_REQUEST_FORMATTERS
)
7 changes: 3 additions & 4 deletions web3/middleware/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from web3._utils.formatters import (
apply_formatter_if,
)
from web3._utils.method_formatters import (
STANDARD_NORMALIZERS,
)
from web3._utils.rpc_abi import (
TRANSACTION_PARAMS_ABIS,
apply_abi_formatters_to_dict,
Expand All @@ -31,10 +34,6 @@
fill_transaction_defaults,
)

from .abi import (
STANDARD_NORMALIZERS,
)

to_hexstr_from_eth_key = operator.methodcaller('to_hex')


Expand Down

0 comments on commit c9bc02b

Please sign in to comment.