Skip to content

Commit

Permalink
feat: reregister if endpoint chenages
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Morales committed Apr 12, 2023
1 parent 828c52f commit 1d7bad4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/uagents/agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import functools
from re import S
from typing import Dict, List, Optional, Set, Union, Type, Tuple

from cosmpy.aerial.wallet import LocalWallet, PrivateKey
Expand Down Expand Up @@ -375,6 +376,7 @@ def start_background_tasks(self):
if (
not self._almanac_contract.is_registered(self.address)
or self._schedule_registration() < MIN_REGISTRATION_TIME
or self._endpoints != self._almanac_contract.get_endpoints(self.address)
):
self._loop.create_task(
_run_interval(
Expand Down
8 changes: 8 additions & 0 deletions src/uagents/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def get_expiry(self, address: str):

return (expiry - height) * BLOCK_INTERVAL

def get_endpoints(self, address: str):
query_msg = {"query_records": {"agent_address": address}}
response = self.query(query_msg)

if not response["record"]:
return 0
return response.get("record")[0]["record"]["service"]["endpoints"]

def get_registration_msg(
self,
protocols: Dict,
Expand Down

0 comments on commit 1d7bad4

Please sign in to comment.