Skip to content

Commit

Permalink
feat: reduce the number of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyrd committed Jan 30, 2025
1 parent 174c995 commit c1fe5fa
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 246 deletions.
4 changes: 2 additions & 2 deletions crates/rust-client/src/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ impl NoteUpdates {

pub fn insert_or_ignore_notes(
&mut self,
input_notes: &Vec<InputNoteRecord>,
output_notes: &Vec<OutputNoteRecord>,
input_notes: &[InputNoteRecord],
output_notes: &[OutputNoteRecord],
) {
for note in input_notes {
self.updated_input_notes.entry(note.id()).or_insert(note.clone());
Expand Down
39 changes: 6 additions & 33 deletions crates/rust-client/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ pub use tag::{NoteTagRecord, NoteTagSource};

mod state_sync;
pub use state_sync::{
on_block_received, on_note_received, on_nullifier_received, on_transaction_committed,
OnNoteReceived, OnNullifierReceived, OnTransactionCommitted, StateSync, StateSyncUpdate,
on_note_received, on_nullifier_received, OnNoteReceived, OnNullifierReceived, StateSync,
StateSyncUpdate,
};

/// Contains stats about the sync operation.
Expand Down Expand Up @@ -182,51 +182,24 @@ impl<R: FeltRng> Client<R> {
self.rpc_api.clone(),
Box::new({
let store_clone = self.store.clone();
move |note_updates, committed_note, block_header| {
move |note_updates, committed_note, block_header, new_public_notes| {
Box::pin(on_note_received(
store_clone.clone(),
note_updates,
committed_note,
block_header,
new_public_notes,
))
}
}),
Box::new({
let store_clone = self.store.clone();
move |note_updates, transaction_update| {
Box::pin(on_transaction_committed(
store_clone.clone(),
note_updates,
transaction_update,
))
}
}),
Box::new({
let store_clone = self.store.clone();
move |note_updates, nullifier_update| {
move |note_updates, nullifier_update, committed_transactions| {
Box::pin(on_nullifier_received(
store_clone.clone(),
note_updates,
nullifier_update,
))
}
}),
Box::new({
let store_clone = self.store.clone();
move |new_block_header,
note_updates,
current_block_header,
current_block_has_relevant_notes,
current_partial_mmr,
mmr_delta| {
Box::pin(on_block_received(
store_clone.clone(),
new_block_header,
note_updates,
current_block_header,
current_block_has_relevant_notes,
current_partial_mmr,
mmr_delta,
committed_transactions,
))
}
}),
Expand Down
Loading

0 comments on commit c1fe5fa

Please sign in to comment.