sui_gql_client/queries/
outputs.rs

1use af_sui_types::{Address, StructTag, TypeTag, encode_base64_default};
2use derive_more::Display;
3
4/// An instance of a dynamic field or dynamic object.
5#[derive(Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
6pub enum DynamicField {
7    /// The object key (id, version) and the raw struct contents.
8    ///
9    /// The object key is useful to query further data about the object later.
10    /// It is also guaranteed that the contents are of a struct, since enums cannot be top-level
11    /// objects.
12    ///
13    /// Reference: <https://move-book.com/reference/enums.html>
14    #[display("DOF {{\n\t{_0}: {_1}\n}})")]
15    Object(ObjectKey, RawMoveStruct),
16    /// The raw Move value contents. Could be a primitive type, struct, or enum.
17    #[display("DF {{\n\t{_0}\n}})")]
18    Field(RawMoveValue),
19}
20
21/// Reference to a specific object instance in time.
22#[derive(Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
23#[display("({object_id}, {version})")]
24pub struct ObjectKey {
25    pub object_id: Address,
26    pub version: u64,
27}
28
29/// Raw representation of a Move value
30#[derive(Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
31#[display("{type_} {{\n\t{}\n}}", encode_base64_default(bcs))]
32pub struct RawMoveValue {
33    pub type_: TypeTag,
34    pub bcs: Vec<u8>,
35}
36
37#[cfg(feature = "move-type")]
38impl<T: af_move_type::MoveType> TryFrom<RawMoveValue> for af_move_type::MoveInstance<T> {
39    type Error = af_move_type::FromRawTypeError;
40    fn try_from(RawMoveValue { type_, bcs }: RawMoveValue) -> Result<Self, Self::Error> {
41        Self::from_raw_type(type_, &bcs)
42    }
43}
44
45#[cfg(feature = "move-type")]
46impl<T: af_move_type::MoveType> TryFrom<af_move_type::MoveInstance<T>> for RawMoveValue {
47    type Error = bcs::Error;
48    fn try_from(value: af_move_type::MoveInstance<T>) -> Result<Self, Self::Error> {
49        Ok(Self {
50            type_: value.type_.into(),
51            bcs: value.value.to_bcs()?,
52        })
53    }
54}
55
56/// Raw representation of a Move struct
57#[derive(Clone, Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash)]
58#[display("{type_} {{\n\t{}\n}}", encode_base64_default(bcs))]
59pub struct RawMoveStruct {
60    pub type_: StructTag,
61    pub bcs: Vec<u8>,
62}
63
64#[cfg(feature = "move-type")]
65impl<T: af_move_type::MoveStruct> TryFrom<RawMoveStruct> for af_move_type::MoveInstance<T> {
66    type Error = af_move_type::FromRawStructError;
67    fn try_from(RawMoveStruct { type_, bcs }: RawMoveStruct) -> Result<Self, Self::Error> {
68        Self::from_raw_struct(type_, &bcs)
69    }
70}
71
72#[cfg(feature = "move-type")]
73impl<T: af_move_type::MoveStruct> TryFrom<af_move_type::MoveInstance<T>> for RawMoveStruct {
74    type Error = bcs::Error;
75    fn try_from(value: af_move_type::MoveInstance<T>) -> Result<Self, Self::Error> {
76        Ok(Self {
77            type_: value.type_.into(),
78            bcs: value.value.to_bcs()?,
79        })
80    }
81}