fuel_core/schema/
assets.rs

1use async_graphql::{
2    Context,
3    Object,
4};
5
6use crate::{
7    fuel_core_graphql_api::query_costs,
8    graphql_api::storage::assets::AssetDetails,
9    schema::{
10        ReadViewProvider,
11        scalars::{
12            AssetId,
13            ContractId,
14            SubId,
15            U128,
16        },
17    },
18};
19
20#[derive(Default)]
21pub struct AssetInfoQuery;
22
23#[Object]
24impl AssetInfoQuery {
25    #[graphql(complexity = "query_costs().storage_read")]
26    async fn asset_details(
27        &self,
28        ctx: &Context<'_>,
29        #[graphql(desc = "ID of the Asset")] id: AssetId,
30    ) -> async_graphql::Result<Option<AssetInfoDetails>> {
31        let query = ctx.read_view()?;
32        let maybe_asset_details = query
33            .get_asset_details(&id.into())
34            .map_err(async_graphql::Error::from)?
35            .map(|details| details.into());
36        Ok(maybe_asset_details)
37    }
38}
39
40#[derive(Clone, Debug)]
41pub struct AssetInfoDetails {
42    pub contract_id: ContractId,
43    pub sub_id: SubId,
44    pub total_supply: U128,
45}
46
47impl From<AssetDetails> for AssetInfoDetails {
48    fn from(details: AssetDetails) -> Self {
49        AssetInfoDetails {
50            contract_id: details.contract_id.into(),
51            sub_id: details.sub_id.into(),
52            total_supply: details.total_supply.into(),
53        }
54    }
55}
56
57#[Object]
58impl AssetInfoDetails {
59    async fn contract_id(&self) -> &ContractId {
60        &self.contract_id
61    }
62
63    async fn sub_id(&self) -> &SubId {
64        &self.sub_id
65    }
66
67    async fn total_supply(&self) -> &U128 {
68        &self.total_supply
69    }
70}