sui_graphql/move_value.rs
1//! Move value types for JSON and BCS representations.
2//!
3//! These types provide a unified interface for working with Move values
4//! returned from GraphQL queries, supporting both JSON and BCS formats.
5
6use sui_graphql_macros::Response;
7use sui_sdk_types::Address;
8use sui_sdk_types::TypeTag;
9
10use crate::bcs::BcsBytes;
11
12/// A Move value with type information and optional JSON/BCS representations.
13///
14/// This type can be used in Response structs to extract Move values from GraphQL.
15/// The JSON and BCS fields are optional - which ones are populated depends on
16/// what fields were requested in the GraphQL query.
17#[derive(Debug, Clone, Response)]
18#[response(root_type = "MoveValue")]
19pub struct MoveValue {
20 /// The Move type of this value.
21 #[field(path = "type.repr")]
22 pub type_tag: TypeTag,
23
24 /// JSON representation (if fetched).
25 #[field(path = "json?")]
26 pub json: Option<serde_json::Value>,
27
28 /// BCS representation (if fetched).
29 #[field(path = "bcs?")]
30 pub bcs: Option<BcsBytes>,
31}
32
33/// A Move object with its address and contents.
34#[derive(Debug, Clone, Response)]
35#[response(root_type = "MoveObject")]
36pub struct MoveObject {
37 /// The object's address.
38 #[field(path = "address")]
39 pub address: Address,
40 /// The object's contents as a MoveValue.
41 #[field(path = "contents")]
42 pub contents: MoveValue,
43}