Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add download json_data task for token metdata extensions #231

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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