From e27e63e04d6be5e766b10a38689f61c3d0c8fb6c Mon Sep 17 00:00:00 2001 From: Bogdan Shinkarenko Date: Thu, 19 Oct 2023 13:43:59 +1000 Subject: [PATCH] feat: add update event function --- src/event_reader_service.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/event_reader_service.rs b/src/event_reader_service.rs index d54c662..38757f8 100644 --- a/src/event_reader_service.rs +++ b/src/event_reader_service.rs @@ -22,6 +22,7 @@ use crate::{ transaction_parser::{BindTransactionInstructionLogs, TransactionParsedMeta}, }; use de_solana_client::GetTransactionsSignaturesForAddress; +use solana_sdk::signature::Signature; use solana_transaction_status::EncodedTransaction; macro_rules! unwrap_or_continue { @@ -369,8 +370,8 @@ where )) } - pub fn get_start_signature(self: Arc, resync_from_slot: u64) -> Result<()> { - let resync_start = match &self + pub async fn get_start_signature(self: &Arc, resync_from_slot: u64) -> Result> { + match &self .client .get_block(resync_from_slot) .await @@ -393,20 +394,10 @@ where other => Err(Error::WrongConfig(format!( "Unexpected format of EncodedTransaction: {other:?}", ))), - }?; + } } - pub async fn hard_resync_event(self: Arc, resync_from_slot: u64) -> Result<()> { - - let resync_start = self.get_start_signature(resync_from_slot - 1)?; - - let signatures = ::get_signatures_data_for_address_with_config( - &self.client, - &self.program_id, - self.commitment_config, - resync_start - ).await?.iter().map(|sig_data| sig_data.signature).collect::>(); - + pub async fn update_events(self: Arc, signatures: Vec) -> Result<()> { let signatures_chunks = signatures .as_slice() .chunks( @@ -496,6 +487,22 @@ where Ok(()) } + pub async fn hard_resync_event(self: Arc, resync_from_slot: u64) -> Result<()> { + + let resync_start = self.get_start_signature(resync_from_slot - 1).await?; + + let signatures = ::get_signatures_data_for_address_with_config( + &self.client, + &self.program_id, + self.commitment_config, + resync_start + ).await?.iter().map(|sig_data| sig_data.signature).collect::>(); + + self.update_events(signatures).await?; + + Ok(()) + } + async fn resync_events(self: &Arc) -> Result<()> { if !self.is_resync_enabled { return Ok(());