Skip to content

Commit

Permalink
add download json_data task for token metdata extensions (#231)
Browse files Browse the repository at this point in the history
* run download_metedata_json taks for json_url after inserting to asset_data for token metadara extensions

* resolve comments and add checks for metadata uri

* cleanup
  • Loading branch information
Nagaprasadvr authored Jan 14, 2025
1 parent 3e4fb88 commit e9fce97
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 134 deletions.

This file was deleted.

This file was deleted.

9 changes: 2 additions & 7 deletions program_transformers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,14 @@ impl ProgramTransformer {
.await
}
ProgramParseResult::TokenProgramAccount(parsing_result) => {
handle_token_program_account(
account_info,
parsing_result,
&self.storage,
&self.download_metadata_notifier,
)
.await
handle_token_program_account(account_info, parsing_result, &self.storage).await
}
ProgramParseResult::TokenExtensionsProgramAccount(parsing_result) => {
handle_token_extensions_program_account(
account_info,
parsing_result,
&self.storage,
&self.download_metadata_notifier,
)
.await
}
Expand Down
3 changes: 1 addition & 2 deletions program_transformers/src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
AssetMintAccountColumns, AssetTokenAccountColumns,
},
error::ProgramTransformerResult,
AccountInfo, DownloadMetadataNotifier,
AccountInfo,
},
blockbuster::programs::token_account::TokenProgramAccount,
digital_asset_types::dao::{
Expand All @@ -24,7 +24,6 @@ pub async fn handle_token_program_account<'a, 'b>(
account_info: &AccountInfo,
parsing_result: &'a TokenProgramAccount,
db: &'b DatabaseConnection,
_download_metadata_notifier: &DownloadMetadataNotifier,
) -> ProgramTransformerResult<()> {
let account_key = account_info.pubkey.to_bytes().to_vec();
let account_owner = account_info.owner.to_bytes().to_vec();
Expand Down
27 changes: 23 additions & 4 deletions program_transformers/src/token_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
AssetMintAccountColumns, AssetTokenAccountColumns,
},
error::{ProgramTransformerError, ProgramTransformerResult},
filter_non_null_fields, AccountInfo,
filter_non_null_fields, AccountInfo, DownloadMetadataInfo, DownloadMetadataNotifier,
},
blockbuster::programs::token_extensions::{
extension::ShadowMetadata, MintAccount, TokenAccount, TokenExtensionsProgramAccount,
Expand All @@ -24,12 +24,14 @@ use {
serde_json::Value,
solana_sdk::program_option::COption,
spl_token_2022::state::AccountState,
tracing::warn,
};

pub async fn handle_token_extensions_program_account<'a, 'b, 'c>(
account_info: &'a AccountInfo,
parsing_result: &'b TokenExtensionsProgramAccount,
db: &'c DatabaseConnection,
download_metadata_notifier: &DownloadMetadataNotifier,
) -> ProgramTransformerResult<()> {
let account_key = account_info.pubkey.to_bytes().to_vec();
let account_owner = account_info.owner.to_bytes().to_vec();
Expand Down Expand Up @@ -195,7 +197,13 @@ pub async fn handle_token_extensions_program_account<'a, 'b, 'c>(
txn.commit().await?;

if let Some(metadata) = &extensions.metadata {
upsert_asset_data(metadata, account_key.clone(), slot, db).await?;
if let Some(info) =
upsert_asset_data(metadata, account_key.clone(), slot, db).await?
{
download_metadata_notifier(info)
.await
.map_err(ProgramTransformerError::DownloadMetadataNotify)?;
}
}

Ok(())
Expand All @@ -209,7 +217,7 @@ async fn upsert_asset_data(
key_bytes: Vec<u8>,
slot: i64,
db: &DatabaseConnection,
) -> ProgramTransformerResult<()> {
) -> ProgramTransformerResult<Option<DownloadMetadataInfo>> {
let metadata_json = serde_json::to_value(metadata.clone())
.map_err(|e| ProgramTransformerError::SerializatonError(e.to_string()))?;
let asset_data_model = asset_data::ActiveModel {
Expand Down Expand Up @@ -257,7 +265,18 @@ async fn upsert_asset_data(

txn.commit().await?;

Ok(())
if metadata.uri.is_empty() {
warn!(
"URI is empty for mint {}. Skipping background task.",
bs58::encode(key_bytes).into_string()
);
return Ok(None);
}

Ok(Some(DownloadMetadataInfo {
uri: metadata.uri.clone(),
asset_data_id: key_bytes,
}))
}

struct AssetMetadataAccountCols {
Expand Down

0 comments on commit e9fce97

Please sign in to comment.