filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS) filter_result_formatter = apply_one_of_formatters(( (is_array_of_dicts, apply_list_to_array_formatter(log_entry_formatter)), (is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))), )) TRANSACTION_REQUEST_FORMATTERS = { 'maxFeePerGas': to_hex_if_integer, 'maxPriorityFeePerGas': to_hex_if_integer, } transaction_request_formatter = apply_formatters_to_dict( TRANSACTION_REQUEST_FORMATTERS) transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), remove_key_if('gasPrice', lambda txn: txn['gasPrice'] in {'', b'', None}), transaction_request_formatter, ) call_without_override: Callable[[Tuple[TxParams, BlockIdentifier]], Tuple[Dict[str, Any], int]] call_without_override = apply_formatters_to_sequence([ transaction_param_formatter, to_hex_if_integer, ]) call_with_override: Callable[ [Tuple[TxParams, BlockIdentifier, CallOverrideParams]], Tuple[Dict[str, Any], int, Dict[str, Any]], ] call_with_override = apply_formatters_to_sequence([ transaction_param_formatter,
proof_formatter = apply_formatters_to_dict(ACCOUNT_PROOF_FORMATTERS) FILTER_PARAMS_FORMATTERS = { 'fromBlock': apply_formatter_if(is_integer, integer_to_hex), 'toBlock': apply_formatter_if(is_integer, integer_to_hex), } filter_params_formatter = apply_formatters_to_dict(FILTER_PARAMS_FORMATTERS) filter_result_formatter = apply_one_of_formatters(( (is_array_of_dicts, apply_list_to_array_formatter(log_entry_formatter)), (is_array_of_strings, apply_list_to_array_formatter(to_hexbytes(32))), )) transaction_param_formatter = compose( remove_key_if('to', lambda txn: txn['to'] in {'', b'', None}), ) estimate_gas_without_block_id: Callable[[Dict[str, Any]], Dict[str, Any]] estimate_gas_without_block_id = apply_formatter_at_index( transaction_param_formatter, 0) estimate_gas_with_block_id: Callable[[Tuple[Dict[str, Any], Union[str, int]]], Tuple[Dict[str, Any], int]] estimate_gas_with_block_id = apply_formatters_to_sequence([ transaction_param_formatter, block_number_formatter, ]) SIGNED_TX_FORMATTER = { 'raw': HexBytes, 'tx': transaction_formatter, }
transaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING) TRANSACTION_PARAMS_FORMATTERS = { 'gas': to_integer_if_hex, 'gasPrice': to_integer_if_hex, 'value': to_integer_if_hex, 'nonce': to_integer_if_hex, } transaction_params_formatter = compose( # remove nonce for now due to issue https://github.com/ethereum/eth-tester/issues/80 remove_key_if('nonce', lambda _: True), apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS), ) FILTER_PARAMS_MAPPINGS = { 'fromBlock': 'from_block', 'toBlock': 'to_block', } filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS) FILTER_PARAMS_FORMATTERS = { 'fromBlock': to_integer_if_hex, 'toBlock': to_integer_if_hex, }
TRANSACTION_PARAMS_MAPPING = { 'gasPrice': 'gas_price', } transaction_params_remapper = apply_key_map(TRANSACTION_PARAMS_MAPPING) TRANSACTION_PARAMS_FORMATTERS = { 'gas': to_integer_if_hex, 'gasPrice': to_integer_if_hex, 'value': to_integer_if_hex, 'nonce': to_integer_if_hex, } transaction_params_formatter = compose( # remove nonce for now due to issue https://github.com/ethereum/eth-tester/issues/80 remove_key_if('nonce', lambda _: True), apply_formatters_to_dict(TRANSACTION_PARAMS_FORMATTERS), ) FILTER_PARAMS_MAPPINGS = { 'fromBlock': 'from_block', 'toBlock': 'to_block', } filter_params_remapper = apply_key_map(FILTER_PARAMS_MAPPINGS) FILTER_PARAMS_FORMATTERS = { 'fromBlock': to_integer_if_hex, 'toBlock': to_integer_if_hex, }
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_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),