solana subscription works!!!
This commit is contained in:
parent
02c1ee7ed4
commit
96601194e0
@ -18,8 +18,9 @@ import base64
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
load_dotenv()
|
||||
app = Flask(__name__)
|
||||
|
||||
# Use the production Solana RPC endpoint
|
||||
@ -84,25 +85,32 @@ async def get_wallet_balances(wallet_address):
|
||||
encoding="jsonParsed" # Ensure encoding is set to jsonParsed
|
||||
)
|
||||
|
||||
# Get all token accounts for the wallet
|
||||
response = await solana_client.get_token_accounts_by_owner(
|
||||
Pubkey.from_string(wallet_address),
|
||||
opts,
|
||||
commitment=Confirmed
|
||||
)
|
||||
try:
|
||||
# Get all token accounts for the wallet
|
||||
response = await solana_client.get_token_accounts_by_owner(
|
||||
Pubkey.from_string(wallet_address),
|
||||
opts,
|
||||
commitment=Confirmed
|
||||
)
|
||||
|
||||
if response.value:
|
||||
for account in response.value:
|
||||
mint = account.account.data.parsed.info.mint
|
||||
balance_response = await solana_client.get_token_account_balance(account.pubkey)
|
||||
if balance_response.value:
|
||||
amount = float(balance_response.value.uiAmount)
|
||||
balances[mint] = amount
|
||||
logging.debug(f"Balance for {mint}: {amount}")
|
||||
if response.value:
|
||||
for account in response.value:
|
||||
if 'parsed' in account.account.data and 'info' in account.account.data.parsed:
|
||||
mint = account.account.data.parsed.info.mint
|
||||
balance_response = await solana_client.get_token_account_balance(account.pubkey)
|
||||
if balance_response.value:
|
||||
amount = float(balance_response.value.uiAmount)
|
||||
balances[mint] = amount
|
||||
logging.debug(f"Balance for {mint}: {amount}")
|
||||
else:
|
||||
logging.warning(f"Unexpected data format for account: {account}")
|
||||
|
||||
sol_balance = await solana_client.get_balance(Pubkey.from_string(wallet_address))
|
||||
if sol_balance.value:
|
||||
balances['SOL'] = sol_balance.value / 1e9
|
||||
sol_balance = await solana_client.get_balance(Pubkey.from_string(wallet_address))
|
||||
if sol_balance.value:
|
||||
balances['SOL'] = sol_balance.value / 1e9
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"Error getting wallet balances: {str(e)}")
|
||||
|
||||
return balances
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user