From e9fce9732a7ad8552691204543f0af0ec39cc678 Mon Sep 17 00:00:00 2001 From: Nagaprasad V R <81755170+Nagaprasadvr@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:00:28 +0530 Subject: [PATCH] add download json_data task for token metdata extensions (#231) * 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 --- ..._token_extensions_get_asset_scenario1.snap | 53 --------------- ..._token_extensions_get_asset_scenario2.snap | 68 ------------------- program_transformers/src/lib.rs | 9 +-- program_transformers/src/token/mod.rs | 3 +- .../src/token_extensions/mod.rs | 27 ++++++-- 5 files changed, 26 insertions(+), 134 deletions(-) delete mode 100644 integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario1.snap delete mode 100644 integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario2.snap diff --git a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario1.snap b/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario1.snap deleted file mode 100644 index 3e6f1d5a1..000000000 --- a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario1.snap +++ /dev/null @@ -1,53 +0,0 @@ ---- -source: integration_tests/tests/integration_tests/token_extensions_tests.rs -expression: response -snapshot_kind: text ---- -{ - "interface": "FungibleToken", - "id": "BPU5vrAHafRuVeK33CgfdwTKSsmC4p6t3aqyav3cFF7Y", - "authorities": [], - "compression": { - "eligible": false, - "compressed": false, - "data_hash": "", - "creator_hash": "", - "asset_hash": "", - "tree": "", - "seq": 0, - "leaf_id": 0 - }, - "grouping": [], - "royalty": { - "royalty_model": "creators", - "target": null, - "percent": 0.0, - "basis_points": 0, - "primary_sale_happened": false, - "locked": false - }, - "creators": [], - "ownership": { - "frozen": false, - "delegated": false, - "delegate": null, - "ownership_model": "token", - "owner": "" - }, - "mutable": true, - "burnt": false, - "mint_extensions": { - "metadata": { - "uri": "https://acme.com/demo.json", - "mint": "BPU5vrAHafRuVeK33CgfdwTKSsmC4p6t3aqyav3cFF7Y", - "name": "DAS Dev", - "symbol": "DAS", - "update_authority": "Em34oqDQYQZ9b6ycPHD28K47mttrRsdNu1S1pgK6NtPL", - "additional_metadata": [] - }, - "metadata_pointer": { - "authority": "Em34oqDQYQZ9b6ycPHD28K47mttrRsdNu1S1pgK6NtPL", - "metadata_address": "BPU5vrAHafRuVeK33CgfdwTKSsmC4p6t3aqyav3cFF7Y" - } - } -} diff --git a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario2.snap b/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario2.snap deleted file mode 100644 index d56a5b03f..000000000 --- a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset_scenario2.snap +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: integration_tests/tests/integration_tests/token_extensions_tests.rs -expression: response -snapshot_kind: text ---- -{ - "interface": "FungibleToken", - "id": "HVbpJAQGNpkgBaYBZQBR1t7yFdvaYVp2vCQQfKKEN4tM", - "authorities": [], - "compression": { - "eligible": false, - "compressed": false, - "data_hash": "", - "creator_hash": "", - "asset_hash": "", - "tree": "", - "seq": 0, - "leaf_id": 0 - }, - "grouping": [], - "royalty": { - "royalty_model": "creators", - "target": null, - "percent": 0.0, - "basis_points": 0, - "primary_sale_happened": false, - "locked": false - }, - "creators": [], - "ownership": { - "frozen": false, - "delegated": false, - "delegate": null, - "ownership_model": "token", - "owner": "" - }, - "mutable": true, - "burnt": false, - "mint_extensions": { - "metadata": { - "uri": "https://token-metadata.paxos.com/usdp_metadata/prod/solana/usdp_metadata.json", - "mint": "HVbpJAQGNpkgBaYBZQBR1t7yFdvaYVp2vCQQfKKEN4tM", - "name": "Pax Dollar", - "symbol": "USDP", - "update_authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk", - "additional_metadata": [] - }, - "transfer_hook": { - "authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk", - "program_id": null - }, - "metadata_pointer": { - "authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk", - "metadata_address": "HVbpJAQGNpkgBaYBZQBR1t7yFdvaYVp2vCQQfKKEN4tM" - }, - "permanent_delegate": { - "delegate": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk" - }, - "mint_close_authority": { - "close_authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk" - }, - "confidential_transfer_mint": { - "authority": "2apBGMsS6ti9RyF5TwQTDswXBWskiJP2LD4cUEDqYJjk", - "auditor_elgamal_pubkey": null, - "auto_approve_new_accounts": false - } - } -} diff --git a/program_transformers/src/lib.rs b/program_transformers/src/lib.rs index 99a10277b..ee20aa2b4 100644 --- a/program_transformers/src/lib.rs +++ b/program_transformers/src/lib.rs @@ -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 } diff --git a/program_transformers/src/token/mod.rs b/program_transformers/src/token/mod.rs index 2abd30666..38c05a734 100644 --- a/program_transformers/src/token/mod.rs +++ b/program_transformers/src/token/mod.rs @@ -5,7 +5,7 @@ use { AssetMintAccountColumns, AssetTokenAccountColumns, }, error::ProgramTransformerResult, - AccountInfo, DownloadMetadataNotifier, + AccountInfo, }, blockbuster::programs::token_account::TokenProgramAccount, digital_asset_types::dao::{ @@ -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(); diff --git a/program_transformers/src/token_extensions/mod.rs b/program_transformers/src/token_extensions/mod.rs index 8fa8dcdd3..b68783011 100644 --- a/program_transformers/src/token_extensions/mod.rs +++ b/program_transformers/src/token_extensions/mod.rs @@ -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, @@ -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(); @@ -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(()) @@ -209,7 +217,7 @@ async fn upsert_asset_data( key_bytes: Vec, slot: i64, db: &DatabaseConnection, -) -> ProgramTransformerResult<()> { +) -> ProgramTransformerResult> { let metadata_json = serde_json::to_value(metadata.clone()) .map_err(|e| ProgramTransformerError::SerializatonError(e.to_string()))?; let asset_data_model = asset_data::ActiveModel { @@ -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 {