diff --git a/crates/torii/core/src/executor/erc.rs b/crates/torii/core/src/executor/erc.rs index e25fa77af2..2f4225f345 100644 --- a/crates/torii/core/src/executor/erc.rs +++ b/crates/torii/core/src/executor/erc.rs @@ -242,9 +242,18 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> { "Failed to fetch metadata for token_id: {}", register_erc721_token.actual_token_id ) - })?; + }); - serde_json::to_string(&metadata).context("Failed to serialize metadata")? + if let Ok(metadata) = metadata { + serde_json::to_string(&metadata).context("Failed to serialize metadata")? + } else { + warn!( + contract_address = format!("{:#x}", register_erc721_token.contract_address), + token_id = %register_erc721_token.actual_token_id, + "Error fetching metadata, empty metadata will be used instead.", + ); + "".to_string() + } }; Ok(RegisterErc721TokenMetadata { query: register_erc721_token, metadata, name, symbol }) diff --git a/crates/torii/core/src/executor/mod.rs b/crates/torii/core/src/executor/mod.rs index ac6580274f..82022d191a 100644 --- a/crates/torii/core/src/executor/mod.rs +++ b/crates/torii/core/src/executor/mod.rs @@ -679,8 +679,6 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> { self.register_tasks.spawn(async move { let permit = semaphore.acquire().await.unwrap(); - let span = tracing::span!(tracing::Level::INFO, "contract_address_span", contract_address = %register_erc721_token.contract_address); - let _enter = span.enter(); let result = Self::process_register_erc721_token_query( register_erc721_token, diff --git a/crates/torii/graphql/src/object/erc/token_balance.rs b/crates/torii/graphql/src/object/erc/token_balance.rs index ab018822e2..db006dfea0 100644 --- a/crates/torii/graphql/src/object/erc/token_balance.rs +++ b/crates/torii/graphql/src/object/erc/token_balance.rs @@ -103,7 +103,10 @@ async fn fetch_token_balances( JOIN tokens t ON b.token_id = t.id JOIN contracts c ON t.contract_address = c.contract_address" ); - let mut conditions = vec!["b.account_address = ?".to_string()]; + let mut conditions = vec![ + "(b.account_address = ?)".to_string(), + "(t.metadata IS NULL OR length(t.metadata) > 0)".to_string(), + ]; let mut cursor_param = &connection.after; if let Some(after_cursor) = &connection.after { @@ -234,14 +237,9 @@ fn token_balances_connection_output<'a>( let token_id = row.token_id.split(':').collect::>(); assert!(token_id.len() == 2); - // skip the token if metadata is null - if row.metadata.is_none() { - continue; - } - let metadata_str = row.metadata.as_ref().unwrap(); - + let metadata_str = row.metadata; let metadata: serde_json::Value = - serde_json::from_str(metadata_str).expect("metadata is always json"); + serde_json::from_str(&metadata_str).expect("metadata is always json"); let metadata_name = metadata.get("name").map(|v| v.to_string().trim_matches('"').to_string()); let metadata_description = metadata @@ -301,5 +299,5 @@ struct BalanceQueryResultRaw { pub token_id: String, pub balance: String, pub contract_type: String, - pub metadata: Option, + pub metadata: String, } diff --git a/crates/torii/graphql/src/object/erc/token_transfer.rs b/crates/torii/graphql/src/object/erc/token_transfer.rs index 0053db28dc..31bf30776d 100644 --- a/crates/torii/graphql/src/object/erc/token_transfer.rs +++ b/crates/torii/graphql/src/object/erc/token_transfer.rs @@ -119,7 +119,10 @@ JOIN "#, ); - let mut conditions = vec!["et.from_address = ? OR et.to_address = ?".to_string()]; + let mut conditions = vec![ + "(et.from_address = ? OR et.to_address = ?)".to_string(), + "(t.metadata IS NULL OR length(t.metadata) > 0)".to_string(), + ]; let mut cursor_param = &connection.after; if let Some(after_cursor) = &connection.after { @@ -263,14 +266,9 @@ fn token_transfers_connection_output<'a>( let token_id = row.token_id.split(':').collect::>(); assert!(token_id.len() == 2); - // skip the token if metadata is null - if row.metadata.is_none() { - continue; - } - - let metadata_str = row.metadata.as_ref().unwrap(); + let metadata_str = row.metadata; let metadata: serde_json::Value = - serde_json::from_str(metadata_str).expect("metadata is always json"); + serde_json::from_str(&metadata_str).expect("metadata is always json"); let metadata_name = metadata.get("name").map(|v| v.to_string().trim_matches('"').to_string()); let metadata_description = metadata @@ -339,7 +337,7 @@ struct TransferQueryResultRaw { pub symbol: String, pub decimals: u8, pub contract_type: String, - pub metadata: Option, + pub metadata: String, } #[derive(Debug, Clone)]