def __log_transaction(self, transaction_dict: dict, contract_function: ContractFunction): """ Format and log a transaction dict and return the transaction name string. This method *must not* mutate the original transaction dict. """ # Do not mutate the original transaction dict tx = dict(transaction_dict).copy() # Format if tx.get('to'): tx['to'] = to_checksum_address(contract_function.address) try: tx['selector'] = contract_function.selector except AttributeError: pass tx['from'] = to_checksum_address(tx['from']) tx.update({ f: prettify_eth_amount(v) for f, v in tx.items() if f in ('gasPrice', 'value') }) payload_pprint = ', '.join("{}: {}".format(k, v) for k, v in tx.items()) # Log transaction_name = get_transaction_name( contract_function=contract_function) self.log.debug(f"[TX-{transaction_name}] | {payload_pprint}")
def __init__(self, message: str, transaction_dict: dict, contract_function: Union[ContractFunction, ContractConstructor], *args): self.base_message = message self.name = get_transaction_name( contract_function=contract_function) self.payload = transaction_dict self.contract_function = contract_function self.failures = { BlockchainInterface.REASONS[INSUFFICIENT_ETH]: self.insufficient_eth } self.message = self.failures.get(self.base_message, self.default) super().__init__(self.message, *args)