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

Fixed search-assets compatibility issues #226

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion das_api/src/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl ApiContract for DasApi {
negate,
condition_type,
interface,
token_type,
owner_address,
owner_type,
creator_address,
Expand Down Expand Up @@ -403,7 +404,7 @@ impl ApiContract for DasApi {

// Deserialize search assets query
let spec: Option<(SpecificationVersions, SpecificationAssetClass)> =
interface.map(|x| x.into());
interface.clone().map(|x| x.into());
let specification_version = spec.clone().map(|x| x.0);
let specification_asset_class = spec.map(|x| x.1);
let condition_type = condition_type.map(|x| match x {
Expand Down Expand Up @@ -431,8 +432,10 @@ impl ApiContract for DasApi {
let saq = SearchAssetsQuery {
negate,
condition_type,
interface,
specification_version,
specification_asset_class,
token_type,
owner_address,
owner_type,
creator_address,
Expand Down
3 changes: 2 additions & 1 deletion das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::DasApiError;
use async_trait::async_trait;
use digital_asset_types::rpc::filter::{AssetSortDirection, SearchConditionType};
use digital_asset_types::rpc::filter::{AssetSortDirection, SearchConditionType, TokenTypeClass};
use digital_asset_types::rpc::options::Options;
use digital_asset_types::rpc::response::{AssetList, TransactionSignatureList};
use digital_asset_types::rpc::{filter::AssetSorting, response::GetGroupingResponse};
Expand Down Expand Up @@ -94,6 +94,7 @@ pub struct SearchAssets {
pub negate: Option<bool>,
pub condition_type: Option<SearchConditionType>,
pub interface: Option<Interface>,
pub token_type : Option<TokenTypeClass>,
pub owner_address: Option<String>,
pub owner_type: Option<OwnershipModel>,
pub creator_address: Option<String>,
Expand Down
63 changes: 59 additions & 4 deletions digital_asset_types/src/dao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod full_asset;
mod generated;
pub mod scopes;
use crate::rpc::{filter::TokenTypeClass, Interface};

use self::sea_orm_active_enums::{
OwnerType, RoyaltyTargetType, SpecificationAssetClass, SpecificationVersions,
};
Expand Down Expand Up @@ -52,8 +54,10 @@ pub struct SearchAssetsQuery {
pub negate: Option<bool>,
/// Defaults to [ConditionType::All]
pub condition_type: Option<ConditionType>,
pub interface : Option<Interface>,
pub specification_version: Option<SpecificationVersions>,
pub specification_asset_class: Option<SpecificationAssetClass>,
pub token_type: Option<TokenTypeClass>,
pub owner_address: Option<Vec<u8>>,
pub owner_type: Option<OwnerType>,
pub creator_address: Option<Vec<u8>>,
Expand All @@ -75,6 +79,34 @@ pub struct SearchAssetsQuery {
}

impl SearchAssetsQuery {

pub fn check_onwer_type(&self) -> Result<(), DbErr> {
if self.token_type.is_some() && self.owner_type.is_some() {
return Err(DbErr::Custom(
"`owner_type` is not supported when using `token_type` field"
.to_string()));
}
Ok(())
}

pub fn check_owner_address(&self) -> Result<(), DbErr> {
if self.owner_address.is_none() && self.token_type.is_some() {
return Err(DbErr::Custom(
"Must provide `owner_address` when using `token_type` field"
.to_string()));
}
Ok(())
}

pub fn check_token_type(&self) -> Result<(), DbErr> {
if self.token_type.is_some() && self.interface.is_some() {
return Err(DbErr::Custom(
"`specification_asset_class` is not supported when using `token_type` field"
.to_string()));
}
Ok(())
}

pub fn conditions(&self) -> Result<(Condition, Vec<RelationDef>), DbErr> {
let mut conditions = match self.condition_type {
// None --> default to all when no option is provided
Expand All @@ -88,11 +120,34 @@ impl SearchAssetsQuery {
.clone()
.map(|x| asset::Column::SpecificationVersion.eq(x)),
)
.add_option(
self.specification_asset_class
.add_option({
self.check_owner_address()?;
match &self.token_type {
Some(x) => Some(match x {
TokenTypeClass::Compressed => asset::Column::TreeId.is_not_null(),
TokenTypeClass::Nft => asset::Column::TreeId.is_null()
.and(
asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::Nft)
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::MplCoreAsset))
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::ProgrammableNft)),
),
TokenTypeClass::NonFungible => asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::Nft)
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::ProgrammableNft))
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::MplCoreAsset)),
TokenTypeClass::Fungible => asset::Column::SpecificationAssetClass
.eq(SpecificationAssetClass::FungibleAsset)
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::FungibleToken)),
TokenTypeClass::All => asset::Column::SpecificationAssetClass.is_not_null(),
}),
None => None,
}
})
.add_option({
self.check_token_type()?;
self.specification_asset_class
.clone()
.map(|x| asset::Column::SpecificationAssetClass.eq(x)),
)
.map(|x| asset::Column::SpecificationAssetClass.eq(x))
})
.add_option(
self.owner_address
.to_owned()
Expand Down
10 changes: 10 additions & 0 deletions digital_asset_types/src/rpc/filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sea_orm::entity::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -31,6 +32,15 @@ pub enum AssetSortBy {
None,
}

#[derive(Debug, Clone, PartialEq, Eq ,EnumIter, Serialize, Deserialize,JsonSchema)]
pub enum TokenTypeClass {
Fungible,
NonFungible,
Compressed,
Nft,
All
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub enum AssetSortDirection {
#[serde(rename = "asc")]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

�Ÿ���9����mR�i\���꠽�]�
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
e 9;�:�$f��E�v�KA�
��\�%.���
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.B�Q�*pp-���U������g����>�
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions integration_tests/tests/integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mod common;
mod general_scenario_tests;
mod mpl_core_tests;
mod regular_nft_tests;
mod token_type_test;
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
---
source: integration_tests/tests/integration_tests/token_type_test.rs
expression: response
snapshot_kind: text
---
{
"total": 2,
"limit": 2,
"page": 1,
"items": [
{
"interface": "ProgrammableNFT",
"id": "8t77ShMViat27Sjphvi1FVPaGrhFcttPAkEnLCFp49Bo",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "https://cdn.hellomoon.io/public/silicons/metadata/1466.json",
"files": [],
"metadata": {
"name": "SILICON #1466",
"symbol": "SILI",
"token_standard": "ProgrammableNonFungible"
},
"links": {}
},
"authorities": [
{
"address": "A2QW89tFNDkkdvJv671tdknAyA21u6hvS7HTUyeMWnf3",
"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": "HS1oygRKNBG1nMqjSmaBXSQqQ7apWr14gUU4pW3aDMCP"
}
],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.05,
"basis_points": 500,
"primary_sale_happened": true,
"locked": false
},
"creators": [
{
"address": "8X2e7Lf3wmA9RPHpPH73kmTqqHHyZE9BcED6Y6TWaZCx",
"share": 0,
"verified": true
},
{
"address": "5bTgyaCCRNCem3DZXxdRREyesduc6adqwks8rRWGXx8D",
"share": 100,
"verified": false
}
],
"ownership": {
"frozen": true,
"delegated": true,
"delegate": "D98f1ebFe6kfZTcztLo1iPeKAwogbWHAgXzgSpdRDiu7",
"ownership_model": "single",
"owner": "2oerfxddTpK5hWAmCMYB6fr9WvNrjEH54CHCWK8sAq7g"
},
"supply": null,
"mutable": true,
"burnt": false
},
{
"interface": "ProgrammableNFT",
"id": "42AYryUGNmJMe9ycBXZekkYvdTehgbtECHs7SLu5JJTB",
"content": {
"$schema": "https://schema.metaplex.com/nft1.0.json",
"json_uri": "https://cdn.hellomoon.io/public/silicons/metadata/2835.json",
"files": [],
"metadata": {
"name": "SILICON #2835",
"symbol": "SILI",
"token_standard": "ProgrammableNonFungible"
},
"links": {}
},
"authorities": [
{
"address": "A2QW89tFNDkkdvJv671tdknAyA21u6hvS7HTUyeMWnf3",
"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": "HS1oygRKNBG1nMqjSmaBXSQqQ7apWr14gUU4pW3aDMCP"
}
],
"royalty": {
"royalty_model": "creators",
"target": null,
"percent": 0.05,
"basis_points": 500,
"primary_sale_happened": true,
"locked": false
},
"creators": [
{
"address": "8X2e7Lf3wmA9RPHpPH73kmTqqHHyZE9BcED6Y6TWaZCx",
"share": 0,
"verified": true
},
{
"address": "5bTgyaCCRNCem3DZXxdRREyesduc6adqwks8rRWGXx8D",
"share": 100,
"verified": false
}
],
"ownership": {
"frozen": true,
"delegated": true,
"delegate": "D98f1ebFe6kfZTcztLo1iPeKAwogbWHAgXzgSpdRDiu7",
"ownership_model": "single",
"owner": "2oerfxddTpK5hWAmCMYB6fr9WvNrjEH54CHCWK8sAq7g"
},
"supply": null,
"mutable": true,
"burnt": false
}
]
}
Loading