af_oracle/graphql/
price_feed_for_source.rs

1use af_move_type::MoveInstance;
2use af_sui_types::Address;
3use sui_gql_client::GraphQlClient;
4use sui_gql_client::queries::{Error as QueryError, GraphQlClientExt as _};
5
6use crate::oracle::PriceFeed;
7
8type Key = crate::keys::PriceFeedForSource;
9
10pub(crate) async fn query<C>(
11    client: &C,
12    af_oracle_pkg: Address,
13    price_feed_storage: Address,
14    source_wrapper_id: Address,
15) -> Result<Option<MoveInstance<PriceFeed>>, Error<C::Error>>
16where
17    C: GraphQlClient,
18{
19    let key = Key::new(source_wrapper_id.into()).move_instance(af_oracle_pkg);
20    let raw_move_value = client
21        .owner_df_content(price_feed_storage, key.try_into()?, None)
22        .await;
23    match raw_move_value {
24        Ok(raw) => Ok(Some(raw.try_into()?)),
25        Err(QueryError::MissingData(_)) => Ok(None),
26        Err(err) => Err(Error::OwnerDfContent(err)),
27    }
28}
29
30#[derive(thiserror::Error, Debug)]
31pub enum Error<C: std::error::Error> {
32    #[error("Querying Owner DF content: {0}")]
33    OwnerDfContent(QueryError<C>),
34
35    #[error("BCS De/Ser: {0}")]
36    Bcs(#[from] bcs::Error),
37
38    #[error(transparent)]
39    FromRawType(#[from] af_move_type::FromRawTypeError),
40}