Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPC API Improvement] - Add object type to transaction effect [SUI-62] #6636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/sui-adapter/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,12 @@ fn process_successful_execution<S: Storage + ParentSync>(
}
},
};
let obj = state_view
.read_object(&id)
.expect("We previously checked all input objects exist").clone();
changes.insert(
id,
ObjectChange::Delete(tx_ctx.clone(), version, delete_kind),
ObjectChange::Delete(tx_ctx.clone(), obj, version, delete_kind),
);
}

Expand Down
50 changes: 36 additions & 14 deletions crates/sui-json-rpc-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tracing::warn;
use fastcrypto::encoding::{Base64, Encoding};
use sui_json::SuiJsonValue;
use sui_types::base_types::{
AuthorityName, ObjectDigest, ObjectID, ObjectInfo, ObjectRef, SequenceNumber, SuiAddress,
AuthorityName, ObjectDigest, ObjectID, ObjectType, ObjectInfo, ObjectRef, ObjectRefAndType, SequenceNumber, SuiAddress,
TransactionDigest, TransactionEffectsDigest,
};
use sui_types::committee::EpochId;
Expand Down Expand Up @@ -316,7 +316,7 @@ pub enum MoveFunctionArgType {
Object(ObjectValueKind),
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't remove JsonSchema

pub struct SuiTransactionResponse {
pub certificate: SuiCertifiedTransaction,
pub effects: SuiTransactionEffects,
Expand Down Expand Up @@ -370,7 +370,7 @@ impl Display for SuiParsedTransactionResponse {
}

#[allow(clippy::large_enum_variant)]
#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Debug)]
pub enum SuiExecuteTransactionResponse {
ImmediateReturn {
tx_digest: TransactionDigest,
Expand Down Expand Up @@ -587,6 +587,28 @@ impl From<ObjectRef> for SuiObjectRef {
}
}

#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd)]
#[serde(rename_all = "camelCase", rename = "ObjectRefAndType")]
pub struct SuiObjectRefAndType {
pub object_ref: ObjectRef,
pub object_type: ObjectType,
}

// impl SuiObjectRefAndType {
// pub fn to_object_ref_and_type(&self) -> ObjectRefAndType{
// (self.object_ref, self.object_type)
// }
// }

impl From<ObjectRefAndType> for SuiObjectRefAndType {
fn from(oref: ObjectRefAndType) -> Self {
Self {
object_ref: oref.0,
object_type: oref.1
}
}
}

impl Display for SuiParsedObject {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let type_ = if self.data.type_().is_some() {
Expand Down Expand Up @@ -1788,7 +1810,7 @@ impl TryFrom<VerifiedCertificate> for SuiCertifiedTransaction {
}

/// The certified Transaction Effects which has signatures from >= 2/3 of validators
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename = "CertifiedTransactionEffects", rename_all = "camelCase")]
pub struct SuiCertifiedTransactionEffects {
pub transaction_effects_digest: TransactionEffectsDigest,
Expand Down Expand Up @@ -1831,15 +1853,15 @@ impl SuiCertifiedTransactionEffects {
}

/// The response from processing a transaction or a certified transaction
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[derive(Eq, PartialEq, Clone, Debug, Serialize, Deserialize)]
#[serde(rename = "TransactionEffects", rename_all = "camelCase")]
pub struct SuiTransactionEffects {
// The status of the execution
pub status: SuiExecutionStatus,
pub gas_used: SuiGasCostSummary,
// The object references of the shared objects used in this transaction. Empty if no shared objects were used.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub shared_objects: Vec<SuiObjectRef>,
pub shared_objects: Vec<SuiObjectRefAndType>,
// The transaction digest
pub transaction_digest: TransactionDigest,
// ObjectRef and owner of new objects created.
Expand All @@ -1855,10 +1877,10 @@ pub struct SuiTransactionEffects {
pub unwrapped: Vec<OwnedObjectRef>,
// Object Refs of objects now deleted (the old refs).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub deleted: Vec<SuiObjectRef>,
pub deleted: Vec<SuiObjectRefAndType>,
// Object refs of objects now wrapped in other objects.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub wrapped: Vec<SuiObjectRef>,
pub wrapped: Vec<SuiObjectRefAndType>,
// The updated gas object reference. Have a dedicated field for convenient access.
// It's also included in mutated.
pub gas_object: OwnedObjectRef,
Expand Down Expand Up @@ -1931,13 +1953,13 @@ impl Display for SuiTransactionEffects {
if !self.deleted.is_empty() {
writeln!(writer, "Deleted Objects:")?;
for oref in &self.deleted {
writeln!(writer, " - ID: {}", oref.object_id)?;
writeln!(writer, " - ID: {}", oref.object_ref.0)?;
}
}
if !self.wrapped.is_empty() {
writeln!(writer, "Wrapped Objects:")?;
for oref in &self.wrapped {
writeln!(writer, " - ID: {}", oref.object_id)?;
writeln!(writer, " - ID: {}", oref.object_ref.0)?;
}
}
if !self.unwrapped.is_empty() {
Expand Down Expand Up @@ -1983,16 +2005,16 @@ impl From<ExecutionStatus> for SuiExecutionStatus {
}
}

fn to_sui_object_ref(refs: Vec<ObjectRef>) -> Vec<SuiObjectRef> {
refs.into_iter().map(SuiObjectRef::from).collect()
fn to_sui_object_ref(refs: Vec<ObjectRefAndType>) -> Vec<SuiObjectRefAndType> {
refs.into_iter().map(SuiObjectRefAndType::from).collect()
}

fn to_owned_ref(owned_refs: Vec<(ObjectRef, Owner)>) -> Vec<OwnedObjectRef> {
fn to_owned_ref(owned_refs: Vec<(ObjectRefAndType, Owner)>) -> Vec<OwnedObjectRef> {
owned_refs
.into_iter()
.map(|(oref, owner)| OwnedObjectRef {
owner,
reference: oref.into(),
reference: oref.0.into(),
})
.collect()
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct ObjectID(
);

pub type ObjectRef = (ObjectID, SequenceNumber, ObjectDigest);
pub type ObjectRefAndType = (ObjectRef, ObjectType);

pub fn random_object_ref() -> ObjectRef {
(
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub fn update_input_coins<S>(
&coin_object.id(),
coin_object.version(),
DeleteKind::Normal,
coin_object.clone(),
)
}
}
Expand Down
28 changes: 14 additions & 14 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,24 +1729,24 @@ pub struct TransactionEffects {
/// this transaction.
pub modified_at_versions: Vec<(ObjectID, SequenceNumber)>,
/// The object references of the shared objects used in this transaction. Empty if no shared objects were used.
pub shared_objects: Vec<ObjectRef>,
pub shared_objects: Vec<ObjectRefAndType>,
/// The transaction digest
pub transaction_digest: TransactionDigest,

// TODO: All the SequenceNumbers in the ObjectRefs below equal the same value (the lamport
// timestamp of the transaction). Consider factoring this out into one place in the effects.
/// ObjectRef and owner of new objects created.
pub created: Vec<(ObjectRef, Owner)>,
pub created: Vec<(ObjectRefAndType, Owner)>,
/// ObjectRef and owner of mutated objects, including gas object.
pub mutated: Vec<(ObjectRef, Owner)>,
pub mutated: Vec<(ObjectRefAndType, Owner)>,
/// ObjectRef and owner of objects that are unwrapped in this transaction.
/// Unwrapped objects are objects that were wrapped into other objects in the past,
/// and just got extracted out.
pub unwrapped: Vec<(ObjectRef, Owner)>,
pub unwrapped: Vec<(ObjectRefAndType, Owner)>,
/// Object Refs of objects now deleted (the old refs).
pub deleted: Vec<ObjectRef>,
pub deleted: Vec<ObjectRefAndType>,
/// Object refs of objects now wrapped in other objects.
pub wrapped: Vec<ObjectRef>,
pub wrapped: Vec<ObjectRefAndType>,
/// The updated gas object reference. Have a dedicated field for convenient access.
/// It's also included in mutated.
pub gas_object: (ObjectRef, Owner),
Expand All @@ -1761,7 +1761,7 @@ impl TransactionEffects {
/// created and unwrapped objects. In other words, all objects that still exist
/// in the object state after this transaction.
/// It doesn't include deleted/wrapped objects.
pub fn all_mutated(&self) -> impl Iterator<Item = (&ObjectRef, &Owner, WriteKind)> + Clone {
pub fn all_mutated(&self) -> impl Iterator<Item = (&ObjectRefAndType, &Owner, WriteKind)> + Clone {
self.mutated
.iter()
.map(|(r, o)| (r, o, WriteKind::Mutate))
Expand All @@ -1781,8 +1781,8 @@ impl TransactionEffects {
}

/// Return an iterator of mutated objects, but excluding the gas object.
pub fn mutated_excluding_gas(&self) -> impl Iterator<Item = &(ObjectRef, Owner)> {
self.mutated.iter().filter(|o| *o != &self.gas_object)
pub fn mutated_excluding_gas(&self) -> impl Iterator<Item = &(ObjectRefAndType, Owner)> {
self.mutated.iter()
}

pub fn gas_cost_summary(&self) -> &GasCostSummary {
Expand Down Expand Up @@ -1832,31 +1832,31 @@ impl Display for TransactionEffects {
writeln!(writer, "Status : {:?}", self.status)?;
if !self.created.is_empty() {
writeln!(writer, "Created Objects:")?;
for ((id, _, _), owner) in &self.created {
for (((id, _, _), _), owner) in &self.created {
writeln!(writer, " - ID: {} , Owner: {}", id, owner)?;
}
}
if !self.mutated.is_empty() {
writeln!(writer, "Mutated Objects:")?;
for ((id, _, _), owner) in &self.mutated {
for (((id, _, _), _), owner) in &self.mutated {
writeln!(writer, " - ID: {} , Owner: {}", id, owner)?;
}
}
if !self.deleted.is_empty() {
writeln!(writer, "Deleted Objects:")?;
for (id, _, _) in &self.deleted {
for ((id, _, _),_) in &self.deleted {
writeln!(writer, " - ID: {}", id)?;
}
}
if !self.wrapped.is_empty() {
writeln!(writer, "Wrapped Objects:")?;
for (id, _, _) in &self.wrapped {
for ((id, _, _),_) in &self.wrapped {
writeln!(writer, " - ID: {}", id)?;
}
}
if !self.unwrapped.is_empty() {
writeln!(writer, "Unwrapped Objects:")?;
for ((id, _, _), owner) in &self.unwrapped {
for (((id, _, _),_), owner) in &self.unwrapped {
writeln!(writer, " - ID: {} , Owner: {}", id, owner)?;
}
}
Expand Down
11 changes: 10 additions & 1 deletion crates/sui-types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::messages::InputObjectKind;
use crate::move_package::MovePackage;
use crate::{
base_types::{
ObjectDigest, ObjectID, ObjectRef, SequenceNumber, SuiAddress, TransactionDigest,
ObjectDigest, ObjectID, ObjectRef, ObjectType, SequenceNumber, SuiAddress, TransactionDigest,
},
gas_coin::GasCoin,
};
Expand Down Expand Up @@ -449,6 +449,15 @@ impl Object {
(self.id(), self.version(), self.digest())
}

pub fn compute_object_type(&self) -> ObjectType{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute imply getting the object type need computation and could be expansive (e.g. compute digest), we can simply call this get_object_type

let type_ = self
.data
.type_()
.map(|tag| ObjectType::Struct(tag.clone()))
.unwrap_or(ObjectType::Package);
type_
}

pub fn id(&self) -> ObjectID {
use Data::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub enum DeleteKind {

pub enum ObjectChange {
Write(SingleTxContext, Object, WriteKind),
Delete(SingleTxContext, SequenceNumber, DeleteKind),
Delete(SingleTxContext, Object, SequenceNumber, DeleteKind),
}

#[derive(Clone)]
Expand Down
Loading