diff --git a/digital_asset_types/src/dapi/common/asset.rs b/digital_asset_types/src/dapi/common/asset.rs index e7d331956..674345640 100644 --- a/digital_asset_types/src/dapi/common/asset.rs +++ b/digital_asset_types/src/dapi/common/asset.rs @@ -378,16 +378,6 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result None, }; - if interface == Interface::FungibleToken { - return Ok(RpcAsset { - interface: interface.clone(), - id: bs58::encode(asset.id).into_string(), - content: Some(content), - mint_extensions: asset.mint_extensions, - ..Default::default() - }); - } - Ok(RpcAsset { interface: interface.clone(), id: bs58::encode(asset.id).into_string(), diff --git a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset.snap b/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset.snap index 104152bb8..e605fed8a 100644 --- a/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset.snap +++ b/integration_tests/tests/integration_tests/snapshots/integration_tests__token_extensions_tests__token_extensions_get_asset.snap @@ -1,9 +1,10 @@ --- source: integration_tests/tests/integration_tests/token_extensions_tests.rs expression: response +snapshot_kind: text --- { - "interface": "V1_NFT", + "interface": "FungibleToken", "id": "BPU5vrAHafRuVeK33CgfdwTKSsmC4p6t3aqyav3cFF7Y", "content": { "$schema": "https://schema.metaplex.com/nft1.0.json", @@ -15,14 +16,7 @@ expression: response }, "links": {} }, - "authorities": [ - { - "address": "Em34oqDQYQZ9b6ycPHD28K47mttrRsdNu1S1pgK6NtPL", - "scopes": [ - "full" - ] - } - ], + "authorities": [], "compression": { "eligible": false, "compressed": false, @@ -48,12 +42,7 @@ expression: response "delegated": false, "delegate": null, "ownership_model": "single", - "owner": "Em34oqDQYQZ9b6ycPHD28K47mttrRsdNu1S1pgK6NtPL" - }, - "supply": { - "print_max_supply": 0, - "print_current_supply": 0, - "edition_nonce": null + "owner": "" }, "mutable": true, "burnt": false, diff --git a/program_transformers/src/asset_upserts.rs b/program_transformers/src/asset_upserts.rs index 7f527ebcd..7ea102437 100644 --- a/program_transformers/src/asset_upserts.rs +++ b/program_transformers/src/asset_upserts.rs @@ -91,6 +91,7 @@ pub async fn upsert_assets_mint_account_columns( Ok(()) } TokenExtensionsProgramAccount::MintAccount(m) => { - println!("Mint account extensions: {:#?}", m.extensions); let MintAccount { account, extensions, } = m; + let is_non_fungible = m.account.is_non_fungible(); + let extensions: Option = if extensions.is_some() { if let Some(metadata) = &m.extensions.metadata { - upsert_asset_data(metadata, account_key.clone(), slot, db).await?; + upsert_asset_data(metadata, account_key.clone(), slot, db, is_non_fungible) + .await?; } filter_non_null_fields( @@ -193,7 +196,7 @@ pub async fn handle_token_extensions_program_account<'a, 'b, 'c>( slot_updated_mint_account: slot, extensions: extensions.clone(), }, - m.is_non_fungible(), + is_non_fungible, &txn, ) .await?; @@ -211,6 +214,7 @@ async fn upsert_asset_data( key_bytes: Vec, slot: i64, db: &DatabaseConnection, + is_non_fungible: bool, ) -> ProgramTransformerResult<()> { let metadata_json = serde_json::to_value(metadata.clone()) .map_err(|e| ProgramTransformerError::SerializatonError(e.to_string()))?; @@ -244,5 +248,59 @@ async fn upsert_asset_data( asset_data_query.sql ); db.execute(asset_data_query).await?; + + if !is_non_fungible { + let txn = db.begin().await?; + upsert_assets_metadata_cols( + AssetMetadataAccountCols { + mint: key_bytes.clone(), + slot_updated_metadata_account: slot, + }, + &txn, + ) + .await?; + + txn.commit().await?; + } + + Ok(()) +} + +struct AssetMetadataAccountCols { + mint: Vec, + slot_updated_metadata_account: i64, +} + +async fn upsert_assets_metadata_cols( + metadata: AssetMetadataAccountCols, + db: &DatabaseTransaction, +) -> Result<(), DbErr> { + let asset = asset::ActiveModel { + id: ActiveValue::Set(metadata.mint.clone()), + specification_asset_class: Set(Some(SpecificationAssetClass::FungibleToken)), + specification_version: Set(Some(SpecificationVersions::V0)), + slot_updated_metadata_account: Set(Some(metadata.slot_updated_metadata_account)), + ..Default::default() + }; + + let mut asset_query = asset::Entity::insert(asset) + .on_conflict( + OnConflict::columns([asset::Column::Id]) + .update_columns([ + asset::Column::SpecificationAssetClass, + asset::Column::SpecificationVersion, + asset::Column::SlotUpdatedMetadataAccount, + ]) + .to_owned(), + ) + .build(DbBackend::Postgres); + + asset_query.sql = format!( + "{} WHERE excluded.slot_updated_metadata_account >= asset.slot_updated_metadata_account OR asset.slot_updated_metadata_account IS NULL", + asset_query.sql + ); + + db.execute(asset_query).await?; + Ok(()) }