def main(argv): global parser global client if len(argv) < 3: usage() exit(0) contractname = argv[0] address = argv[1] event_name = argv[2] indexed_value = argv[3:] try: print("usage input {},{},{},{}".format(contractname, address, event_name, indexed_value)) if address == "last": cn = ContractNote() address = cn.get_last(contractname) print("hex address :", address) abifile = "contracts/" + contractname + ".abi" parser = DatatypeParser(abifile) client = BcosClient() print(client.getinfo()) register_event_callback([address], event_name, indexed_value) except Exception as e: import traceback traceback.print_exc() client.finish() import time time.sleep(0.5) sys.exit(-1)
def start(self): print('client '+str(self.id)+" start") bcos_event = BcosEventCallback() bcos_event.setclient(BcosClient()) cn = ContractNote() address = cn.get_last('gmodel') abifile = "contracts/gmodel.abi" abiparser = DatatypeParser(abifile) eventcallback01 = EventCallbackImpl01(self.model,self.Update,self.Gmodel,self.cur_round,self.fdfs) eventcallback01.abiparser = abiparser print("register events") result = bcos_event.register_eventlog_filter( eventcallback01, abiparser, [address], 'modelupdate', None) print( "after register ,event_name:{},result:{},all:{}".format( 'modelupdate', result['result'], result)) #获取全局模型轮次 cur_round = self.Gmodel.get_round()[1][0] while(cur_round<5): print("the "+str(cur_round)+" th round") print("client "+str(self.id)+" waiting gmodel_update...") cur_round = self.Gmodel.get_round()[1][0] time.sleep(10)
def main(argv): if len(argv) < 2: usage() exit(0) contractname = argv[0] address = argv[1] event_name = None indexed_value = None if len(argv) > 2: event_name = argv[2] indexed_value = argv[3:] try: bcos_event = BcosEventCallback() if client_config.client_protocol is not client_config.PROTOCOL_CHANNEL: print( "** using event callback, client prototol MUST be client_config.PROTOCOL_CHANNEL!!" ) print("** please check the configure file") sys.exit(-1) bcos_event.setclient(BcosClient()) print(bcos_event.client.getinfo()) print("usage input {},{},{},{}".format(contractname, address, event_name, indexed_value)) print(address) if address == "last" or address == "latest": cn = ContractNote() address = cn.get_last(contractname) print("hex address :", address) abifile = "contracts/" + contractname + ".abi" abiparser = DatatypeParser(abifile) eventcallback01 = EventCallbackImpl01() eventcallback02 = EventCallbackImpl02() eventcallback01.abiparser = abiparser eventcallback02.abiparser = abiparser result = bcos_event.register_eventlog_filter(eventcallback01, abiparser, [address], event_name, indexed_value) #result = bcos_event.register_eventlog_filter(eventcallback02,abiparser, [address], "on_number") print("after register ,event_name:{},result:{},all:{}".format( event_name, result['result'], result)) while True: print("waiting event...") time.sleep(10) except Exception as e: print("Exception!") import traceback traceback.print_exc() finally: print("event callback finished!") if bcos_event.client is not None: bcos_event.client.finish() sys.exit(-1)
def on_push(self, packmsg: ChannelPack): print("EventPushHandler", packmsg.detail()) strmsg = packmsg.data.decode("utf-8") response = json.loads(strmsg) print("response filterID:", response['filterID']) #print("response:", json.dumps(response,indent=4)) loglist = parser.parse_event_logs(response["logs"]) print(json.dumps(loglist, indent=4)) # 从文件加载abi定义 abi_file = "contracts/HelloEvent.abi" parser = data_parser = DatatypeParser(abi_file) contract_abi = data_parser.contract_abi contractnode = ContractNote() address = contractnode.get_last("HelloEvent") print("event contract address is ", address) client = None client = BcosClient() info = client.getinfo() print("client info:", info) params_set = ["aaabbb"] params_setnum_5 = ["setnum_ab", 5] params_setnum_10 = ["setnum_ab", 10] params_settwo_1 = ["settwo_aabb", 10, 'key1'] params_settwo_2 = ["settwo_aabb", 10, 'key2'] ''' CHANNEL_RPC_REQUEST = 0x12, // type for rpc request