Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AhzamAkhtar committed Dec 24, 2024
1 parent 4549aa1 commit d6b96d7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion das_api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct SearchAssets {
pub negate: Option<bool>,
pub condition_type: Option<SearchConditionType>,
pub interface: Option<Interface>,
pub token_type : Option<TokenTypeClass>,
pub token_type: Option<TokenTypeClass>,
pub owner_address: Option<String>,
pub owner_type: Option<OwnershipModel>,
pub creator_address: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions digital_asset_types/src/dao/extensions/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use sea_orm::{EntityTrait, EnumIter, Related, RelationDef, RelationTrait};

use crate::dao::{
asset, asset_authority, asset_creators, asset_data, asset_grouping,
asset_v1_account_attachments,token_accounts,
asset_v1_account_attachments,
sea_orm_active_enums::{OwnerType, RoyaltyTargetType},
token_accounts,
};


#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
AssetData,
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/src/dao/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub mod asset_data;
pub mod asset_grouping;
pub mod asset_v1_account_attachment;
pub mod instruction;
pub mod token_accounts;
pub mod token_accounts;
14 changes: 7 additions & 7 deletions digital_asset_types/src/dao/extensions/token_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub enum Relation {
}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Asset => token_accounts::Entity::belongs_to(asset::Entity)
.from(token_accounts::Column::Mint)
.to(asset::Column::Id)
.into(),
fn def(&self) -> RelationDef {
match self {
Self::Asset => token_accounts::Entity::belongs_to(asset::Entity)
.from(token_accounts::Column::Mint)
.to(asset::Column::Id)
.into(),
}
}
}
Expand All @@ -23,4 +23,4 @@ impl Related<asset::Entity> for token_accounts::Entity {
fn to() -> RelationDef {
Relation::Asset.def()
}
}
}
109 changes: 56 additions & 53 deletions digital_asset_types/src/dao/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ pub struct SearchAssetsQuery {
}

impl SearchAssetsQuery {

pub fn check_for_onwer_type_and_token_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()));
"`owner_type` is not supported when using `token_type` field".to_string(),
));
}
Ok(())
}

pub fn check_for_owner_address_and_token_type(&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()));
"Must provide `owner_address` when using `token_type` field".to_string(),
));
}
Ok(())
}
pub fn check_for_token_type_and_interface(&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()));
.to_string(),
));
}
Ok(())
}
Expand All @@ -122,31 +122,34 @@ impl SearchAssetsQuery {
.add_option({
self.check_for_owner_address_and_token_type()?;
self.check_for_onwer_type_and_token_type()?;
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,
}
self.token_type.as_ref().map(|x| 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(),
})
})
.add_option({
self.check_for_token_type_and_interface()?;
self.specification_asset_class
.clone()
.map(|x| asset::Column::SpecificationAssetClass.eq(x))
.clone()
.map(|x| asset::Column::SpecificationAssetClass.eq(x))
})
.add_option(
self.delegate
Expand Down Expand Up @@ -198,17 +201,17 @@ impl SearchAssetsQuery {
match self.token_type {
Some(TokenTypeClass::Fungible) => {
conditions = conditions.add_option(Some(
asset::Column::OwnerType
.eq(OwnerType::Token)
.and((asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::FungibleToken))
.or(asset::Column::SpecificationAssetClass.eq(SpecificationAssetClass::FungibleAsset))
),
));
asset::Column::OwnerType.eq(OwnerType::Token).and(
(asset::Column::SpecificationAssetClass
.eq(SpecificationAssetClass::FungibleToken))
.or(asset::Column::SpecificationAssetClass
.eq(SpecificationAssetClass::FungibleAsset)),
),
));
}
Some(TokenTypeClass::All) => {
conditions = conditions.add_option(Some(
asset::Column::SpecificationAssetClass.is_not_null(),
));
conditions = conditions
.add_option(Some(asset::Column::SpecificationAssetClass.is_not_null()));
}
_ => {
// Default to NFTs
Expand All @@ -217,14 +220,13 @@ impl SearchAssetsQuery {
// however there is an old bug that has marked some non-NFTs as "single" with supply > 1.
// The supply check guarentees we do not include those.
conditions = conditions.add_option(Some(
asset::Column::OwnerType
.eq(OwnerType::Single)
.and(asset::Column::Supply.lte(1)),
));
asset::Column::OwnerType
.eq(OwnerType::Single)
.and(asset::Column::Supply.lte(1)),
));
}
}

}
}

if let Some(c) = self.creator_address.to_owned() {
conditions = conditions.add(asset_creators::Column::Creator.eq(c));
Expand Down Expand Up @@ -264,21 +266,22 @@ impl SearchAssetsQuery {
}

if let Some(o) = self.owner_address.to_owned() {
if self.token_type == Some(TokenTypeClass::Fungible) || self.token_type == Some(TokenTypeClass::All) {
if self.token_type == Some(TokenTypeClass::Fungible)
|| self.token_type == Some(TokenTypeClass::All)
{
conditions = conditions.add(token_accounts::Column::Owner.eq(o));
let rel = extensions::token_accounts::Relation::Asset
.def()
.rev()
.on_condition(|left, right| {
Expr::tbl(right, token_accounts::Column::Mint)
.eq(Expr::tbl(left, asset::Column::Id))
.into_condition()
});
joins.push(rel);
let rel = extensions::token_accounts::Relation::Asset
.def()
.rev()
.on_condition(|left, right| {
Expr::tbl(right, token_accounts::Column::Mint)
.eq(Expr::tbl(left, asset::Column::Id))
.into_condition()
});
joins.push(rel);
} else {
conditions = conditions.add(asset::Column::Owner.eq(o));
}

}

if let Some(g) = self.grouping.to_owned() {
Expand Down
6 changes: 3 additions & 3 deletions digital_asset_types/src/rpc/filter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

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

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

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
Expand Down
2 changes: 0 additions & 2 deletions integration_tests/tests/integration_tests/token_type_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ async fn test_search_asset_with_token_type_regular_nft() {
insta::assert_json_snapshot!(name, response);
}


#[tokio::test]
#[serial]
#[named]
Expand Down Expand Up @@ -149,7 +148,6 @@ async fn test_search_asset_with_token_type_all() {
insta::assert_json_snapshot!(name, response);
}


#[tokio::test]
#[serial]
#[named]
Expand Down

0 comments on commit d6b96d7

Please sign in to comment.