def json_dict_to_transaction(self, json_dict): transaction = Transaction() transaction.hash = json_dict.get('hash', None) transaction.nonce = hex_to_dec(json_dict.get('nonce', None)) transaction.block_hash = json_dict.get('blockHash', None) transaction.block_number = hex_to_dec(json_dict.get('blockNumber', None)) transaction.transaction_index = hex_to_dec(json_dict.get('transactionIndex', None)) transaction.from_address = to_normalized_address(json_dict.get('from', None)) transaction.to_address = to_normalized_address(json_dict.get('to', None)) transaction.value = hex_to_dec(json_dict.get('value', None)) transaction.gas = hex_to_dec(json_dict.get('gas', None)) transaction.gas_price = hex_to_dec(json_dict.get('gasPrice', None)) transaction.input = json_dict.get('input', None) return transaction
def parse(self): return { 'hash': self.data.get('hash').hex(), 'nonce': self.data.get('nonce'), 'block_hash': self.data.get('blockHash').hex(), 'block_number': self.data.get('blockNumber'), 'transaction_index': self.data.get('transactionIndex'), 'from_address': to_normalized_address(self.data.get('from')), 'to_address': to_normalized_address(self.data.get('to')), 'value': self.data.get('value'), 'gas': self.data.get('gas'), 'gas_price': self.data.get('gasPrice'), 'input': self.data.get('input'), }
def parse(self): # 日志的 data 类型是 list,表示一个交易的所有日志 return [{ 'log_index': data.get('logIndex'), 'transaction_hash': data.get('transactionHash').hex(), 'transaction_index': data.get('transactionIndex'), 'block_hash': data.get('blockHash').hex(), 'block_number': data.get('blockNumber'), 'address': to_normalized_address(data.get('address')), 'data': data.get('data'), 'topics': ','.join([i.hex() for i in data.get('topics')]) } for data in self.data]
def parse(self): return { 'address': to_normalized_address(self.data), 'symbol': get_first_result(self.contract.functions.symbol(), self.contract.functions.SYMBOL()), 'name': get_first_result(self.contract.functions.name(), self.contract.functions.NAME()), 'decimals': get_first_result(self.contract.functions.decimals(), self.contract.functions.DECIMALS()), 'total_supply': get_first_result(self.contract.functions.totalSupply()), 'block_number': self.block_number }
def parse(self): return { 'transaction_hash': self.data.get('transactionHash').hex(), 'transaction_index': self.data.get('transactionIndex'), 'block_hash': self.data.get('blockHash').hex(), 'block_number': self.data.get('blockNumber'), 'cumulative_gas_used': self.data.get('cumulativeGasUsed'), 'gas_used': self.data.get('gasUsed'), 'contract_address': to_normalized_address(self.data.get('contractAddress')), 'root': self.data.get('root'), 'status': self.data.get('status'), }
def extract(self, tx: Transaction): cl = inject.instance(ParityEthJsonRpc) tx._reciept = cl.eth_getTransactionReceipt(tx.hash) mapper = TxReceiptLogMapper() for log_dict in tx._reciept['logs']: receipt_log = mapper.dict_to_receipt_log(log_dict) topics = receipt_log.topics if topics is None or len(topics) < 1: logger.warning( "Topics are empty in log {} of transaction {}".format( receipt_log.log_index, receipt_log.transaction_hash)) continue if topics[0] == TRANSFER_EVENT_TOPIC: topics_with_data = topics + split_to_words(receipt_log.data) if len(topics_with_data) != 4: logger.warning( "The number of topics and data parts is not equal to 4 in log {} of transaction {}" .format(receipt_log.log_index, receipt_log.transaction_hash)) continue token_transfer = TokenTransfer() token_transfer.value_id = to_normalized_address( receipt_log.address) token_transfer.from_address = word_to_address( topics_with_data[1]) token_transfer.to_address = word_to_address( topics_with_data[2]) token_transfer.value = hex_to_dec(topics_with_data[3]) token_transfer.transaction_hash = receipt_log.transaction_hash token_transfer.block_number = tx.block_number token_transfer.transaction_hash = tx.hash yield token_transfer
def parse(self): return { 'address': to_normalized_address(self.data.get('contractAddress')), 'block_number': self.block_number }