From 9d035b08ae50df7096108e1c152c406ce06ccc1a Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Fri, 15 Nov 2024 21:23:41 +0530 Subject: [PATCH 1/6] optional display collection metadata in rpc responce --- .../src/dao/extensions/asset_grouping.rs | 13 ++- digital_asset_types/src/dao/full_asset.rs | 14 ++- digital_asset_types/src/dao/scopes/asset.rs | 85 +++++++++++++------ .../src/dapi/assets_by_authority.rs | 2 +- .../src/dapi/assets_by_creator.rs | 2 +- .../src/dapi/assets_by_group.rs | 2 +- .../src/dapi/assets_by_owner.rs | 2 +- digital_asset_types/src/dapi/common/asset.rs | 41 +++++++-- digital_asset_types/src/dapi/get_asset.rs | 6 +- digital_asset_types/src/dapi/search_assets.rs | 2 +- digital_asset_types/src/rpc/asset.rs | 4 +- digital_asset_types/src/rpc/options.rs | 4 +- 12 files changed, 129 insertions(+), 48 deletions(-) diff --git a/digital_asset_types/src/dao/extensions/asset_grouping.rs b/digital_asset_types/src/dao/extensions/asset_grouping.rs index 49b091efb..75e0442d7 100644 --- a/digital_asset_types/src/dao/extensions/asset_grouping.rs +++ b/digital_asset_types/src/dao/extensions/asset_grouping.rs @@ -1,11 +1,12 @@ use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait}; -use crate::dao::{asset, asset_authority, asset_grouping}; +use crate::dao::{asset, asset_authority, asset_data, asset_grouping}; #[derive(Copy, Clone, Debug, EnumIter)] pub enum Relation { Asset, AssetAuthority, + AssetData, } impl RelationTrait for Relation { @@ -19,6 +20,10 @@ impl RelationTrait for Relation { .from(asset_grouping::Column::AssetId) .to(asset_authority::Column::Id) .into(), + Self::AssetData => asset_grouping::Entity::belongs_to(asset_data::Entity) + .from(asset_grouping::Column::AssetId) + .to(asset_data::Column::Id) + .into(), } } } @@ -34,3 +39,9 @@ impl Related for asset_grouping::Entity { Relation::AssetAuthority.def() } } + +impl Related for asset_grouping::Entity { + fn to() -> RelationDef { + Relation::AssetData.def() + } +} \ No newline at end of file diff --git a/digital_asset_types/src/dao/full_asset.rs b/digital_asset_types/src/dao/full_asset.rs index fda932d21..695d71b2d 100644 --- a/digital_asset_types/src/dao/full_asset.rs +++ b/digital_asset_types/src/dao/full_asset.rs @@ -1,12 +1,22 @@ use crate::dao::{asset, asset_authority, asset_creators, asset_data, asset_grouping}; +pub struct FullAssetGroup { + pub id: i64, + pub asset_id: Vec, + pub group_key: String, + pub group_value: Option, + pub seq: Option, + pub slot_updated: Option, + pub verified: bool, + pub group_info_seq: Option, +} #[derive(Clone, Debug, PartialEq)] pub struct FullAsset { pub asset: asset::Model, pub data: asset_data::Model, pub authorities: Vec, pub creators: Vec, - pub groups: Vec, + pub groups: Vec<(asset_grouping::Model, Option)>, } #[derive(Clone, Debug, PartialEq)] pub struct AssetRelated { @@ -17,4 +27,4 @@ pub struct AssetRelated { pub struct FullAssetList { pub list: Vec, -} +} \ No newline at end of file diff --git a/digital_asset_types/src/dao/scopes/asset.rs b/digital_asset_types/src/dao/scopes/asset.rs index 58e4cbbaf..ab2de0667 100644 --- a/digital_asset_types/src/dao/scopes/asset.rs +++ b/digital_asset_types/src/dao/scopes/asset.rs @@ -6,7 +6,7 @@ use crate::{ sea_orm_active_enums::Instruction, Cursor, FullAsset, GroupingSize, Pagination, }, - rpc::filter::AssetSortDirection, + rpc::{filter::AssetSortDirection, options::Options}, }; use indexmap::IndexMap; use sea_orm::{entity::*, query::*, ConnectionTrait, DbErr, Order}; @@ -60,7 +60,7 @@ pub async fn get_by_creator( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, ) -> Result, DbErr> { let mut condition = Condition::all() .add(asset_creators::Column::Creator.eq(creator.clone())) @@ -76,7 +76,7 @@ pub async fn get_by_creator( sort_direction, pagination, limit, - show_unverified_collections, + options, Some(creator), ) .await @@ -112,13 +112,13 @@ pub async fn get_by_grouping( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, ) -> Result, DbErr> { let mut condition = asset_grouping::Column::GroupKey .eq(group_key) .and(asset_grouping::Column::GroupValue.eq(group_value)); - if !show_unverified_collections { + if !options.show_unverified_collections { condition = condition.and( asset_grouping::Column::Verified .eq(true) @@ -136,7 +136,7 @@ pub async fn get_by_grouping( sort_direction, pagination, limit, - show_unverified_collections, + options, None, ) .await @@ -149,7 +149,7 @@ pub async fn get_assets_by_owner( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, ) -> Result, DbErr> { let cond = Condition::all() .add(asset::Column::Owner.eq(owner)) @@ -162,7 +162,7 @@ pub async fn get_assets_by_owner( sort_direction, pagination, limit, - show_unverified_collections, + options, ) .await } @@ -172,6 +172,7 @@ pub async fn get_assets( asset_ids: Vec>, pagination: &Pagination, limit: u64, + options : &Options, ) -> Result, DbErr> { let cond = Condition::all() .add(asset::Column::Id.is_in(asset_ids)) @@ -185,7 +186,7 @@ pub async fn get_assets( Order::Asc, pagination, limit, - false, + options, ) .await } @@ -197,7 +198,7 @@ pub async fn get_by_authority( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, ) -> Result, DbErr> { let cond = Condition::all() .add(asset_authority::Column::Authority.eq(authority)) @@ -210,7 +211,7 @@ pub async fn get_by_authority( sort_direction, pagination, limit, - show_unverified_collections, + options, None, ) .await @@ -225,7 +226,7 @@ async fn get_by_related_condition( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, required_creator: Option>, ) -> Result, DbErr> where @@ -244,13 +245,13 @@ where let assets = paginate(pagination, limit, stmt, sort_direction, asset::Column::Id) .all(conn) .await?; - get_related_for_assets(conn, assets, show_unverified_collections, required_creator).await + get_related_for_assets(conn, assets, options, required_creator).await } pub async fn get_related_for_assets( conn: &impl ConnectionTrait, assets: Vec, - show_unverified_collections: bool, + options: &Options, required_creator: Option>, ) -> Result, DbErr> { let asset_ids = assets.iter().map(|a| a.id.clone()).collect::>(); @@ -325,7 +326,7 @@ pub async fn get_related_for_assets( } } - let cond = if show_unverified_collections { + let cond = if options.show_unverified_collections { Condition::all() } else { Condition::any() @@ -335,19 +336,35 @@ pub async fn get_related_for_assets( .add(asset_grouping::Column::Verified.is_null()) }; - let grouping = asset_grouping::Entity::find() + let grouping = if options.show_collection_metadata { + asset_grouping::Entity::find() + .find_also_related(asset_data::Entity) .filter(asset_grouping::Column::AssetId.is_in(ids.clone())) .filter(asset_grouping::Column::GroupValue.is_not_null()) .filter(cond) .order_by_asc(asset_grouping::Column::AssetId) .all(conn) - .await?; - for g in grouping.into_iter() { + .await? + } else { + asset_grouping::Entity::find() + .filter(asset_grouping::Column::AssetId.is_in(ids.clone())) + .filter(asset_grouping::Column::GroupValue.is_not_null()) + .filter(cond) + .order_by_asc(asset_grouping::Column::AssetId) + .all(conn) + .await? + .into_iter() + .map(|g| (g, None)) + .collect::>() + }; + + for (g, a) in grouping.into_iter() { if let Some(asset) = assets_map.get_mut(&g.asset_id) { - asset.groups.push(g); + asset.groups.push((g, a)); } } + Ok(assets_map.into_iter().map(|(_, v)| v).collect()) } @@ -360,7 +377,7 @@ pub async fn get_assets_by_condition( sort_direction: Order, pagination: &Pagination, limit: u64, - show_unverified_collections: bool, + options: &Options, ) -> Result, DbErr> { let mut stmt = asset::Entity::find(); for def in joins { @@ -377,7 +394,7 @@ pub async fn get_assets_by_condition( .all(conn) .await?; let full_assets = - get_related_for_assets(conn, assets, show_unverified_collections, None).await?; + get_related_for_assets(conn, assets, options, None).await?; Ok(full_assets) } @@ -385,6 +402,7 @@ pub async fn get_by_id( conn: &impl ConnectionTrait, asset_id: Vec, include_no_supply: bool, + options: &Options, ) -> Result { let mut asset_data = asset::Entity::find_by_id(asset_id.clone()).find_also_related(asset_data::Entity); @@ -411,7 +429,7 @@ pub async fn get_by_id( filter_out_stale_creators(&mut creators); - let grouping: Vec = asset_grouping::Entity::find() + let grouping_query = asset_grouping::Entity::find() .filter(asset_grouping::Column::AssetId.eq(asset.id.clone())) .filter(asset_grouping::Column::GroupValue.is_not_null()) .filter( @@ -421,15 +439,28 @@ pub async fn get_by_id( // Therefore if verified is null, we can assume that the group is verified. .add(asset_grouping::Column::Verified.is_null()), ) - .order_by_asc(asset_grouping::Column::AssetId) - .all(conn) - .await?; + .order_by_asc(asset_grouping::Column::AssetId); + + let groups = if options.show_collection_metadata { + grouping_query + .find_also_related(asset_data::Entity) + .all(conn) + .await? + } else { + grouping_query + .all(conn) + .await? + .into_iter() + .map(|g| (g, None)) + .collect::>() + }; + Ok(FullAsset { asset, data, authorities, creators, - groups: grouping, + groups, }) } @@ -552,4 +583,4 @@ fn filter_out_stale_creators(creators: &mut Vec) { creators.retain(|creator| creator.seq == seq); } } -} +} \ No newline at end of file diff --git a/digital_asset_types/src/dapi/assets_by_authority.rs b/digital_asset_types/src/dapi/assets_by_authority.rs index 59404f3e0..b52891062 100644 --- a/digital_asset_types/src/dapi/assets_by_authority.rs +++ b/digital_asset_types/src/dapi/assets_by_authority.rs @@ -24,7 +24,7 @@ pub async fn get_assets_by_authority( sort_direction, &pagination, page_options.limit, - options.show_unverified_collections, + options, ) .await?; Ok(build_asset_response( diff --git a/digital_asset_types/src/dapi/assets_by_creator.rs b/digital_asset_types/src/dapi/assets_by_creator.rs index 9ce5de591..3a2b1e53e 100644 --- a/digital_asset_types/src/dapi/assets_by_creator.rs +++ b/digital_asset_types/src/dapi/assets_by_creator.rs @@ -27,7 +27,7 @@ pub async fn get_assets_by_creator( sort_direction, &pagination, page_options.limit, - options.show_unverified_collections, + options, ) .await?; Ok(build_asset_response( diff --git a/digital_asset_types/src/dapi/assets_by_group.rs b/digital_asset_types/src/dapi/assets_by_group.rs index 68784b9f4..36f4ae534 100644 --- a/digital_asset_types/src/dapi/assets_by_group.rs +++ b/digital_asset_types/src/dapi/assets_by_group.rs @@ -27,7 +27,7 @@ pub async fn get_assets_by_group( sort_direction, &pagination, page_options.limit, - options.show_unverified_collections, + options, ) .await?; Ok(build_asset_response( diff --git a/digital_asset_types/src/dapi/assets_by_owner.rs b/digital_asset_types/src/dapi/assets_by_owner.rs index c3c4da3a5..5f342fe9a 100644 --- a/digital_asset_types/src/dapi/assets_by_owner.rs +++ b/digital_asset_types/src/dapi/assets_by_owner.rs @@ -24,7 +24,7 @@ pub async fn get_assets_by_owner( sort_direction, &pagination, page_options.limit, - options.show_unverified_collections, + options, ) .await?; Ok(build_asset_response( diff --git a/digital_asset_types/src/dapi/common/asset.rs b/digital_asset_types/src/dapi/common/asset.rs index c9a9dd486..a4fa6dfd1 100644 --- a/digital_asset_types/src/dapi/common/asset.rs +++ b/digital_asset_types/src/dapi/common/asset.rs @@ -310,25 +310,50 @@ pub fn to_creators(creators: Vec) -> Vec { } pub fn to_grouping( - groups: Vec, + groups: Vec<(asset_grouping::Model, Option)>, options: &Options, ) -> Result, DbErr> { let result: Vec = groups .iter() - .filter_map(|model| { + .filter_map(|(asset_group, asset_data)| { let verified = match options.show_unverified_collections { // Null verified indicates legacy data, meaning it is verified. - true => Some(model.verified), + true => Some(asset_group.verified), false => None, }; // Filter out items where group_value is None. - model.group_value.clone().map(|group_value| Group { - group_key: model.group_key.clone(), - group_value: Some(group_value), - verified, + asset_group.group_value.clone().map(|group_value| { + let collection_metadata = asset_data.as_ref().map(|data| { + let mut metadata_selector_fn = jsonpath_lib::selector(&data.metadata); + let metadata_selector = &mut metadata_selector_fn; + let mut meta: MetadataMap = MetadataMap::new(); + + if let Some(name) = safe_select(metadata_selector, "$.name") { + meta.set_item("name", name.clone()); + } + if let Some(symbol) = safe_select(metadata_selector, "$.symbol") { + meta.set_item("symbol", symbol.clone()); + } + if let Some(image) = safe_select(metadata_selector, "$.image") { + meta.set_item("image", image.clone()); + } + if let Some(external_url) = safe_select(metadata_selector, "$.external_url") { + meta.set_item("external_url", external_url.clone()); + } + + meta + }); + + Group { + group_key: asset_group.group_key.clone(), + group_value: Some(group_value), + verified, + collection_metadata, + } }) }) .collect(); + Ok(result) } @@ -469,4 +494,4 @@ pub fn asset_list_to_rpc( } (assets, errors) }) -} +} \ No newline at end of file diff --git a/digital_asset_types/src/dapi/get_asset.rs b/digital_asset_types/src/dapi/get_asset.rs index 3740562c3..b3816989f 100644 --- a/digital_asset_types/src/dapi/get_asset.rs +++ b/digital_asset_types/src/dapi/get_asset.rs @@ -11,7 +11,7 @@ pub async fn get_asset( id: Vec, options: &Options, ) -> Result { - let asset = scopes::asset::get_by_id(db, id, false).await?; + let asset = scopes::asset::get_by_id(db, id, false, options).await?; asset_to_rpc(asset, options) } @@ -22,7 +22,7 @@ pub async fn get_assets( options: &Options, ) -> Result, DbErr> { let pagination = Pagination::Page { page: 1 }; - let assets = scopes::asset::get_assets(db, ids, &pagination, limit).await?; + let assets = scopes::asset::get_assets(db, ids, &pagination, limit,options).await?; let asset_list = build_asset_response(assets, limit, &pagination, options); let asset_map = asset_list .items @@ -30,4 +30,4 @@ pub async fn get_assets( .map(|asset| (asset.id.clone(), asset)) .collect(); Ok(asset_map) -} +} \ No newline at end of file diff --git a/digital_asset_types/src/dapi/search_assets.rs b/digital_asset_types/src/dapi/search_assets.rs index a7ee65509..85a0f190d 100644 --- a/digital_asset_types/src/dapi/search_assets.rs +++ b/digital_asset_types/src/dapi/search_assets.rs @@ -23,7 +23,7 @@ pub async fn search_assets( sort_direction, &pagination, page_options.limit, - options.show_unverified_collections, + options, ) .await?; Ok(build_asset_response( diff --git a/digital_asset_types/src/rpc/asset.rs b/digital_asset_types/src/rpc/asset.rs index 751ef3841..c3300bc6f 100644 --- a/digital_asset_types/src/rpc/asset.rs +++ b/digital_asset_types/src/rpc/asset.rs @@ -219,6 +219,8 @@ pub struct Group { pub group_value: Option, #[serde(skip_serializing_if = "Option::is_none")] pub verified: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub collection_metadata: Option, } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq, JsonSchema)] @@ -398,4 +400,4 @@ pub struct Asset { pub external_plugins: Option, #[serde(skip_serializing_if = "Option::is_none")] pub unknown_external_plugins: Option, -} +} \ No newline at end of file diff --git a/digital_asset_types/src/rpc/options.rs b/digital_asset_types/src/rpc/options.rs index a1fafa2c4..7e13c47b2 100644 --- a/digital_asset_types/src/rpc/options.rs +++ b/digital_asset_types/src/rpc/options.rs @@ -6,4 +6,6 @@ use serde::{Deserialize, Serialize}; pub struct Options { #[serde(default)] pub show_unverified_collections: bool, -} + #[serde(default)] + pub show_collection_metadata: bool, +} \ No newline at end of file From af4a4a7ee1f3fcdf1b9787e91ceef3ccd05f83f1 Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Sat, 23 Nov 2024 21:42:39 +0530 Subject: [PATCH 2/6] test snapshot added --- ...Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk | Bin 0 -> 224 bytes .../tests/integration_tests/main.rs | 1 + ..._with_show_collection_metadata_option.snap | 123 ++++++++++++++++++ .../test_show_collection_metadata_option.rs | 48 +++++++ 4 files changed, 172 insertions(+) create mode 100644 integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk create mode 100644 integration_tests/tests/integration_tests/snapshots/integration_tests__test_show_collection_metadata_option__get_asset_with_show_collection_metadata_option.snap create mode 100644 integration_tests/tests/integration_tests/test_show_collection_metadata_option.rs diff --git a/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk b/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk new file mode 100644 index 0000000000000000000000000000000000000000..5999bdd4481537930146f220c38f429b2ca643f0 GIT binary patch literal 224 zcmY#jfB*@G3l zF8?E<_L}F@|79!L?tXiCJ$2#ao2MVToqJumMrKRv+xTeniB>&dTkHNatOS{v;420s z85sUULHbicArRkI;7H_TMh1o;AR9q*uJ TCc`h8r!_%pz<`k$)eH;(N#|9z literal 0 HcmV?d00001 diff --git a/integration_tests/tests/integration_tests/main.rs b/integration_tests/tests/integration_tests/main.rs index 7220ca96c..68ef229e9 100644 --- a/integration_tests/tests/integration_tests/main.rs +++ b/integration_tests/tests/integration_tests/main.rs @@ -4,3 +4,4 @@ mod common; mod general_scenario_tests; mod mpl_core_tests; mod regular_nft_tests; +mod test_show_collection_metadata_option; diff --git a/integration_tests/tests/integration_tests/snapshots/integration_tests__test_show_collection_metadata_option__get_asset_with_show_collection_metadata_option.snap b/integration_tests/tests/integration_tests/snapshots/integration_tests__test_show_collection_metadata_option__get_asset_with_show_collection_metadata_option.snap new file mode 100644 index 000000000..d722b2df6 --- /dev/null +++ b/integration_tests/tests/integration_tests/snapshots/integration_tests__test_show_collection_metadata_option__get_asset_with_show_collection_metadata_option.snap @@ -0,0 +1,123 @@ +--- +source: integration_tests/tests/integration_tests/test_show_collection_metadata_option.rs +expression: response +snapshot_kind: text +--- +{ + "interface": "ProgrammableNFT", + "id": "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "content": { + "$schema": "https://schema.metaplex.com/nft1.0.json", + "json_uri": "https://madlads.s3.us-west-2.amazonaws.com/json/8420.json", + "files": [ + { + "uri": "https://madlads.s3.us-west-2.amazonaws.com/images/8420.png", + "mime": "image/png" + }, + { + "uri": "https://arweave.net/qJ5B6fx5hEt4P7XbicbJQRyTcbyLaV-OQNA1KjzdqOQ/0.png", + "mime": "image/png" + } + ], + "metadata": { + "attributes": [ + { + "value": "Male", + "trait_type": "Gender" + }, + { + "value": "King", + "trait_type": "Type" + }, + { + "value": "Royal", + "trait_type": "Expression" + }, + { + "value": "Mad Crown", + "trait_type": "Hat" + }, + { + "value": "Madness", + "trait_type": "Eyes" + }, + { + "value": "Mad Armor", + "trait_type": "Clothing" + }, + { + "value": "Royal Rug", + "trait_type": "Background" + } + ], + "description": "Fock it.", + "name": "Mad Lads #8420", + "symbol": "MAD", + "token_standard": "ProgrammableNonFungible" + }, + "links": { + "image": "https://madlads.s3.us-west-2.amazonaws.com/images/8420.png", + "external_url": "https://madlads.com" + } + }, + "authorities": [ + { + "address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW", + "scopes": [ + "full" + ] + } + ], + "compression": { + "eligible": false, + "compressed": false, + "data_hash": "", + "creator_hash": "", + "asset_hash": "", + "tree": "", + "seq": 0, + "leaf_id": 0 + }, + "grouping": [ + { + "group_key": "collection", + "group_value": "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w", + "collection_metadata": { + "external_url": "https://madlads.com", + "image": "https://madlads.s3.us-west-2.amazonaws.com/images/8420.png", + "name": "Mad Lads #8420", + "symbol": "MAD" + } + } + ], + "royalty": { + "royalty_model": "creators", + "target": null, + "percent": 0.042, + "basis_points": 420, + "primary_sale_happened": true, + "locked": false + }, + "creators": [ + { + "address": "5XvhfmRjwXkGp3jHGmaKpqeerNYjkuZZBYLVQYdeVcRv", + "share": 0, + "verified": true + }, + { + "address": "2RtGg6fsFiiF1EQzHqbd66AhW7R5bWeQGpTbv2UMkCdW", + "share": 100, + "verified": true + } + ], + "ownership": { + "frozen": false, + "delegated": false, + "delegate": null, + "ownership_model": "single", + "owner": "" + }, + "supply": null, + "mutable": true, + "burnt": false +} diff --git a/integration_tests/tests/integration_tests/test_show_collection_metadata_option.rs b/integration_tests/tests/integration_tests/test_show_collection_metadata_option.rs new file mode 100644 index 000000000..98dc76a65 --- /dev/null +++ b/integration_tests/tests/integration_tests/test_show_collection_metadata_option.rs @@ -0,0 +1,48 @@ +use function_name::named; + +use das_api::api::{self, ApiContract}; + +use itertools::Itertools; + +use serial_test::serial; + +use super::common::*; + +#[tokio::test] +#[serial] +#[named] + +async fn test_get_asset_with_show_collection_metadata_option() { + let name = trim_test_name(function_name!()); + + let setup = TestSetup::new_with_options( + name.clone(), + TestSetupOptions { + network: Some(Network::Mainnet), + }, + ) + .await; + + let seeds: Vec = seed_accounts( + ["F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk"] + ); + + apply_migrations_and_delete_data(setup.db.clone()).await; + + index_seed_events(&setup, seeds.iter().collect_vec()).await; + + let request = r#" + { + "id": "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "displayOptions" : { + "showCollectionMetadata": true + } + } + "#; + + let request: api::GetAsset = serde_json::from_str(request).unwrap(); + + let response = setup.das_api.get_asset(request).await.unwrap(); + + insta::assert_json_snapshot!(name, response); +} From 18c0e3bb5374c27738296005c136962ade054977 Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Sun, 24 Nov 2024 00:08:06 +0530 Subject: [PATCH 3/6] grouping query improved --- digital_asset_types/src/dao/scopes/asset.rs | 31 ++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/digital_asset_types/src/dao/scopes/asset.rs b/digital_asset_types/src/dao/scopes/asset.rs index ab2de0667..5c31cc3af 100644 --- a/digital_asset_types/src/dao/scopes/asset.rs +++ b/digital_asset_types/src/dao/scopes/asset.rs @@ -336,26 +336,25 @@ pub async fn get_related_for_assets( .add(asset_grouping::Column::Verified.is_null()) }; - let grouping = if options.show_collection_metadata { - asset_grouping::Entity::find() - .find_also_related(asset_data::Entity) + + let grouping_base_query = asset_grouping::Entity::find() .filter(asset_grouping::Column::AssetId.is_in(ids.clone())) .filter(asset_grouping::Column::GroupValue.is_not_null()) .filter(cond) - .order_by_asc(asset_grouping::Column::AssetId) - .all(conn) - .await? + .order_by_asc(asset_grouping::Column::AssetId); + + let grouping = if options.show_collection_metadata { + grouping_base_query + .find_also_related(asset_data::Entity) + .all(conn) + .await? } else { - asset_grouping::Entity::find() - .filter(asset_grouping::Column::AssetId.is_in(ids.clone())) - .filter(asset_grouping::Column::GroupValue.is_not_null()) - .filter(cond) - .order_by_asc(asset_grouping::Column::AssetId) - .all(conn) - .await? - .into_iter() - .map(|g| (g, None)) - .collect::>() + grouping_base_query + .all(conn) + .await? + .into_iter() + .map(|g| (g, None)) + .collect::>() }; for (g, a) in grouping.into_iter() { From 98c4177070ace6f5405378c5d2a7a3aba3412a29 Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Mon, 25 Nov 2024 02:52:19 +0530 Subject: [PATCH 4/6] removed duplicacy and extra mapping to inject None --- digital_asset_types/src/dao/scopes/asset.rs | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/digital_asset_types/src/dao/scopes/asset.rs b/digital_asset_types/src/dao/scopes/asset.rs index 5c31cc3af..9661aa893 100644 --- a/digital_asset_types/src/dao/scopes/asset.rs +++ b/digital_asset_types/src/dao/scopes/asset.rs @@ -336,32 +336,32 @@ pub async fn get_related_for_assets( .add(asset_grouping::Column::Verified.is_null()) }; - let grouping_base_query = asset_grouping::Entity::find() .filter(asset_grouping::Column::AssetId.is_in(ids.clone())) .filter(asset_grouping::Column::GroupValue.is_not_null()) .filter(cond) .order_by_asc(asset_grouping::Column::AssetId); - let grouping = if options.show_collection_metadata { - grouping_base_query + if options.show_collection_metadata { + let combined_group_query = grouping_base_query .find_also_related(asset_data::Entity) .all(conn) - .await? + .await?; + for (g, a) in combined_group_query.into_iter() { + if let Some(asset) = assets_map.get_mut(&g.asset_id) { + asset.groups.push((g, a)); + } + } } else { - grouping_base_query + let single_group_query = grouping_base_query .all(conn) - .await? - .into_iter() - .map(|g| (g, None)) - .collect::>() - }; - - for (g, a) in grouping.into_iter() { - if let Some(asset) = assets_map.get_mut(&g.asset_id) { - asset.groups.push((g, a)); + .await?; + for g in single_group_query.into_iter() { + if let Some(asset) = assets_map.get_mut(&g.asset_id) { + asset.groups.push((g, None)); + } } - } + }; Ok(assets_map.into_iter().map(|(_, v)| v).collect()) From f281154538055f8382fc349d93859dce943b063f Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Tue, 17 Dec 2024 16:58:32 +0530 Subject: [PATCH 5/6] test improvments added --- ...XKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK | Bin 0 -> 824 bytes ...v3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti | Bin 0 -> 312 bytes ...6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM | Bin 0 -> 224 bytes ..._with_show_collection_metadata_option.snap | 68 +++--------------- .../test_show_collection_metadata_option.rs | 10 +-- 5 files changed, 16 insertions(+), 62 deletions(-) create mode 100644 integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK create mode 100644 integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti create mode 100644 integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM diff --git a/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK b/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK new file mode 100644 index 0000000000000000000000000000000000000000..8825aa19653acfe437926e531f73d87f5dbe0fa4 GIT binary patch literal 824 zcmY#jfB*@G90nE!4+a$=H-NzfNJap00)qsQOlGO` z@E;0_0%C+fe9iROE0Y;PECz<AH-%>0>Jeph3QgDGEM`Da8uP zhL#q_Afr(M7m(}g2=XKdoB-mCl9GaAD}DXk#FQMMM!jNVz0zXc^3>uIT_e53+{CK< zyu|Wiz2y8{{jB2rJbjS4dLS0qguz2BVPpgbB7<|(lLW7jM2kZwJ&iu?EVgUzb~U-P zs_mdfcbFaSqdty!FrAuorKD>KE<=>IP6GBvS F2>?&{rQQGl literal 0 HcmV?d00001 diff --git a/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti b/integration_tests/tests/data/accounts/get_asset_with_show_collection_metadata_option/8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti new file mode 100644 index 0000000000000000000000000000000000000000..4ce4fb62cecbf296f4de148948844fe865a1de52 GIT binary patch literal 312 zcmY#jfB*@G90nE!4+a$=H-NzfNJap00)qsQ%ztaDbFVke^QO+S9HEuhcs#SZ6V6T8 z_;3DN6VAv9PV?FBetUR5b>ZZjryshVdtJFkW=rea_-ONqRy|)^>;5yW)Bu|CK~^3} zGBEsyf}(&JArSv^dhC_Sj35>R!%`sbylEuCxJkw#F<{4)ORU?M`!9XFv$ZuUJYmyy z8FkagRsbIdh+mFkeu3 oL~in;#hz3C{uT2{`?o2@lY#T = seed_accounts( - ["F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk"] - ); + let seeds: Vec = seed_accounts([ + "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM", + "7fXKY9tPpvYsdbSNyesUqo27WYC6ZsBEULdtngGHqLCK", + "8Xv3SpX94HHf32Apg4TeSeS3i2p6wuXeE8FBZr168Hti", + ]); apply_migrations_and_delete_data(setup.db.clone()).await; @@ -33,7 +35,7 @@ async fn test_get_asset_with_show_collection_metadata_option() { let request = r#" { - "id": "F9Lw3ki3hJ7PF9HQXsBzoY8GyE6sPoEZZdXJBsTTD2rk", + "id": "AH6wj7T8Ke5nbukjtcobjjs1CDWUcQxndtnLkKAdrSrM", "displayOptions" : { "showCollectionMetadata": true } From 30814328bcd145b245bf5f3e51b666568c860c53 Mon Sep 17 00:00:00 2001 From: AhzamAkhtar Date: Fri, 27 Dec 2024 22:51:39 +0530 Subject: [PATCH 6/6] cleanup --- .../src/dao/extensions/asset_grouping.rs | 2 +- digital_asset_types/src/dao/full_asset.rs | 2 +- digital_asset_types/src/dao/scopes/asset.rs | 12 ++++-------- digital_asset_types/src/dapi/common/asset.rs | 2 +- digital_asset_types/src/dapi/get_asset.rs | 4 ++-- digital_asset_types/src/rpc/asset.rs | 2 +- digital_asset_types/src/rpc/options.rs | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) diff --git a/digital_asset_types/src/dao/extensions/asset_grouping.rs b/digital_asset_types/src/dao/extensions/asset_grouping.rs index 75e0442d7..d474c63bb 100644 --- a/digital_asset_types/src/dao/extensions/asset_grouping.rs +++ b/digital_asset_types/src/dao/extensions/asset_grouping.rs @@ -44,4 +44,4 @@ impl Related for asset_grouping::Entity { fn to() -> RelationDef { Relation::AssetData.def() } -} \ No newline at end of file +} diff --git a/digital_asset_types/src/dao/full_asset.rs b/digital_asset_types/src/dao/full_asset.rs index 695d71b2d..496fe2621 100644 --- a/digital_asset_types/src/dao/full_asset.rs +++ b/digital_asset_types/src/dao/full_asset.rs @@ -27,4 +27,4 @@ pub struct AssetRelated { pub struct FullAssetList { pub list: Vec, -} \ No newline at end of file +} diff --git a/digital_asset_types/src/dao/scopes/asset.rs b/digital_asset_types/src/dao/scopes/asset.rs index 9661aa893..7125f1c93 100644 --- a/digital_asset_types/src/dao/scopes/asset.rs +++ b/digital_asset_types/src/dao/scopes/asset.rs @@ -172,7 +172,7 @@ pub async fn get_assets( asset_ids: Vec>, pagination: &Pagination, limit: u64, - options : &Options, + options: &Options, ) -> Result, DbErr> { let cond = Condition::all() .add(asset::Column::Id.is_in(asset_ids)) @@ -353,9 +353,7 @@ pub async fn get_related_for_assets( } } } else { - let single_group_query = grouping_base_query - .all(conn) - .await?; + let single_group_query = grouping_base_query.all(conn).await?; for g in single_group_query.into_iter() { if let Some(asset) = assets_map.get_mut(&g.asset_id) { asset.groups.push((g, None)); @@ -363,7 +361,6 @@ pub async fn get_related_for_assets( } }; - Ok(assets_map.into_iter().map(|(_, v)| v).collect()) } @@ -392,8 +389,7 @@ pub async fn get_assets_by_condition( let assets = paginate(pagination, limit, stmt, sort_direction, asset::Column::Id) .all(conn) .await?; - let full_assets = - get_related_for_assets(conn, assets, options, None).await?; + let full_assets = get_related_for_assets(conn, assets, options, None).await?; Ok(full_assets) } @@ -582,4 +578,4 @@ fn filter_out_stale_creators(creators: &mut Vec) { creators.retain(|creator| creator.seq == seq); } } -} \ No newline at end of file +} diff --git a/digital_asset_types/src/dapi/common/asset.rs b/digital_asset_types/src/dapi/common/asset.rs index a4fa6dfd1..24fd620c3 100644 --- a/digital_asset_types/src/dapi/common/asset.rs +++ b/digital_asset_types/src/dapi/common/asset.rs @@ -494,4 +494,4 @@ pub fn asset_list_to_rpc( } (assets, errors) }) -} \ No newline at end of file +} diff --git a/digital_asset_types/src/dapi/get_asset.rs b/digital_asset_types/src/dapi/get_asset.rs index b3816989f..2ec7d9006 100644 --- a/digital_asset_types/src/dapi/get_asset.rs +++ b/digital_asset_types/src/dapi/get_asset.rs @@ -22,7 +22,7 @@ pub async fn get_assets( options: &Options, ) -> Result, DbErr> { let pagination = Pagination::Page { page: 1 }; - let assets = scopes::asset::get_assets(db, ids, &pagination, limit,options).await?; + let assets = scopes::asset::get_assets(db, ids, &pagination, limit, options).await?; let asset_list = build_asset_response(assets, limit, &pagination, options); let asset_map = asset_list .items @@ -30,4 +30,4 @@ pub async fn get_assets( .map(|asset| (asset.id.clone(), asset)) .collect(); Ok(asset_map) -} \ No newline at end of file +} diff --git a/digital_asset_types/src/rpc/asset.rs b/digital_asset_types/src/rpc/asset.rs index c3300bc6f..82476e13c 100644 --- a/digital_asset_types/src/rpc/asset.rs +++ b/digital_asset_types/src/rpc/asset.rs @@ -400,4 +400,4 @@ pub struct Asset { pub external_plugins: Option, #[serde(skip_serializing_if = "Option::is_none")] pub unknown_external_plugins: Option, -} \ No newline at end of file +} diff --git a/digital_asset_types/src/rpc/options.rs b/digital_asset_types/src/rpc/options.rs index 7e13c47b2..de41b088c 100644 --- a/digital_asset_types/src/rpc/options.rs +++ b/digital_asset_types/src/rpc/options.rs @@ -8,4 +8,4 @@ pub struct Options { pub show_unverified_collections: bool, #[serde(default)] pub show_collection_metadata: bool, -} \ No newline at end of file +}