|
|
import asyncio |
|
|
from phi.tools import Toolkit |
|
|
from phi.utils.log import logger |
|
|
from src.libs.rpc_client import rpc_call |
|
|
|
|
|
class CryptoWalletTools(Toolkit): |
|
|
def __init__(self): |
|
|
super().__init__(name="crypto_wallet_tools") |
|
|
|
|
|
|
|
|
self.register(self.create_crypto_wallet) |
|
|
|
|
|
def create_crypto_wallet(self, user_email: str) -> str: |
|
|
""" |
|
|
Creates a crypto wallet account for the given user email. |
|
|
|
|
|
Parameters: |
|
|
user_email (str): The email of the user for whom the wallet is being created. |
|
|
|
|
|
Returns: |
|
|
str: A string representation of the response from the RPC call. |
|
|
|
|
|
Raises: |
|
|
None |
|
|
|
|
|
Note: |
|
|
This method uses asyncio.run() to run the asynchronous RPC call. |
|
|
""" |
|
|
logger.info(f"Creating crypto wallet account for {user_email}") |
|
|
|
|
|
params = { |
|
|
'userEmail': user_email, |
|
|
} |
|
|
response = asyncio.run(rpc_call(method_name="createLocalWallet", params=params)) |
|
|
return f"{response}" |
|
|
|
|
|
def get_crypto_wallet(self, user_email: str) -> str: |
|
|
""" |
|
|
Fetches the crypto wallet account for the given user email. |
|
|
|
|
|
Parameters: |
|
|
user_email (str): The email of the user for whom the wallet is being fetched. |
|
|
|
|
|
Returns: |
|
|
str: A string representation of the response from the RPC call. |
|
|
|
|
|
Raises: |
|
|
None |
|
|
|
|
|
Note: |
|
|
This method uses asyncio.run() to run the asynchronous RPC call. |
|
|
""" |
|
|
logger.info(f"Fetching crypto wallet account for {user_email}") |
|
|
|
|
|
params = { |
|
|
'userEmail': user_email, |
|
|
} |
|
|
response = asyncio.run(rpc_call(method_name="getLocalWallet", params=params)) |
|
|
return f"{response}" |
|
|
|
|
|
|
|
|
|