def estimate_tx_gas_with_safe(self, safe_address: str, to: str, value: int, data: bytes, operation: int,<EOL>block_identifier='<STR_LIT>') -> int:
data = data or b'<STR_LIT>'<EOL>def parse_revert_data(result: bytes) -> int:<EOL><INDENT>gas_estimation_offset = <NUM_LIT:4> + <NUM_LIT:32> + <NUM_LIT:32><EOL>estimated_gas = result[gas_estimation_offset:]<EOL>if len(estimated_gas) != <NUM_LIT:32>:<EOL><INDENT>logger.warning('<STR_LIT>',<EOL>safe_address, result.hex(), tx)<EOL>raise CannotEstimateGas('<STR_LIT>' % (result.hex(), tx))<EOL><DEDENT>return int(estimated_gas.hex(), <NUM_LIT:16>)<EOL><DEDENT>try:<EOL><INDENT>tx = self.get_contract(safe_address).functions.requiredTxGas(<EOL>to,<EOL>value,<EOL>data,<EOL>operation<EOL>).buildTransaction({<EOL>'<STR_LIT>': safe_address,<EOL>'<STR_LIT>': int(<NUM_LIT>),<EOL>'<STR_LIT>': <NUM_LIT:0>,<EOL>})<EOL>result: HexBytes = self.w3.eth.call(tx, block_identifier=block_identifier)<EOL>return parse_revert_data(result)<EOL><DEDENT>except ValueError as exc:  <EOL><INDENT>"""<STR_LIT>"""<EOL>error_dict = exc.args[<NUM_LIT:0>]<EOL>data = error_dict.get('<STR_LIT:data>')<EOL>if not data:<EOL><INDENT>raise exc<EOL><DEDENT>elif isinstance(data, str) and '<STR_LIT>' in data:<EOL><INDENT>result = HexBytes(data.replace('<STR_LIT>', '<STR_LIT>'))<EOL>return parse_revert_data(result)<EOL><DEDENT>key = list(data.keys())[<NUM_LIT:0>]<EOL>result = data[key]['<STR_LIT>']<EOL>if result == '<STR_LIT>':<EOL><INDENT>raise exc<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>estimated_gas_hex = result[<NUM_LIT>:]<EOL>assert len(estimated_gas_hex) == <NUM_LIT:64><EOL>estimated_gas = int(estimated_gas_hex, <NUM_LIT:16>)<EOL>return estimated_gas<EOL><DEDENT><DEDENT>
Estimate tx gas using safe `requiredTxGas` method
:return: int: Estimated gas
:raises: CannotEstimateGas: If gas cannot be estimated
:raises: ValueError: Cannot decode received data