From 08d6a6ac478f357f04995e7800b1d8c2ffec6b21 Mon Sep 17 00:00:00 2001 From: Valentine Date: Fri, 6 Oct 2023 03:05:33 +0300 Subject: [PATCH] clears state in flush_updates --- crates/wasm/src/view_server.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/wasm/src/view_server.rs b/crates/wasm/src/view_server.rs index da2df7e099..02d11f481f 100644 --- a/crates/wasm/src/view_server.rs +++ b/crates/wasm/src/view_server.rs @@ -62,6 +62,8 @@ pub struct ViewServer { denoms: BTreeMap, nct: Tree, storage: IndexedDBStorage, + last_position: Option, + last_forgotten: Option, } #[wasm_bindgen] @@ -94,6 +96,8 @@ impl ViewServer { nct: tree, swaps: Default::default(), storage: IndexedDBStorage::new(constants).await?, + last_position: None, + last_forgotten: None, }; Ok(view_server) } @@ -248,35 +252,33 @@ impl ViewServer { /// Get new notes, swaps, SCT state updates /// Function also clears state - /// Arguments: - /// last_position: `Option` - /// last_forgotten: `Option` /// Returns: `ScanBlockResult` #[wasm_bindgen] pub fn flush_updates( &mut self, - last_position: JsValue, - last_forgotten: JsValue, ) -> WasmResult { - let stored_position: Option = - serde_wasm_bindgen::from_value(last_position)?; - let stored_forgotten: Option = serde_wasm_bindgen::from_value(last_forgotten)?; let nct_updates: Updates = self .nct .updates( - stored_position.unwrap_or_default(), - stored_forgotten.unwrap_or_default(), + self.last_position.unwrap_or_default(), + self.last_forgotten.unwrap_or_default(), ) .collect::(); let updates = ScanBlockResult { height: self.latest_height, - nct_updates, + nct_updates: nct_updates.clone(), new_notes: self.notes.clone().into_values().collect(), new_swaps: self.swaps.clone().into_values().collect(), }; + self.notes = Default::default(); + self.swaps = Default::default(); + + self.last_position= nct_updates.set_position; + self.last_forgotten = nct_updates.set_forgotten; + let result = serde_wasm_bindgen::to_value(&updates)?; Ok(result) }