subscription works
This commit is contained in:
@ -189,30 +189,43 @@ async def follow_move(move):
|
||||
await send_telegram_message(message)
|
||||
|
||||
async def on_logs(log):
|
||||
print(f"Received log: {log}")
|
||||
if 'err' in log and log['err']:
|
||||
return
|
||||
|
||||
tx = log['signature']
|
||||
tx_result = await solana_client.get_transaction(tx)
|
||||
|
||||
if tx_result and 'result' in tx_result and tx_result['result']:
|
||||
transaction = tx_result['result']['transaction']
|
||||
message = transaction['message']
|
||||
for instruction in message['instructions']:
|
||||
if instruction['programId'] == TOKEN_ADDRESSES['SOL']:
|
||||
# This is a token transfer
|
||||
from_pubkey = instruction['accounts'][0]
|
||||
to_pubkey = instruction['accounts'][1]
|
||||
amount = int(instruction['data'], 16) / 1e9 # Convert lamports to SOL
|
||||
|
||||
if from_pubkey == FOLLOWED_WALLET:
|
||||
move = {
|
||||
'token': 'SOL',
|
||||
'amount': amount,
|
||||
'to_token': 'Unknown' # You might want to determine this based on the receiving address
|
||||
}
|
||||
await follow_move(move)
|
||||
try:
|
||||
print(f"Received log: {log}")
|
||||
if 'err' in log and log['err']:
|
||||
return
|
||||
|
||||
if 'value' in log and 'logs' in log['value']:
|
||||
tx = log['value']['signature']
|
||||
logs = log['value']['logs']
|
||||
|
||||
# Fetch transaction details
|
||||
tx_result = await solana_client.get_transaction(tx)
|
||||
|
||||
if tx_result and 'result' in tx_result and tx_result['result']:
|
||||
transaction = tx_result['result']['transaction']
|
||||
message = transaction['message']
|
||||
|
||||
for log_entry in logs:
|
||||
if 'Program log: Instruction: Swap' in log_entry:
|
||||
# Handle swap event
|
||||
for instruction in message['instructions']:
|
||||
if instruction['programId'] == TOKEN_ADDRESSES['SOL']:
|
||||
# This is a token transfer
|
||||
from_pubkey = instruction['accounts'][0]
|
||||
to_pubkey = instruction['accounts'][1]
|
||||
amount = int(instruction['data'], 16) / 1e9 # Convert lamports to SOL
|
||||
|
||||
if from_pubkey == FOLLOWED_WALLET:
|
||||
move = {
|
||||
'token': 'SOL',
|
||||
'amount': amount,
|
||||
'to_token': 'Unknown' # You might want to determine this based on the receiving address
|
||||
}
|
||||
await follow_move(move)
|
||||
else:
|
||||
print(f"Unexpected log format: {log}")
|
||||
except:
|
||||
print(f"error logging: {log}")
|
||||
async def subscribe_to_wallet():
|
||||
uri = SOLANA_URL
|
||||
async with websockets.connect(uri) as websocket:
|
||||
|
Reference in New Issue
Block a user