Skip to content

Commit

Permalink
Fix bad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Nov 6, 2019
1 parent 7e18f20 commit 1740e3a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/core/version-module/test_version_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ async def test_async_blocking_version(async_w3, blocking_w3):
assert async_w3.async_version.api == blocking_w3.api

assert await async_w3.async_version.node == blocking_w3.clientVersion
assert await async_w3.async_version.ethereum == int(blocking_w3.eth.protocolVersion)
assert await async_w3.async_version.ethereum == blocking_w3.eth.protocolVersion
47 changes: 27 additions & 20 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import operator

from eth_utils.curried import (
apply_formatter_at_index,
apply_formatter_if,
apply_formatter_to_array,
apply_formatters_to_dict,
apply_formatters_to_sequence,
apply_one_of_formatters,
is_address,
is_bytes,
is_dict,
Expand All @@ -12,6 +17,7 @@
remove_0x_prefix,
text_if_str,
to_checksum_address,
to_list,
to_tuple,
)
from eth_utils.toolz import (
Expand All @@ -33,11 +39,6 @@
to_hex,
)
from web3._utils.formatters import (
apply_formatter_at_index,
apply_formatter_if,
apply_formatter_to_array,
apply_formatters_to_dict,
apply_one_of_formatters,
hex_to_integer,
integer_to_hex,
is_array_of_dicts,
Expand Down Expand Up @@ -137,14 +138,18 @@ def is_attrdict(val):
whisper_log_formatter = apply_formatters_to_dict(WHISPER_LOG_FORMATTERS)


def apply_list_to_array_formatter(formatter):
return to_list(apply_formatter_to_array(formatter))


LOG_ENTRY_FORMATTERS = {
'blockHash': apply_formatter_if(is_not_null, to_hexbytes(32)),
'blockNumber': apply_formatter_if(is_not_null, to_integer_if_hex),
'transactionIndex': apply_formatter_if(is_not_null, to_integer_if_hex),
'transactionHash': apply_formatter_if(is_not_null, to_hexbytes(32)),
'logIndex': to_integer_if_hex,
'address': to_checksum_address,
'topics': apply_formatter_to_array(to_hexbytes(32)),
'topics': apply_list_to_array_formatter(to_hexbytes(32)),
'data': to_ascii_if_bytes,
}

Expand All @@ -161,7 +166,7 @@ def is_attrdict(val):
'status': to_integer_if_hex,
'gasUsed': to_integer_if_hex,
'contractAddress': apply_formatter_if(is_not_null, to_checksum_address),
'logs': apply_formatter_to_array(log_entry_formatter),
'logs': apply_list_to_array_formatter(log_entry_formatter),
'logsBloom': to_hexbytes(256),
}

Expand All @@ -182,14 +187,14 @@ def is_attrdict(val):
'number': apply_formatter_if(is_not_null, to_integer_if_hex),
'parentHash': apply_formatter_if(is_not_null, to_hexbytes(32)),
'sha3Uncles': apply_formatter_if(is_not_null, to_hexbytes(32)),
'uncles': apply_formatter_to_array(to_hexbytes(32)),
'uncles': apply_list_to_array_formatter(to_hexbytes(32)),
'difficulty': to_integer_if_hex,
'receiptsRoot': to_hexbytes(32),
'stateRoot': to_hexbytes(32),
'totalDifficulty': to_integer_if_hex,
'transactions': apply_one_of_formatters((
(apply_formatter_to_array(transaction_formatter), is_array_of_dicts),
(apply_formatter_to_array(to_hexbytes(32)), is_array_of_strings),
(is_array_of_dicts, apply_list_to_array_formatter(transaction_formatter)),
(is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))),
)),
'transactionsRoot': to_hexbytes(32),
}
Expand Down Expand Up @@ -240,17 +245,19 @@ def is_attrdict(val):
STORAGE_PROOF_FORMATTERS = {
'key': HexBytes,
'value': HexBytes,
'proof': apply_formatter_to_array(HexBytes),
'proof': apply_list_to_array_formatter(HexBytes),
}

ACCOUNT_PROOF_FORMATTERS = {
'address': to_checksum_address,
'accountProof': apply_formatter_to_array(HexBytes),
'accountProof': apply_list_to_array_formatter(HexBytes),
'balance': to_integer_if_hex,
'codeHash': to_hexbytes(32),
'nonce': to_integer_if_hex,
'storageHash': to_hexbytes(32),
'storageProof': apply_formatter_to_array(apply_formatters_to_dict(STORAGE_PROOF_FORMATTERS))
'storageProof': apply_list_to_array_formatter(
apply_formatters_to_dict(STORAGE_PROOF_FORMATTERS)
)
}

proof_formatter = apply_formatters_to_dict(ACCOUNT_PROOF_FORMATTERS)
Expand All @@ -265,8 +272,8 @@ def is_attrdict(val):


filter_result_formatter = apply_one_of_formatters((
(apply_formatter_to_array(log_entry_formatter), is_array_of_dicts),
(apply_formatter_to_array(to_hexbytes(32)), is_array_of_strings),
(is_array_of_dicts, apply_list_to_array_formatter(log_entry_formatter)),
(is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))),
))


Expand Down Expand Up @@ -325,8 +332,8 @@ def is_attrdict(val):
block_number_formatter,
]),
'eth_estimateGas': apply_one_of_formatters((
(estimate_gas_without_block_id, is_length(1)),
(estimate_gas_with_block_id, is_length(2)),
(is_length(1), estimate_gas_without_block_id),
(is_length(2), estimate_gas_with_block_id),
)),
'eth_sendTransaction': apply_formatter_at_index(transaction_param_formatter, 0),
'eth_getProof': apply_formatter_at_index(block_number_formatter, 2),
Expand All @@ -351,7 +358,7 @@ def is_attrdict(val):

PYTHONIC_RESULT_FORMATTERS = {
# Eth
'eth_accounts': apply_formatter_to_array(to_checksum_address),
'eth_accounts': apply_list_to_array_formatter(to_checksum_address),
'eth_blockNumber': to_integer_if_hex,
'eth_chainId': to_integer_if_hex,
'eth_coinbase': to_checksum_address,
Expand Down Expand Up @@ -397,12 +404,12 @@ def is_attrdict(val):
'eth_syncing': apply_formatter_if(is_not_false, syncing_formatter),
# personal
'personal_importRawKey': to_checksum_address,
'personal_listAccounts': apply_formatter_to_array(to_checksum_address),
'personal_listAccounts': apply_list_to_array_formatter(to_checksum_address),
'personal_newAccount': to_checksum_address,
'personal_sendTransaction': to_hexbytes(32),
'personal_signTypedData': HexBytes,
# SHH
'shh_getFilterMessages': apply_formatter_to_array(whisper_log_formatter),
'shh_getFilterMessages': apply_list_to_array_formatter(whisper_log_formatter),
# Transaction Pool
'txpool_content': transaction_pool_content_formatter,
'txpool_inspect': transaction_pool_inspect_formatter,
Expand Down

0 comments on commit 1740e3a

Please sign in to comment.