diff --git a/applications/tari_indexer/src/event_manager.rs b/applications/tari_indexer/src/event_manager.rs index 2d4652b7f..c338f83a8 100644 --- a/applications/tari_indexer/src/event_manager.rs +++ b/applications/tari_indexer/src/event_manager.rs @@ -77,18 +77,18 @@ impl EventManager { version: u64, timestamp: u64, ) -> Result<(), anyhow::Error> { - let mut tx = self.substate_store.create_write_tx()?; - let new_event = NewEvent { - substate_id: Some(substate_id.to_string()), - template_address: template_address.to_string(), - tx_hash: tx_hash.to_string(), - topic, - payload: payload.to_json().expect("Failed to convert to JSON"), - version: version as i32, - timestamp: timestamp as i64, - }; - tx.save_event(new_event)?; - tx.commit()?; + self.substate_store.with_write_tx(|tx| { + let new_event = NewEvent { + substate_id: Some(substate_id.to_string()), + template_address: template_address.to_string(), + tx_hash: tx_hash.to_string(), + topic, + payload: payload.to_json().expect("Failed to convert to JSON"), + version: version as i32, + timestamp: timestamp as i64, + }; + tx.save_event(new_event) + })?; Ok(()) } diff --git a/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs b/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs index cf42dce0f..aabda07fd 100644 --- a/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs +++ b/applications/tari_indexer/src/substate_storage_sqlite/sqlite_substate_store_factory.rs @@ -177,6 +177,7 @@ impl<'a> SqliteSubstateStoreReadTransaction<'a> { } } +// TODO: remove the allow dead_code attributes as these become used. pub trait SubstateStoreReadTransaction { fn list_substates( &mut self, @@ -186,13 +187,17 @@ pub trait SubstateStoreReadTransaction { offset: Option, ) -> Result, StorageError>; fn get_substate(&mut self, address: &SubstateId) -> Result, StorageError>; + #[allow(dead_code)] fn get_latest_version_for_substate(&mut self, address: &SubstateId) -> Result, StorageError>; + #[allow(dead_code)] fn get_all_addresses(&mut self) -> Result, StorageError>; #[allow(dead_code)] fn get_all_substates(&mut self) -> Result, StorageError>; fn get_non_fungible_collections(&mut self) -> Result, StorageError>; fn get_non_fungible_count(&mut self, resource_address: String) -> Result; + #[allow(dead_code)] fn get_non_fungible_latest_index(&mut self, resource_address: String) -> Result, StorageError>; + #[allow(dead_code)] fn get_non_fungibles( &mut self, resource_address: String, @@ -629,12 +634,16 @@ impl<'a> SqliteSubstateStoreWriteTransaction<'a> { } } +// TODO: remove the allow dead_code attributes as these become used. pub trait SubstateStoreWriteTransaction { fn commit(self) -> Result<(), StorageError>; fn rollback(self) -> Result<(), StorageError>; fn set_substate(&mut self, new_substate: NewSubstate) -> Result<(), StorageError>; + #[allow(dead_code)] fn delete_substate(&mut self, address: String) -> Result<(), StorageError>; + #[allow(dead_code)] fn clear_substates(&mut self) -> Result<(), StorageError>; + #[allow(dead_code)] fn add_non_fungible_index(&mut self, new_nft_index: NewNonFungibleIndex) -> Result<(), StorageError>; fn save_event(&mut self, new_event: NewEvent) -> Result<(), StorageError>; fn save_scanned_block_id(&mut self, new_scanned_block_id: NewScannedBlockId) -> Result<(), StorageError>;