Esempio n. 1
0
 def parse_receipt_output(self, name, outputdata):
     if name not in self.func_abi_map_by_name:
         return None
     func_abi = self.func_abi_map_by_name[name]
     output_args = get_fn_abi_types_single(func_abi, "outputs")
     # print(output_args)
     result = decode_single(output_args, decode_hex(outputdata))
     return result
Esempio n. 2
0
    def validate_value(self, value):
        if is_text(value):
            try:
                value = decode_hex(value)
            except binascii.Error:
                self.invalidate_value(
                    value,
                    msg='invalid hex string',
                )

        super().validate_value(value)
Esempio n. 3
0
def to_bytes(primitive=None, hexstr=None, text=None):
    assert_one_val(primitive, hexstr=hexstr, text=text)

    if is_boolean(primitive):
        return b'\x01' if primitive else b'\x00'
    elif isinstance(primitive, bytes):
        return primitive
    elif is_integer(primitive):
        return to_bytes(hexstr=to_hex(primitive))
    elif hexstr is not None:
        if len(hexstr) % 2:
            hexstr = '0x0' + remove_0x_prefix(hexstr)
        return decode_hex(hexstr)
    elif text is not None:
        return text.encode('utf-8')
    raise TypeError("expected an int in first arg, or keyword of hexstr or text")
Esempio n. 4
0
 def parse_transaction_input(self, inputdata):
     selector = inputdata[0:10]
     argsdata = inputdata[10:]
     # print(selector)
     # print(self.func_abi_map_by_selector.keys())
     if selector not in self.func_abi_map_by_selector:
         return None
     func_abi = self.func_abi_map_by_selector[selector]
     # print(func_abi)
     args_abi = get_fn_abi_types_single(func_abi, "inputs")
     args = decode_single(args_abi, decode_hex(argsdata))
     result = dict()
     result['name'] = func_abi["name"]
     result['args'] = args
     result['signature'] = abi_to_signature(func_abi)
     return result
Esempio n. 5
0
 def parse_event_logs(self, logs):
     # print(self.event_abi_map)
     for log in logs:
         if (len(log["topics"]) == 0):  # 匿名event
             continue
         topic = log["topics"][0]
         if topic not in self.event_topic_map:
             continue
         eventabi = self.event_topic_map[topic]
         # print(eventabi)
         if eventabi is None:
             continue
         # args_abi = get_fn_abi_types(eventabi,'inputs')
         argslist = exclude_indexed_event_inputs_to_single(eventabi)
         # print(argslist)
         result = decode_single(argslist, decode_hex(log['data']))
         # print(result)
         log["topic"] = topic
         log["eventdata"] = result
         log["eventname"] = eventabi["name"]
     return logs