Skip to content

Commit

Permalink
fix(ingester): allow empty json uris (metaplex-foundation#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasPennie authored Jun 30, 2023
1 parent cd8348b commit 2c6d19c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
7 changes: 5 additions & 2 deletions nft_ingester/src/program_transformers/token_metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand Down
22 changes: 13 additions & 9 deletions nft_ingester/src/program_transformers/token_metadata/v1_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use digital_asset_types::{
json::ChainDataV1,
};

use log::warn;
use num_traits::FromPrimitive;
use plerkle_serialization::Pubkey as FBPubkey;
use sea_orm::{
entity::*, query::*, sea_query::OnConflict, ActiveValue::Set, ConnectionTrait, DbBackend,
DbErr, EntityTrait, JsonValue,
};


use crate::tasks::{DownloadMetadata, IntoTaskData};

pub async fn burn_v1_asset<T: ConnectionTrait + TransactionTrait>(
Expand Down Expand Up @@ -61,7 +61,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
id: FBPubkey,
slot: u64,
metadata: &Metadata,
) -> Result<TaskData, IngesterError> {
) -> Result<Option<TaskData>, IngesterError> {
let metadata = metadata.clone();
let data = metadata.data;
let meta_mint_pubkey = metadata.mint;
Expand All @@ -71,11 +71,6 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
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,
Expand Down Expand Up @@ -148,7 +143,7 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
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),
Expand Down Expand Up @@ -365,11 +360,20 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
}
}
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))
}
8 changes: 6 additions & 2 deletions tools/acc_forwarder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <REDIS_URL> --rpc-url <RPC_URL> mint --mint <ACCOUNT>`
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

Expand Down

0 comments on commit 2c6d19c

Please sign in to comment.