Skip to content

Commit 613f0bb

Browse files
authored
chore : add asset supply checks and return meaningful error message for getAsset method (#245)
1 parent 62323a4 commit 613f0bb

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

digital_asset_types/src/dao/scopes/asset.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use crate::{
1515
};
1616
use indexmap::IndexMap;
1717
use mpl_token_metadata::accounts::{Edition, MasterEdition};
18-
use sea_orm::{entity::*, query::*, sea_query::Expr, ConnectionTrait, DbErr, Order};
18+
use sea_orm::{
19+
entity::*, prelude::Decimal, query::*, sea_query::Expr, ConnectionTrait, DbErr, Order,
20+
};
1921
use serde::de::DeserializeOwned;
2022
use serde_json::Value;
2123
use solana_sdk::pubkey::Pubkey;
@@ -433,14 +435,10 @@ pub async fn get_assets_by_condition(
433435
pub async fn get_by_id(
434436
conn: &impl ConnectionTrait,
435437
asset_id: Vec<u8>,
436-
include_no_supply: bool,
437438
options: &Options,
438439
) -> Result<FullAsset, DbErr> {
439-
let mut asset_data =
440+
let asset_data =
440441
asset::Entity::find_by_id(asset_id.clone()).find_also_related(asset_data::Entity);
441-
if !include_no_supply {
442-
asset_data = asset_data.filter(Condition::all().add(asset::Column::Supply.gt(0)));
443-
}
444442

445443
let inscription = if options.show_inscription {
446444
get_inscription_by_mint(conn, asset_id.clone()).await.ok()
@@ -463,6 +461,10 @@ pub async fn get_by_id(
463461
_ => Err(DbErr::RecordNotFound("Asset Not Found".to_string())),
464462
})?;
465463

464+
if asset.supply == Decimal::from(0) {
465+
return Err(DbErr::Custom("Asset has no supply".to_string()));
466+
}
467+
466468
let authorities: Vec<asset_authority::Model> = asset_authority::Entity::find()
467469
.filter(asset_authority::Column::AssetId.eq(asset.id.clone()))
468470
.order_by_asc(asset_authority::Column::AssetId)

digital_asset_types/src/dapi/get_asset.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn get_asset(
1111
id: Vec<u8>,
1212
options: &Options,
1313
) -> Result<Asset, DbErr> {
14-
let asset = scopes::asset::get_by_id(db, id, false, options).await?;
14+
let asset = scopes::asset::get_by_id(db, id, options).await?;
1515
asset_to_rpc(asset, options)
1616
}
1717

0 commit comments

Comments
 (0)