diff --git a/sdk/typescript/src/types/objects.ts b/sdk/typescript/src/types/objects.ts index 1bd1c077a5b80..df5e342dc9ad0 100644 --- a/sdk/typescript/src/types/objects.ts +++ b/sdk/typescript/src/types/objects.ts @@ -11,6 +11,7 @@ export type ObjectRef = { export type ObjectExistsInfo = { objectRef: ObjectRef, + objectType: ObjectType, object: any, }; @@ -19,6 +20,7 @@ export type ObjectNotExistsInfo = { }; export type ObjectStatus = 'Exists' | 'NotExists' | 'Deleted'; +export type ObjectType = 'moveObject' | 'movePackage'; export type GetOwnedObjectRefsResponse = { diff --git a/sui/src/rest_gateway/responses.rs b/sui/src/rest_gateway/responses.rs index b24f666ecaab9..34a3ea67c387e 100644 --- a/sui/src/rest_gateway/responses.rs +++ b/sui/src/rest_gateway/responses.rs @@ -21,7 +21,7 @@ use sui_types::base_types::{ObjectDigest, ObjectID, ObjectRef, SequenceNumber}; use sui_types::crypto::SignableBytes; use sui_types::error::SuiError; use sui_types::messages::TransactionData; -use sui_types::object::ObjectRead; +use sui_types::object::{Data, ObjectRead}; #[serde_as] #[derive(Serialize, Deserialize, JsonSchema)] @@ -141,6 +141,7 @@ impl HttpResponse for HttpRes #[serde(rename_all = "camelCase")] pub struct ObjectExistsResponse { object_ref: NamedObjectRef, + object_type: MoveObjectType, object: Value, } @@ -165,8 +166,10 @@ impl TryFrom for GetObjectInfoResponse { fn try_from(obj: ObjectRead) -> Result { match obj { ObjectRead::Exists(object_ref, object, layout) => { + let object_type = MoveObjectType::from_data(&object.data); Ok(Self::Exists(ObjectExistsResponse { object_ref: object_ref.into(), + object_type, object: object.to_json(&layout)?, })) } @@ -177,3 +180,19 @@ impl TryFrom for GetObjectInfoResponse { } } } + +#[derive(Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "camelCase")] +pub enum MoveObjectType { + MoveObject, + MovePackage, +} + +impl MoveObjectType { + fn from_data(data: &Data) -> Self { + match data { + Data::Move(_) => MoveObjectType::MoveObject, + Data::Package(_) => MoveObjectType::MovePackage, + } + } +}