Skip to main content

sui_graphql/
scalars.rs

1//! GraphQL scalar types for Sui.
2
3use std::borrow::Cow;
4
5use serde::Deserialize;
6
7/// `SuiAddress` scalar in Sui GraphQL schema. 32-byte hex-encoded address with `0x` prefix.
8pub use sui_sdk_types::Address;
9
10/// Useful for digest fields (Base58 string). Not a scalar in Sui GraphQL schema.
11pub use sui_sdk_types::Digest;
12
13/// `BigInt` scalar in Sui GraphQL schema.
14///
15/// Represented as a string because JSON numbers cannot reliably represent 64-bit integers.
16/// Deserializes from a string and parses as u64.
17pub struct BigInt(pub u64);
18
19impl<'de> Deserialize<'de> for BigInt {
20    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
21    where
22        D: serde::Deserializer<'de>,
23    {
24        let s = <Cow<'_, str>>::deserialize(deserializer)?;
25        let value = s.parse().map_err(serde::de::Error::custom)?;
26        Ok(BigInt(value))
27    }
28}
29
30/// `DateTime` scalar in Sui GraphQL schema.
31/// ISO-8601 Date and Time in UTC.
32pub type DateTime = chrono::DateTime<chrono::Utc>;