Add mock implementations for Solana dependencies
- Add graceful handling of missing Solana dependencies - Create mock implementations for Solana classes - Added all required __init__.py files to make modules importable - Update requirements.txt with missing dependencies
This commit is contained in:
parent
73b706f0eb
commit
572a7c0dd0
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
0
app/api/__init__.py
Normal file
0
app/api/__init__.py
Normal file
0
app/api/api_v1/__init__.py
Normal file
0
app/api/api_v1/__init__.py
Normal file
0
app/api/api_v1/endpoints/__init__.py
Normal file
0
app/api/api_v1/endpoints/__init__.py
Normal file
0
app/models/__init__.py
Normal file
0
app/models/__init__.py
Normal file
0
app/schemas/__init__.py
Normal file
0
app/schemas/__init__.py
Normal file
@ -3,15 +3,59 @@ import logging
|
|||||||
from typing import Dict, List, Optional, Any, Tuple
|
from typing import Dict, List, Optional, Any, Tuple
|
||||||
import base64
|
import base64
|
||||||
import base58
|
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__)
|
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
|
# Initialize Solana client
|
||||||
solana_client = Client(settings.SOLANA_RPC_URL)
|
solana_client = Client(settings.SOLANA_RPC_URL)
|
||||||
|
|
||||||
@ -57,6 +101,10 @@ def load_wallet_keypair() -> Optional[Keypair]:
|
|||||||
|
|
||||||
def get_wallet_balance() -> Dict[str, float]:
|
def get_wallet_balance() -> Dict[str, float]:
|
||||||
"""Get SOL and USDC balance for the configured wallet"""
|
"""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()
|
keypair = load_wallet_keypair()
|
||||||
if not keypair:
|
if not keypair:
|
||||||
return {"SOL": 0.0, "USDC": 0.0}
|
return {"SOL": 0.0, "USDC": 0.0}
|
||||||
@ -160,6 +208,10 @@ def send_transaction(transaction: Transaction, signers: List[Keypair], opts: Opt
|
|||||||
Returns:
|
Returns:
|
||||||
Tuple of (success, signature, error_message)
|
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:
|
try:
|
||||||
# Sign the transaction
|
# Sign the transaction
|
||||||
transaction.sign(*signers)
|
transaction.sign(*signers)
|
||||||
|
0
app/utils/__init__.py
Normal file
0
app/utils/__init__.py
Normal file
@ -11,4 +11,5 @@ loguru>=0.7.0
|
|||||||
python-dotenv>=1.0.0
|
python-dotenv>=1.0.0
|
||||||
ruff>=0.0.292
|
ruff>=0.0.292
|
||||||
httpx>=0.25.0
|
httpx>=0.25.0
|
||||||
pytest>=7.4.2
|
pytest>=7.4.2
|
||||||
|
base58>=2.1.1
|
Loading…
x
Reference in New Issue
Block a user