-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new almanac and name service registration flow (#114)
Co-authored-by: James Riehl <[email protected]> Co-authored-by: James Riehl <[email protected]>
- Loading branch information
1 parent
01ae9d1
commit b8569a5
Showing
9 changed files
with
304 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from cosmpy.aerial.wallet import LocalWallet | ||
|
||
from uagents.network import get_ledger, get_name_service_contract | ||
from uagents.setup import fund_agent_if_low | ||
from uagents import Agent, Context, Model | ||
|
||
|
||
# NOTE: Run agent1.py before running agent2.py | ||
|
||
|
||
class Message(Model): | ||
message: str | ||
|
||
|
||
bob = Agent( | ||
name="bob-0", | ||
seed="agent bob-0 secret phrase", | ||
port=8001, | ||
endpoint=["http://localhost:8001/submit"], | ||
) | ||
|
||
ledger = get_ledger() | ||
my_wallet = LocalWallet.from_unsafe_seed("registration test wallet") | ||
name_service_contract = get_name_service_contract() | ||
DOMAIN = "agent" | ||
|
||
for wallet in [my_wallet, bob.wallet]: | ||
fund_agent_if_low(wallet.address()) | ||
|
||
|
||
@bob.on_event("startup") | ||
async def register_agent_name(ctx: Context): | ||
await name_service_contract.register( | ||
ledger, my_wallet, ctx.address, ctx.name, DOMAIN | ||
) | ||
|
||
|
||
@bob.on_message(model=Message) | ||
async def message_handler(ctx: Context, sender: str, msg: Message): | ||
ctx.logger.info(f"Received message from {sender}: {msg.message}") | ||
|
||
|
||
if __name__ == "__main__": | ||
bob.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from uagents.setup import fund_agent_if_low | ||
from uagents import Agent, Context, Model | ||
|
||
|
||
class Message(Model): | ||
message: str | ||
|
||
|
||
alice = Agent( | ||
name="alice-0", | ||
seed="agent alice-0 secret phrase", | ||
port=8000, | ||
endpoint=["http://localhost:8000/submit"], | ||
) | ||
|
||
|
||
fund_agent_if_low(alice.wallet.address()) | ||
|
||
|
||
@alice.on_interval(period=5) | ||
async def alice_interval_handler(ctx: Context): | ||
bob_name = "bob-0.agent" | ||
ctx.logger.info(f"Sending message to {bob_name}...") | ||
await ctx.send(bob_name, Message(message="Hello there bob.")) | ||
|
||
|
||
if __name__ == "__main__": | ||
alice.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.