コード例 #1
0
    def get_event_data(self, log: dict):
        data_types, data_names, topic_types, topic_names = [], [], [], []   # cannot use `[[]] * 4`
        for arg in self._abi['inputs']:
            if arg.get('indexed', False) is False:
                data_types.append(arg['type'])
                data_names.append(arg['name'])
            else:
                topic_types.append(arg['type'])
                topic_names.append(arg['name'])

        topics = log['topics'][1:]
        decoded_topic_data = [
            trx_abi.decode_single(topic_type, decode_hex(topic_data))
            for topic_type, topic_data
            in zip(topic_types, topics)
        ]

        data = decode_hex(log['data'])
        decoded_data = trx_abi.decode_abi(data_types, data)

        event_args = dict(itertools.chain(
            zip(topic_names, decoded_topic_data),
            zip(data_names, decoded_data),
        ))
        return {
            'args': event_args,
            'event': self._event_name,
            'address': log['address'],
        }
コード例 #2
0
ファイル: contract.py プロジェクト: varche1/tronpy
 def parse_output(self, raw: str) -> Any:
     """Parse contract result as result."""
     parsed_result = trx_abi.decode_single(self.output_type, bytes.fromhex(raw))
     if len(self.outputs) == 1:
         return parsed_result[0]
     if len(self.outputs) == 0:
         return None
     return parsed_result