Solana v1.r
Solana v1.r
import requests
import asyncio
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
CHECK_INTERVAL = 60 # seconds
# Command Handlers
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Send a welcome message with instructions."""
await update.message.reply_text(
"Welcome to the Solana Wallet Tracker Bot! Use the following commands:\n"
"/track <wallet_address> <name> - Start tracking a wallet.\n"
"/list - List all wallets you are tracking.\n"
"/delete <wallet_address> - Stop tracking a specific wallet."
)
user_id = update.message.from_user.id
wallet_address = args[0]
name = " ".join(args[1:])
if not is_valid_wallet(wallet_address):
await update.message.reply_text(f"Invalid wallet address:
{wallet_address}")
return
if wallet_address in tracked_wallets[user_id]:
await update.message.reply_text(f"Wallet '{name}' ({wallet_address}) is
already being tracked.")
return
if not user_wallets:
await update.message.reply_text("You are not tracking any wallets.")
return
user_id = update.message.from_user.id
wallet_address = args[0]
# Background Monitoring
async def monitor_wallet(user_id: int, wallet_address: str, name: str):
"""Monitor a wallet for new transactions."""
while wallet_address in tracked_wallets.get(user_id, {}):
try:
logger.info(f"Monitoring wallet {name} ({wallet_address}) for user
{user_id}.")
transactions = await get_transactions(wallet_address)
for tx in transactions:
signature = tx['signature']
if signature not in seen_signatures[user_id][wallet_address]:
seen_signatures[user_id][wallet_address].add(signature)
await notify_user(user_id, name, wallet_address, signature)
except Exception as e:
logger.error(f"Error monitoring wallet {wallet_address}: {e}")
await asyncio.sleep(CHECK_INTERVAL)
# Helper Function
async def get_transactions(wallet_address):
"""Fetch transactions using Solscan API."""
url = f"https://api.solscan.io/account/transaction?address={wallet_address}"
# Main Function
def main():
application = Application.builder().token(TELEGRAM_TOKEN).build()
if __name__ == '__main__':
main()