TRANSACTION_RESULT_KEY_MAPPING = { 'access_list': 'accessList', 'block_hash': 'blockHash', 'block_number': 'blockNumber', 'gas_price': 'gasPrice', 'max_fee_per_gas': 'maxFeePerGas', 'max_priority_fee_per_gas': 'maxPriorityFeePerGas', 'transaction_hash': 'transactionHash', 'transaction_index': 'transactionIndex', } transaction_result_remapper = apply_key_map(TRANSACTION_RESULT_KEY_MAPPING) TRANSACTION_RESULT_FORMATTERS = { 'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)), 'access_list': apply_formatter_to_array( apply_key_map({'storage_keys': 'storageKeys'}), ), } transaction_result_formatter = apply_formatters_to_dict(TRANSACTION_RESULT_FORMATTERS) LOG_RESULT_KEY_MAPPING = { 'log_index': 'logIndex', 'transaction_index': 'transactionIndex', 'transaction_hash': 'transactionHash', 'block_hash': 'blockHash', 'block_number': 'blockNumber', } log_result_remapper = apply_key_map(LOG_RESULT_KEY_MAPPING)
def is_testrpc_available(): try: import testrpc # noqa: F401 return True except ImportError: return False to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer) TRANSACTION_FORMATTERS = { '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),
def is_testrpc_available(): try: import testrpc # noqa: F401 return True except ImportError: return False to_integer_if_hex = apply_formatter_if(is_string, hex_to_integer) TRANSACTION_FORMATTERS = { '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),
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_params_transformer = compose(filter_params_remapper, filter_params_formatter) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)), # type: ignore } transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS) RECEIPT_FORMATTERS = { 'logs': apply_formatter_to_array(log_key_remapper), } receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS) transaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter) ethereum_tester_middleware = construct_formatting_middleware( request_formatters={
} 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_params_transformer = compose(filter_params_remapper, filter_params_formatter) TRANSACTION_FORMATTERS = { 'to': apply_formatter_if(partial(operator.eq, ''), static_return(None)), } transaction_formatter = apply_formatters_to_dict(TRANSACTION_FORMATTERS) RECEIPT_FORMATTERS = { 'logs': apply_formatter_to_array(log_key_remapper), } receipt_formatter = apply_formatters_to_dict(RECEIPT_FORMATTERS) transaction_params_transformer = compose(transaction_params_remapper, transaction_params_formatter)