feat: listening the new task from blockchain
This commit is contained in:
parent
7fa71768e1
commit
feb25fc894
@ -82,7 +82,7 @@ class NodeManager():
|
|||||||
self.scheduler = Scheduler(self.w3, SCHEDULER_ADDR, SCHEDULER_ABI_FILE)
|
self.scheduler = Scheduler(self.w3, SCHEDULER_ADDR, SCHEDULER_ABI_FILE)
|
||||||
self.wallet = self.w3.eth.account.from_key(WALLET_KEY)
|
self.wallet = self.w3.eth.account.from_key(WALLET_KEY)
|
||||||
print(f"We have use {WEB3_PROVIDER_URL+WEB3_PROVIDER_KEY} as the web3 provider.")
|
print(f"We have use {WEB3_PROVIDER_URL+WEB3_PROVIDER_KEY} as the web3 provider.")
|
||||||
print(f"And we have load your wallet private key {WALLET_KEY}")
|
print(f"And we have load your wallet private key {WALLET_KEY} (address={self.wallet.address})")
|
||||||
print()
|
print()
|
||||||
if self.w3.is_connected():
|
if self.w3.is_connected():
|
||||||
print("Connected Successfully.")
|
print("Connected Successfully.")
|
||||||
@ -102,6 +102,8 @@ class NodeManager():
|
|||||||
# start waiting
|
# start waiting
|
||||||
print("\nWaiting for the new task from Sepolia testnet...")
|
print("\nWaiting for the new task from Sepolia testnet...")
|
||||||
self.cluster_communication_module.start_listen_task()
|
self.cluster_communication_module.start_listen_task()
|
||||||
|
next_task = self.scheduler.listen_task(self.wallet.address)
|
||||||
|
print(next_task)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("[ERROR] Connected Failed.")
|
print("[ERROR] Connected Failed.")
|
||||||
|
|||||||
@ -48,3 +48,12 @@ class Scheduler():
|
|||||||
def get_cluster_event(self, receipt):
|
def get_cluster_event(self, receipt):
|
||||||
event = self.contract.events.RegisterCluster().process_receipt(receipt)
|
event = self.contract.events.RegisterCluster().process_receipt(receipt)
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
def listen_task(self, address):
|
||||||
|
event_filter = self.contract.events.StartRun.create_filter(fromBlock='latest')
|
||||||
|
while True:
|
||||||
|
for event in event_filter.get_new_entries():
|
||||||
|
if event['args']['provider'] == address:
|
||||||
|
return event
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user