BLOCK_VALIDATORS = { 'extraData': check_extradata_length, } block_validator = apply_formatter_if( is_not_null, apply_formatters_to_dict(BLOCK_VALIDATORS)) @curry def chain_id_validator(web3): return compose(apply_formatter_at_index(transaction_normalizer, 0), transaction_param_validator(web3)) def build_validators_with_web3(w3): return dict( request_formatters={ 'eth_sendTransaction': chain_id_validator(w3), 'eth_estimateGas': chain_id_validator(w3), 'eth_call': chain_id_validator(w3), }, result_formatters={ 'eth_getBlockByHash': block_validator, 'eth_getBlockByNumber': block_validator, }, ) validation_middleware = construct_web3_formatting_middleware( build_validators_with_web3)
# -- sync -- # def build_method_validators(w3: "Web3", method: RPCEndpoint) -> FormattersDict: request_formatters = {} if RPCEndpoint(method) in METHODS_TO_VALIDATE: w3_chain_id = w3.eth.chain_id for method in METHODS_TO_VALIDATE: request_formatters[method] = _chain_id_validator(w3_chain_id) return _build_formatters_dict(request_formatters) validation_middleware = construct_web3_formatting_middleware( build_method_validators) # -- async --- # async def async_build_method_validators(async_w3: "Web3", method: RPCEndpoint) -> FormattersDict: request_formatters: Formatters = {} if RPCEndpoint(method) in METHODS_TO_VALIDATE: w3_chain_id = await async_w3.eth.chain_id # type: ignore for method in METHODS_TO_VALIDATE: request_formatters[method] = _chain_id_validator(w3_chain_id) return _build_formatters_dict(request_formatters) async def async_validation_middleware(make_request: Callable[