Skip to content

Commit

Permalink
feat: add update event function
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Shinkarenko committed Oct 19, 2023
1 parent 3383960 commit e27e63e
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/event_reader_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -369,8 +370,8 @@ where
))
}

pub fn get_start_signature(self: Arc<Self>, resync_from_slot: u64) -> Result<()> {
let resync_start = match &self
pub async fn get_start_signature(self: &Arc<Self>, resync_from_slot: u64) -> Result<Option<Signature>> {
match &self
.client
.get_block(resync_from_slot)
.await
Expand All @@ -393,20 +394,10 @@ where
other => Err(Error::WrongConfig(format!(
"Unexpected format of EncodedTransaction: {other:?}",
))),
}?;
}
}

pub async fn hard_resync_event(self: Arc<Self>, resync_from_slot: u64) -> Result<()> {

let resync_start = self.get_start_signature(resync_from_slot - 1)?;

let signatures = <RpcClient as GetTransactionsSignaturesForAddress>::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::<Vec<_>>();

pub async fn update_events(self: Arc<Self>, signatures: Vec<Signature>) -> Result<()> {
let signatures_chunks = signatures
.as_slice()
.chunks(
Expand Down Expand Up @@ -496,6 +487,22 @@ where
Ok(())
}

pub async fn hard_resync_event(self: Arc<Self>, resync_from_slot: u64) -> Result<()> {

let resync_start = self.get_start_signature(resync_from_slot - 1).await?;

let signatures = <RpcClient as GetTransactionsSignaturesForAddress>::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::<Vec<_>>();

self.update_events(signatures).await?;

Ok(())
}

async fn resync_events(self: &Arc<Self>) -> Result<()> {
if !self.is_resync_enabled {
return Ok(());
Expand Down

0 comments on commit e27e63e

Please sign in to comment.