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