diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/__init__.py b/app/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/api_v1/__init__.py b/app/api/api_v1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/api_v1/endpoints/__init__.py b/app/api/api_v1/endpoints/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/services/solana.py b/app/services/solana.py index 9d09669..0e91318 100644 --- a/app/services/solana.py +++ b/app/services/solana.py @@ -3,15 +3,59 @@ import logging from typing import Dict, List, Optional, Any, Tuple import base64 import base58 -from solana.rpc.api import Client -from solana.keypair import Keypair -from solana.transaction import Transaction -from solana.rpc.types import TxOpts - -from app.core.config import settings logger = logging.getLogger(__name__) +# Try to import Solana packages, otherwise use mock implementations +try: + from solana.rpc.api import Client + from solana.publickey import PublicKey + from solana.keypair import Keypair + from solana.transaction import Transaction + from solana.rpc.types import TxOpts + SOLANA_AVAILABLE = True +except ImportError: + logger.warning("Solana package not available. Using mock implementations.") + SOLANA_AVAILABLE = False + # Mock classes for when solana package is not available + class Client: + def __init__(self, endpoint): + self.endpoint = endpoint + + def get_balance(self, *args, **kwargs): + return {"result": {"value": 0}} + + def get_token_accounts_by_owner(self, *args, **kwargs): + return {"result": {"value": []}} + + def get_token_supply(self, *args, **kwargs): + return {"result": {"value": {"decimals": 9}}} + + def send_transaction(self, *args, **kwargs): + return {"error": {"message": "Solana package not available"}} + + class PublicKey: + def __init__(self, key): + self.key = key + + class Keypair: + @classmethod + def from_secret_key(cls, *args, **kwargs): + return cls() + + @property + def public_key(self): + return PublicKey("mock") + + class Transaction: + def sign(self, *args, **kwargs): + pass + + class TxOpts: + pass + +from app.core.config import settings + # Initialize Solana client solana_client = Client(settings.SOLANA_RPC_URL) @@ -57,6 +101,10 @@ def load_wallet_keypair() -> Optional[Keypair]: def get_wallet_balance() -> Dict[str, float]: """Get SOL and USDC balance for the configured wallet""" + if not SOLANA_AVAILABLE: + logger.warning("Solana package not available. Returning mock balances.") + return {"SOL": 0.0, "USDC": 0.0} + keypair = load_wallet_keypair() if not keypair: return {"SOL": 0.0, "USDC": 0.0} @@ -160,6 +208,10 @@ def send_transaction(transaction: Transaction, signers: List[Keypair], opts: Opt Returns: Tuple of (success, signature, error_message) """ + if not SOLANA_AVAILABLE: + logger.warning("Solana package not available. Cannot send transaction.") + return False, "", "Solana package not available" + try: # Sign the transaction transaction.sign(*signers) diff --git a/app/utils/__init__.py b/app/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index f854a88..d622bbd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,5 @@ loguru>=0.7.0 python-dotenv>=1.0.0 ruff>=0.0.292 httpx>=0.25.0 -pytest>=7.4.2 \ No newline at end of file +pytest>=7.4.2 +base58>=2.1.1 \ No newline at end of file