diff --git a/crates/ark-metadata/src/elasticsearch_manager.rs b/crates/ark-metadata/src/elasticsearch_manager.rs index 1f9092eff..823d7919d 100644 --- a/crates/ark-metadata/src/elasticsearch_manager.rs +++ b/crates/ark-metadata/src/elasticsearch_manager.rs @@ -1,5 +1,7 @@ use crate::types::{RequestError, TokenMetadata}; use async_trait::async_trait; +pub struct NoOpElasticsearchManager; + #[cfg(any(test, feature = "mock"))] use mockall::automock; @@ -15,3 +17,17 @@ pub trait ElasticsearchManager { metadata: TokenMetadata, ) -> Result<(), RequestError>; } + + +#[async_trait] +impl ElasticsearchManager for NoOpElasticsearchManager { + async fn upsert_token_metadata( + &self, + _contract_address: &str, + _token_id: &str, + _chain_id: &str, + _metadata: TokenMetadata, + ) -> Result<(), RequestError> { + Ok(()) + } +} diff --git a/crates/ark-metadata/src/metadata_manager.rs b/crates/ark-metadata/src/metadata_manager.rs index b62f66112..781203684 100644 --- a/crates/ark-metadata/src/metadata_manager.rs +++ b/crates/ark-metadata/src/metadata_manager.rs @@ -16,6 +16,7 @@ use starknet::core::types::{BlockId, BlockTag, FieldElement}; use starknet::macros::selector; use std::{str::FromStr, time::Duration}; use tracing::{debug, error, trace}; +use crate::elasticsearch_manager::NoOpElasticsearchManager; /// `MetadataManager` is responsible for managing metadata information related to tokens. /// It works with the underlying storage and Starknet client to fetch and update token metadata. @@ -24,13 +25,13 @@ pub struct MetadataManager< T: Storage, C: StarknetClient, F: FileManager, - E: ElasticsearchManager, + E: ElasticsearchManager = NoOpElasticsearchManager, > { storage: &'a T, starknet_client: &'a C, request_client: ReqwestClient, file_manager: &'a F, - elasticsearch_manager: &'a E, + elasticsearch_manager: Option<&'a E>, } pub struct MetadataMedia { @@ -70,7 +71,7 @@ impl<'a, T: Storage, C: StarknetClient, F: FileManager, E: ElasticsearchManager> storage: &'a T, starknet_client: &'a C, file_manager: &'a F, - elasticsearch_manager: &'a E, + elasticsearch_manager: Option<&'a E>, ) -> Self { MetadataManager { storage, @@ -185,10 +186,13 @@ impl<'a, T: Storage, C: StarknetClient, F: FileManager, E: ElasticsearchManager> .await .map_err(MetadataError::DatabaseError)?; - self.elasticsearch_manager - .upsert_token_metadata(contract_address, token_id, chain_id, token_metadata) - .await - .map_err(|e| MetadataError::ElasticSearchError(e.to_string()))?; + + if let Some(elasticsearch_manager) = self.elasticsearch_manager { + elasticsearch_manager + .upsert_token_metadata(contract_address, token_id, chain_id, token_metadata) + .await + .map_err(|e| MetadataError::ElasticSearchError(e.to_string()))?; + } Ok(()) }