get transactions/logs from different program, on a span of blocks

34 views Asked by At

Here is the situation:

I'm using Rust. I need to be able to "listen" to transaction, or at least logs from a list of solana program. I cannot use Websocket's "logsubscribe" function, as I would need multiple sockets for each program, and in case of disconnection, if I restart, I will have no way of getting the logs I missed. I do not need full history, only logs on recent blocks. If I cannot get the logs from block x to block y, getting logs of block x, x+1... y is also viable for me.

I couldn't find any good solution but to fetch a whole block, iterate over every transaction, get the program id, compare to my "list" of program, and if it matches, iterate over the logs until I find what I want. But that's actually a lot of iteration, and I couldn't figure out how to get the program id (as the the program_id method is only available on Legacy Message, and I get VersionedMessage from the logs

For now, Implementing the "parsing all and every transaction" method, I did this:

block.transactions.iter().for_each(|tx| {
let meta = tx.meta.clone().unwrap();
let logs = meta.log_messages;
if let solana_transaction_status::option_serializer::OptionSerializer::Some(e) = meta.inner_instructions {
//do smth
   }
       let tx = tx.transaction.decode().unwrap();
       let accs = tx.message.static_account_keys();
   };
}

But then I don't know how to get the right program id out of the account keys, so I can validate that the transaction is something I need.

0

There are 0 answers