From 2c6d19cff672e9fb573971b7c90b935d44a4f5dc Mon Sep 17 00:00:00 2001 From: Nicolas Pennie Date: Fri, 30 Jun 2023 12:40:55 -0700 Subject: [PATCH] fix(ingester): allow empty json uris (#72) --- .../token_metadata/mod.rs | 7 ++++-- .../token_metadata/v1_asset.rs | 22 +++++++++++-------- tools/acc_forwarder/README.md | 8 +++++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/nft_ingester/src/program_transformers/token_metadata/mod.rs b/nft_ingester/src/program_transformers/token_metadata/mod.rs index bed380710..10ab9a74c 100644 --- a/nft_ingester/src/program_transformers/token_metadata/mod.rs +++ b/nft_ingester/src/program_transformers/token_metadata/mod.rs @@ -2,11 +2,12 @@ mod master_edition; mod v1_asset; use crate::{ + error::IngesterError, program_transformers::token_metadata::{ master_edition::{save_v1_master_edition, save_v2_master_edition}, v1_asset::{burn_v1_asset, save_v1_asset}, }, - error::IngesterError, tasks::TaskData, + tasks::TaskData, }; use blockbuster::programs::token_metadata::{TokenMetadataAccountData, TokenMetadataAccountState}; use plerkle_serialization::AccountInfo; @@ -33,7 +34,9 @@ pub async fn handle_token_metadata_account<'a, 'b, 'c>( } TokenMetadataAccountData::MetadataV1(m) => { let task = save_v1_asset(db, m.mint.as_ref().into(), account_update.slot(), m).await?; - task_manager.send(task)?; + if let Some(task) = task { + task_manager.send(task)?; + } Ok(()) } TokenMetadataAccountData::MasterEditionV2(m) => { diff --git a/nft_ingester/src/program_transformers/token_metadata/v1_asset.rs b/nft_ingester/src/program_transformers/token_metadata/v1_asset.rs index a50c1cd46..a8b263740 100644 --- a/nft_ingester/src/program_transformers/token_metadata/v1_asset.rs +++ b/nft_ingester/src/program_transformers/token_metadata/v1_asset.rs @@ -17,6 +17,7 @@ use digital_asset_types::{ json::ChainDataV1, }; +use log::warn; use num_traits::FromPrimitive; use plerkle_serialization::Pubkey as FBPubkey; use sea_orm::{ @@ -24,7 +25,6 @@ use sea_orm::{ DbErr, EntityTrait, JsonValue, }; - use crate::tasks::{DownloadMetadata, IntoTaskData}; pub async fn burn_v1_asset( @@ -61,7 +61,7 @@ pub async fn save_v1_asset( id: FBPubkey, slot: u64, metadata: &Metadata, -) -> Result { +) -> Result, IngesterError> { let metadata = metadata.clone(); let data = metadata.data; let meta_mint_pubkey = metadata.mint; @@ -71,11 +71,6 @@ pub async fn save_v1_asset( let id = id.0; let slot_i = slot as i64; let uri = data.uri.trim().replace('\0', ""); - if uri.is_empty() { - return Err(IngesterError::DeserializationError( - "URI is empty".to_string(), - )); - } let _spec = SpecificationVersions::V1; let class = match metadata.token_standard { Some(TokenStandard::NonFungible) => SpecificationAssetClass::Nft, @@ -148,7 +143,7 @@ pub async fn save_v1_asset( let asset_data_model = asset_data::ActiveModel { chain_data_mutability: Set(chain_mutability), chain_data: Set(chain_data_json), - metadata_url: Set(data.uri.trim().replace('\0', "")), + metadata_url: Set(uri.clone()), metadata: Set(JsonValue::String("processing".to_string())), metadata_mutability: Set(Mutability::Mutable), slot_updated: Set(slot_i), @@ -365,11 +360,20 @@ pub async fn save_v1_asset( } } txn.commit().await?; + if uri.is_empty() { + warn!( + "URI is empty for mint {}. Skipping background task.", + bs58::encode(mint).into_string() + ); + return Ok(None); + } + let mut task = DownloadMetadata { asset_data_id: id.to_vec(), uri, created_at: Some(Utc::now().naive_utc()), }; task.sanitize(); - task.into_task_data() + let t = task.into_task_data()?; + Ok(Some(t)) } diff --git a/tools/acc_forwarder/README.md b/tools/acc_forwarder/README.md index 067098d2e..b368f3f24 100644 --- a/tools/acc_forwarder/README.md +++ b/tools/acc_forwarder/README.md @@ -12,9 +12,13 @@ To forward information about a single account, run the following command: ### Send mint, metadata, and owned token account -To forward mint, metadata, and owned token account information for a specific mint, use the following command: +To forward mint, metadata, and owned token account information for a specific mint, use the following commands. -`cargo run -- --redis-url --rpc-url mint --mint ` +Locally: +`cargo run -- --redis-url redis://localhost:6379 --rpc-url $RPC_URL mint --mint t8nGUrFQozLtgiqnc5Pu8yiodbrJCaFyE3CGeubAvky` + +Dev/Prod: +`cargo run -- --redis-url $REDIS_URL --rpc-url $RPC_URL mint --mint t8nGUrFQozLtgiqnc5Pu8yiodbrJCaFyE3CGeubAvky` ### Process accounts from a file