Skip to content

Commit

Permalink
feat: updates to match aname contract-V2
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Morales committed Jan 23, 2024
1 parent dc9cda9 commit 8258480
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion python/src/uagents/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"fetch1479lwv5vy8skute5cycuz727e55spkhxut0valrcm38x9caa2x8q99ef0q"
)
TESTNET_CONTRACT_NAME_SERVICE = (
"fetch1mxz8kn3l5ksaftx8a9pj9a6prpzk2uhxnqdkwuqvuh37tw80xu6qges77l"
"fetch1kewgfwxwtuxcnppr547wj6sd0e5fkckyp48dazsh89hll59epgpspmh0tn"
)
REGISTRATION_FEE = 500000000000000000
REGISTRATION_DENOM = "atestfet"
Expand Down
38 changes: 26 additions & 12 deletions python/src/uagents/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def is_domain_public(self, domain: str):
Returns:
bool: True if the domain is public, False otherwise.
"""
res = self.query({"domain_record": {"domain": f".{domain}"}})
res = self.query({"domain_record": {"domain": f"VAL.{domain}"}})
return res["is_public"]

def get_registration_tx(
Expand All @@ -370,24 +370,38 @@ def get_registration_tx(
Optional[Transaction]: The registration transaction, or None if the name is not
available or not owned by the wallet address.
"""
if not self.is_name_available(name, domain) and not self.is_owner(
name, domain, wallet_address
):
transaction = Transaction()

contract = (
TESTNET_CONTRACT_NAME_SERVICE if test else MAINNET_CONTRACT_NAME_SERVICE
)

if self.is_name_available(name, domain):
price_per_second = self.query({"contract_state": {}})["price_per_second"]
amount = int(price_per_second["amount"]) * 86400
denom = price_per_second["denom"]

registration_msg = {"register": {"domain": f"{name}.{domain}"}}

transaction.add_message(
create_cosmwasm_execute_msg(
wallet_address, contract, registration_msg, funds=f"{amount}{denom}"
)
)
elif not self.is_owner(name, domain, wallet_address):
return None

registration_msg = {
"register": {
agent_record = {"address": agent_address, "weight": 1}

record_msg = {
"update_record": {
"domain": f"{name}.{domain}",
"agent_address": agent_address,
"agent_records": [agent_record],
}
}

contract = (
TESTNET_CONTRACT_NAME_SERVICE if test else MAINNET_CONTRACT_NAME_SERVICE
)
transaction = Transaction()
transaction.add_message(
create_cosmwasm_execute_msg(wallet_address, contract, registration_msg)
create_cosmwasm_execute_msg(wallet_address, contract, record_msg)
)

return transaction
Expand Down

0 comments on commit 8258480

Please sign in to comment.