Skip to content

Commit

Permalink
fis: revert fund_agent to original
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-Morales committed Oct 3, 2023
1 parent 24d1acf commit 0261661
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 37 deletions.
4 changes: 2 additions & 2 deletions python/examples/06-send-tokens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class TransactionInfo(Model):
alice = Agent(name="alice", seed="alice secret phrase")
bob = Agent(name="bob", seed="bob secret phrase")

fund_agent_if_low(alice)
fund_agent_if_low(bob)
fund_agent_if_low(alice.wallet.address())
fund_agent_if_low(bob.wallet.address())


@alice.on_interval(period=10.0)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/08-local-network-interaction/agent1.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Message(Model):
endpoint=["http://127.0.0.1:8001/submit"],
)

fund_agent_if_low(bob)
fund_agent_if_low(bob.wallet.address())


@bob.on_message(model=Message)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/08-local-network-interaction/agent2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Message(Model):
endpoint=["http://127.0.0.1:8000/submit"],
)

fund_agent_if_low(alice)
fund_agent_if_low(alice.wallet.address())


@alice.on_interval(period=2.0)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/09-booking-protocol-demo/restaurant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
)

fund_agent_if_low(restaurant)
fund_agent_if_low(restaurant.wallet.address())

# build the restaurant agent from stock protocols and publish their details
restaurant.include(query_proto, publish_manifest=True)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/09-booking-protocol-demo/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
)

fund_agent_if_low(user)
fund_agent_if_low(user.wallet.address())

table_query = QueryTableRequest(
guests=3,
Expand Down
2 changes: 1 addition & 1 deletion python/examples/10-cleaning-demo/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
)

fund_agent_if_low(cleaner)
fund_agent_if_low(cleaner.wallet.address())


# build the cleaning service agent from the cleaning protocol
Expand Down
2 changes: 1 addition & 1 deletion python/examples/10-cleaning-demo/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
)

fund_agent_if_low(user)
fund_agent_if_low(user.wallet.address())

request = ServiceRequest(
user=user.name,
Expand Down
2 changes: 1 addition & 1 deletion python/examples/11-mailbox-agents/alice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Message(Model):
mailbox=f"{API_KEY}@wss://agentverse.ai",
)

fund_agent_if_low(agent)
fund_agent_if_low(agent.wallet.address())


@agent.on_message(model=Message, replies={Message})
Expand Down
2 changes: 1 addition & 1 deletion python/examples/11-mailbox-agents/bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Message(Model):
mailbox=f"{API_KEY}@wss://agentverse.ai",
)

fund_agent_if_low(agent)
fund_agent_if_low(agent.wallet.address())


@agent.on_interval(period=2.0)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/12-remote-agents/agent1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Message(Model):
endpoint=[f"{http_tunnel.public_url}/submit"],
)

fund_agent_if_low(alice)
fund_agent_if_low(alice.wallet.address())


@alice.on_message(model=Message)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/12-remote-agents/agent2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Message(Model):
endpoint=["http://127.0.0.1:8001/submit"],
)

fund_agent_if_low(bob)
fund_agent_if_low(bob.wallet.address())

ALICE_ADDRESS = "agent1qv2l7qzcd2g2rcv2p93tqflrcaq5dk7c2xc7fcnfq3s37zgkhxjmq5mfyvz"

Expand Down
4 changes: 2 additions & 2 deletions python/examples/13-agent-name-service/agent1.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class Message(Model):
endpoint=["http://localhost:8001/submit"],
)

fund_agent_if_low(bob)
fund_agent_if_low(bob.wallet.address())

my_wallet = LocalWallet.from_unsafe_seed("registration test wallet")
name_service_contract = get_name_service_contract()
DOMAIN = "agent"

faucet = get_faucet()
ledger = get_ledger(True)
ledger = get_ledger(test=True)
WALLET_BALANCE = ledger.query_bank_balance(my_wallet)

if WALLET_BALANCE < REGISTRATION_FEE:
Expand Down
2 changes: 1 addition & 1 deletion python/examples/13-agent-name-service/agent2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Message(Model):
endpoint=["http://localhost:8000/submit"],
)

fund_agent_if_low(alice)
fund_agent_if_low(alice.wallet.address())


@alice.on_interval(period=5)
Expand Down
6 changes: 3 additions & 3 deletions python/examples/14-broadcast/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
bob = Agent(name="bob", seed="bob recovery phrase")
charles = Agent(name="charles", seed="charles recovery phrase")

fund_agent_if_low(alice)
fund_agent_if_low(bob)
fund_agent_if_low(charles)
fund_agent_if_low(alice.wallet.address())
fund_agent_if_low(bob.wallet.address())
fund_agent_if_low(charles.wallet.address())


class BroadcastExampleRequest(Model):
Expand Down
25 changes: 8 additions & 17 deletions python/src/uagents/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,28 @@
LOGGER = get_logger("setup")


# pylint: disable=protected-access
def fund_agent_if_low(agent: Agent):
def fund_agent_if_low(wallet_address: str):
"""
Checks the agent's wallet balance and adds funds if it's below the registration fee.
Checks the agent's wallet balance and adds testnet funds if it's below the registration fee.
Args:
wallet_address (str): The wallet address of the agent.
Returns:
None
"""
ledger = get_ledger(agent._test)
ledger = get_ledger(test=True)
faucet = get_faucet()

agent_balance = ledger.query_bank_balance(Address(agent.wallet.address()))

if not agent._test:
LOGGER.warning(
"Faucet only available for testnet, please add FET tokens to your wallet "
f"{agent.wallet.address()}"
)
LOGGER.info(f"Current FET balance: {agent_balance}")
return
agent_balance = ledger.query_bank_balance(Address(wallet_address))

if agent_balance < REGISTRATION_FEE:
try:
LOGGER.info("Adding funds to agent...")
faucet.get_wealth(agent.wallet.address())
LOGGER.info("Adding funds to agent...complete")
LOGGER.info("Adding testnet funds to agent...")
faucet.get_wealth(wallet_address)
LOGGER.info("Adding testnet funds to agent...complete")
except Exception as ex:
LOGGER.error(f"Failed to add funds to agent: {str(ex)}")
LOGGER.error(f"Failed to add testnet funds to agent: {str(ex)}")


def register_agent_with_mailbox(agent: Agent, email: str):
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_agent_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestRegistration(unittest.IsolatedAsyncioTestCase):
async def test_almanac_registration(self):
agent = Agent(endpoint=["http://localhost:8000/submit"])

fund_agent_if_low(agent)
fund_agent_if_low(agent.wallet.address())

await agent.register()

Expand Down Expand Up @@ -48,7 +48,7 @@ async def test_name_service_registration(self):

domain = "agent"

fund_agent_if_low(agent)
fund_agent_if_low(agent.wallet.address())

await agent.register()

Expand Down

0 comments on commit 0261661

Please sign in to comment.