def abi_request_formatters(normalizers, abis): for method, abi_types in abis.items(): if isinstance(abi_types, list): yield method, map_abi_data(normalizers, abi_types) elif isinstance(abi_types, dict): single_dict_formatter = apply_abi_formatters_to_dict(normalizers, abi_types) yield method, apply_formatter_at_index(single_dict_formatter, 0) else: raise TypeError("ABI definitions must be a list or dictionary, got %r" % abi_types)
filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS) 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), )) transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), ) estimate_gas_without_block_id = apply_formatter_at_index(transaction_param_formatter, 0) estimate_gas_with_block_id = apply_formatters_to_sequence([ transaction_param_formatter, block_number_formatter, ]) pythonic_middleware = construct_formatting_middleware( request_formatters={ # Eth 'eth_getBalance': apply_formatter_at_index(block_number_formatter, 1), 'eth_getBlockByNumber': apply_formatter_at_index(block_number_formatter, 0), 'eth_getBlockTransactionCountByNumber': apply_formatter_at_index( block_number_formatter, 0, ),
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), )) TRANSACTION_PARAM_FORMATTERS = { 'chainId': apply_formatter_if(is_integer, str), } transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), apply_formatters_to_dict(TRANSACTION_PARAM_FORMATTERS), ) estimate_gas_without_block_id = apply_formatter_at_index( transaction_param_formatter, 0) estimate_gas_with_block_id = combine_argument_formatters( transaction_param_formatter, block_number_formatter, ) pythonic_middleware = construct_formatting_middleware( request_formatters={ # Eth 'eth_getBalance': apply_formatter_at_index(block_number_formatter, 1), 'eth_getBlockByNumber': apply_formatter_at_index(block_number_formatter, 0), 'eth_getBlockTransactionCountByNumber': apply_formatter_at_index( block_number_formatter,
'to': apply_formatter_if( compose(complement(bool), decode_hex), static_return(None), ), } def ethtestrpc_string_middleware(make_request, web3): def middleware(method, params): return valmap(to_text, make_request(method, params)) return middleware ethtestrpc_middleware = construct_formatting_middleware( request_formatters={ 'eth_uninstallFilter': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterChanges': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterLogs': apply_formatter_at_index(to_integer_if_hex, 0), }, result_formatters={ # Eth 'eth_newFilter': apply_formatter_if(is_integer, hex), 'eth_protocolVersion': apply_formatter_if(is_integer, str), 'eth_getTransactionByHash': apply_formatters_to_dict(TRANSACTION_FORMATTERS), # Net 'net_version': apply_formatter_if(is_integer, str), }, ) return_none_result = static_result(None)
compose(complement(bool), decode_hex), static_return(None), ), } def ethtestrpc_string_middleware(make_request, web3): def middleware(method, params): return valmap(to_text, make_request(method, params)) return middleware ethtestrpc_middleware = construct_formatting_middleware( request_formatters={ 'eth_uninstallFilter': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterChanges': apply_formatter_at_index(to_integer_if_hex, 0), 'eth_getFilterLogs': apply_formatter_at_index(to_integer_if_hex, 0), }, result_formatters={ # Eth 'eth_newFilter': apply_formatter_if(is_integer, hex), 'eth_protocolVersion': apply_formatter_if(is_integer, str), 'eth_getTransactionByHash': apply_formatters_to_dict(TRANSACTION_FORMATTERS), # Net 'net_version': apply_formatter_if(is_integer, str), },
from eth_utils import ( is_string, ) from web3._utils.formatters import ( apply_formatter_at_index, apply_formatter_if, apply_formatters_to_dict, ) from .formatting import ( construct_formatting_middleware, ) FILTER_PARAM_NORMALIZERS = apply_formatters_to_dict({ 'address': apply_formatter_if(is_string, lambda x: [x])}) METHOD_NORMALIZERS = { 'eth_getLogs': apply_formatter_at_index(FILTER_PARAM_NORMALIZERS, 0), 'eth_newFilter': apply_formatter_at_index(FILTER_PARAM_NORMALIZERS, 0) } request_parameter_normalizer = construct_formatting_middleware( request_formatters=METHOD_NORMALIZERS, )
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), )) TRANSACTION_PARAM_FORMATTERS = { 'chainId': apply_formatter_if(is_integer, str), } transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), apply_formatters_to_dict(TRANSACTION_PARAM_FORMATTERS), ) estimate_gas_without_block_id = apply_formatter_at_index( transaction_param_formatter, 0) estimate_gas_with_block_id = apply_formatters_to_sequence([ transaction_param_formatter, block_number_formatter, ]) min_gas_price_formatter = apply_formatters_to_sequence([ to_integer_if_hex, to_integer_if_hex, ]) BLOCK_CREATION_PARAMETERS_FORMATTER = { 'block_number': to_integer_if_hex, 'parent_hash': HexBytes, 'nonce': to_integer_if_hex, 'receive_transactions': apply_formatter_to_array(HexBytes),
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), )) TRANSACTION_PARAM_FORMATTERS = { 'chainId': apply_formatter_if(is_integer, str), } transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), apply_formatters_to_dict(TRANSACTION_PARAM_FORMATTERS), ) estimate_gas_without_block_id = apply_formatter_at_index(transaction_param_formatter, 0) estimate_gas_with_block_id = combine_argument_formatters( transaction_param_formatter, block_number_formatter, ) pythonic_middleware = construct_formatting_middleware( request_formatters={ # Eth 'eth_getBalance': apply_formatter_at_index(block_number_formatter, 1), 'eth_getBlockByNumber': apply_formatter_at_index(block_number_formatter, 0), 'eth_getBlockTransactionCountByNumber': apply_formatter_at_index( block_number_formatter, 0, ),