def register_event_callback(addresses, event_name, indexed_value):
    topics = []
    topic0 = parser.topic_from_event_name(event_name)
    topics.append(topic0)
    event_abi = parser.event_name_map[event_name]
    print("event abi:", event_abi)
    if len(indexed_value) > 0:
        indexedinput = []
        for input in event_abi["inputs"]:
            if input["indexed"] is True:
                indexedinput.append((input['name'], input['type']))
        print(indexedinput)
        i = 0
        for v in indexed_value:
            itype = indexedinput[i][1]
            topic = DatatypeParser.topic_from_type(itype, v)
            if not (topic is None):
                topics.append(topic)
            i = i + 1
    requestJson = format_event_register_request("latest", "latest", addresses,
                                                topics)
    requestbytes = ChannelPack.pack_amop_topic_message("", requestJson)
    client.channel_handler.pushDispacher.add_handler(
        ChannelPack.EVENT_LOG_PUSH, eventHandler01)
    client.channel_handler.pushDispacher.add_handler(
        ChannelPack.EVENT_LOG_PUSH, eventHandler02)
    response = client.channel_handler.make_channel_request(
        requestbytes, ChannelPack.CLIENT_REGISTER_EVENT_LOG,
        ChannelPack.CLIENT_REGISTER_EVENT_LOG)
    (topic, result) = ChannelPack.unpack_amop_topic_message(response)
    dataobj = json.loads(result)
    print("after register ,event_name:{},topic:{},result:{}".format(
        event_name, topic, dataobj['result']))
예제 #2
0
 def register_eventlog_filter(
         self,
         eventcallback,
         abiparser,
         addresses,
         event_name,
         indexed_value=None,
         fromblock="latest",
         to_block="latest"):
     topics = []
     if event_name is not None:
         topic0 = abiparser.topic_from_event_name(event_name)
         topics.append(topic0)
         event_abi = abiparser.event_name_map[event_name]
     #print("event abi:", event_abi)
     if indexed_value is not None and len(indexed_value) > 0:
         indexedinput = []
         for event_input in event_abi["inputs"]:
             if event_input["indexed"] is True:
                 indexedinput.append((event_input['name'], event_input['type']))
         # print(indexedinput)
         i = 0
         for v in indexed_value:
             itype = indexedinput[i][1]
             topic = DatatypeParser.topic_from_type(itype, v)
             if not (topic is None):
                 topics.append(topic)
             i = i + 1
     # create new filterid by uuid
     seq = uuid.uuid1()
     filterid = seq.hex
     requestJson = self.format_event_register_request(
         fromblock, to_block, addresses, topics, self.client.groupid, filterid)
     requestbytes = ChannelPack.pack_amop_topic_message("", requestJson)
     response = self.client.channel_handler.make_channel_request(
         requestbytes, ChannelPack.CLIENT_REGISTER_EVENT_LOG, ChannelPack.CLIENT_REGISTER_EVENT_LOG)
     (topic, result) = ChannelPack.unpack_amop_topic_message(response)
     dataobj = json.loads(result)
    # print(dataobj)
     if dataobj["result"] == 0:
         self.ecb_manager.set_callback(filterid, eventcallback)
     return dataobj