Skip to content

Commit

Permalink
add object type to object info response (MystenLabs#1556)
Browse files Browse the repository at this point in the history
* add object type to object info response

* use enum instead of string

* update typescript objects
  • Loading branch information
patrickkuo authored Apr 25, 2022
1 parent 621e7a9 commit 69fa607
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/typescript/src/types/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ObjectRef = {

export type ObjectExistsInfo = {
objectRef: ObjectRef,
objectType: ObjectType,
object: any,
};

Expand All @@ -19,6 +20,7 @@ export type ObjectNotExistsInfo = {
};

export type ObjectStatus = 'Exists' | 'NotExists' | 'Deleted';
export type ObjectType = 'moveObject' | 'movePackage';


export type GetOwnedObjectRefsResponse = {
Expand Down
21 changes: 20 additions & 1 deletion sui/src/rest_gateway/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -141,6 +141,7 @@ impl<T: JsonSchema + Serialize + Send + Sync + 'static> HttpResponse for HttpRes
#[serde(rename_all = "camelCase")]
pub struct ObjectExistsResponse {
object_ref: NamedObjectRef,
object_type: MoveObjectType,
object: Value,
}

Expand All @@ -165,8 +166,10 @@ impl TryFrom<ObjectRead> for GetObjectInfoResponse {
fn try_from(obj: ObjectRead) -> Result<Self, Self::Error> {
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)?,
}))
}
Expand All @@ -177,3 +180,19 @@ impl TryFrom<ObjectRead> 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,
}
}
}

0 comments on commit 69fa607

Please sign in to comment.