11// Copyright (c) 2025 IOTA Stiftung
22// SPDX-License-Identifier: Apache-2.0
33
4- use std:: sync:: Arc ;
4+ use std:: { fmt , sync:: Arc } ;
55
66use iota_types:: { GasCostSummary , IdOperation } ;
77
@@ -31,6 +31,7 @@ use crate::types::{
3131/// (option digest) ; auxiliary data digest
3232/// ```
3333#[ derive( uniffi:: Record ) ]
34+ #[ uniffi:: export( Display ) ]
3435pub struct TransactionEffectsV1 {
3536 /// The status of the execution
3637 pub status : ExecutionStatus ,
@@ -69,6 +70,68 @@ pub struct TransactionEffectsV1 {
6970 pub auxiliary_data_digest : Option < Arc < Digest > > ,
7071}
7172
73+ impl fmt:: Display for TransactionEffectsV1 {
74+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
75+ // Helper to format optional digest
76+ let fmt_opt_digest = |d : & Option < Arc < Digest > > | -> String {
77+ d. as_ref ( )
78+ . map ( |v| v. to_string ( ) )
79+ . unwrap_or_else ( || "-" . to_string ( ) )
80+ } ;
81+ let dependencies = if self . dependencies . is_empty ( ) {
82+ String :: from ( "[]" )
83+ } else {
84+ format ! (
85+ "[{}]" ,
86+ self . dependencies
87+ . iter( )
88+ . map( |d| d. to_string( ) )
89+ . collect:: <Vec <_>>( )
90+ . join( ", " )
91+ )
92+ } ;
93+ let changed = if self . changed_objects . is_empty ( ) {
94+ String :: from ( "[]" )
95+ } else {
96+ format ! (
97+ "[{}]" ,
98+ self . changed_objects
99+ . iter( )
100+ . map( |c| c. to_string( ) )
101+ . collect:: <Vec <_>>( )
102+ . join( ", " )
103+ )
104+ } ;
105+ let unchanged = if self . unchanged_shared_objects . is_empty ( ) {
106+ String :: from ( "[]" )
107+ } else {
108+ format ! (
109+ "[{}]" ,
110+ self . unchanged_shared_objects
111+ . iter( )
112+ . map( |c| c. to_string( ) )
113+ . collect:: <Vec <_>>( )
114+ . join( ", " )
115+ )
116+ } ;
117+ write ! (
118+ f,
119+ "TransactionEffectsV1(status={}, epoch={}, gas_used={}, tx_digest={}, gas_object_index={:?}, events_digest={}, dependencies={}, lamport_version={}, changed_objects={}, unchanged_shared_objects={}, auxiliary_data_digest={})" ,
120+ self . status,
121+ self . epoch,
122+ self . gas_used,
123+ self . transaction_digest,
124+ self . gas_object_index,
125+ fmt_opt_digest( & self . events_digest) ,
126+ dependencies,
127+ self . lamport_version,
128+ changed,
129+ unchanged,
130+ fmt_opt_digest( & self . auxiliary_data_digest)
131+ )
132+ }
133+ }
134+
72135impl From < iota_types:: TransactionEffectsV1 > for TransactionEffectsV1 {
73136 fn from ( value : iota_types:: TransactionEffectsV1 ) -> Self {
74137 Self {
@@ -127,7 +190,8 @@ impl From<TransactionEffectsV1> for iota_types::TransactionEffectsV1 {
127190/// ```text
128191/// changed-object = object-id object-in object-out id-operation
129192/// ```
130- #[ derive( uniffi:: Record ) ]
193+ #[ derive( Debug , uniffi:: Record ) ]
194+ #[ uniffi:: export( Display ) ]
131195pub struct ChangedObject {
132196 /// Id of the object
133197 pub object_id : Arc < ObjectId > ,
@@ -141,6 +205,12 @@ pub struct ChangedObject {
141205 pub id_operation : IdOperation ,
142206}
143207
208+ impl fmt:: Display for ChangedObject {
209+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
210+ write ! ( f, "ChangedObject(object_id={})" , self . object_id)
211+ }
212+ }
213+
144214impl From < iota_types:: ChangedObject > for ChangedObject {
145215 fn from ( value : iota_types:: ChangedObject ) -> Self {
146216 Self {
@@ -172,12 +242,23 @@ impl From<ChangedObject> for iota_types::ChangedObject {
172242/// ```text
173243/// unchanged-shared-object = object-id unchanged-shared-object-kind
174244/// ```
175- #[ derive( uniffi:: Record ) ]
245+ #[ derive( Debug , uniffi:: Record ) ]
246+ #[ uniffi:: export( Display ) ]
176247pub struct UnchangedSharedObject {
177248 pub object_id : Arc < ObjectId > ,
178249 pub kind : UnchangedSharedKind ,
179250}
180251
252+ impl fmt:: Display for UnchangedSharedObject {
253+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
254+ write ! (
255+ f,
256+ "UnchangedSharedObject(object_id={}, kind={})" ,
257+ self . object_id, self . kind
258+ )
259+ }
260+ }
261+
181262impl From < iota_types:: UnchangedSharedObject > for UnchangedSharedObject {
182263 fn from ( value : iota_types:: UnchangedSharedObject ) -> Self {
183264 Self {
@@ -215,7 +296,7 @@ impl From<UnchangedSharedObject> for iota_types::UnchangedSharedObject {
215296/// cancelled = %x03 u64
216297/// per-epoch-config = %x04
217298/// ```
218- #[ derive( uniffi:: Enum ) ]
299+ #[ derive( Debug , uniffi:: Enum ) ]
219300pub enum UnchangedSharedKind {
220301 /// Read-only shared objects from the input. We don't really need
221302 /// ObjectDigest for protocol correctness, but it will make it easier to
@@ -285,7 +366,7 @@ impl From<UnchangedSharedKind> for iota_types::UnchangedSharedKind {
285366/// object-in-missing = %x00
286367/// object-in-data = %x01 u64 digest owner
287368/// ```
288- #[ derive( uniffi:: Enum ) ]
369+ #[ derive( Debug , uniffi:: Enum ) ]
289370pub enum ObjectIn {
290371 Missing ,
291372 /// The old version, digest and owner.
@@ -346,7 +427,7 @@ impl From<ObjectIn> for iota_types::ObjectIn {
346427/// object-out-object-write = %x01 digest owner
347428/// object-out-package-write = %x02 version digest
348429/// ```
349- #[ derive( uniffi:: Enum ) ]
430+ #[ derive( Debug , uniffi:: Enum ) ]
350431pub enum ObjectOut {
351432 /// Same definition as in ObjectIn.
352433 Missing ,
@@ -376,6 +457,27 @@ impl From<iota_types::ObjectOut> for ObjectOut {
376457 }
377458}
378459
460+ // Display impls for enums (placed after their definitions)
461+ impl fmt:: Display for UnchangedSharedKind {
462+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
463+ match self {
464+ UnchangedSharedKind :: ReadOnlyRoot { version, digest } => {
465+ write ! ( f, "ReadOnlyRoot(version={}, digest={})" , version, digest)
466+ }
467+ UnchangedSharedKind :: MutateDeleted { version } => {
468+ write ! ( f, "MutateDeleted(version={})" , version)
469+ }
470+ UnchangedSharedKind :: ReadDeleted { version } => {
471+ write ! ( f, "ReadDeleted(version={})" , version)
472+ }
473+ UnchangedSharedKind :: Cancelled { version } => {
474+ write ! ( f, "Cancelled(version={})" , version)
475+ }
476+ UnchangedSharedKind :: PerEpochConfig => write ! ( f, "PerEpochConfig" ) ,
477+ }
478+ }
479+ }
480+
379481impl From < ObjectOut > for iota_types:: ObjectOut {
380482 fn from ( value : ObjectOut ) -> Self {
381483 match value {
@@ -392,6 +494,35 @@ impl From<ObjectOut> for iota_types::ObjectOut {
392494 }
393495}
394496
497+ impl fmt:: Display for ObjectIn {
498+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
499+ match self {
500+ ObjectIn :: Missing => write ! ( f, "Missing" ) ,
501+ ObjectIn :: Data {
502+ version,
503+ digest,
504+ owner : _,
505+ } => {
506+ write ! ( f, "Data(version={}, digest={})" , version, digest)
507+ }
508+ }
509+ }
510+ }
511+
512+ impl fmt:: Display for ObjectOut {
513+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
514+ match self {
515+ ObjectOut :: Missing => write ! ( f, "Missing" ) ,
516+ ObjectOut :: ObjectWrite { digest, owner : _ } => {
517+ write ! ( f, "ObjectWrite(digest={})" , digest)
518+ }
519+ ObjectOut :: PackageWrite { version, digest } => {
520+ write ! ( f, "PackageWrite(version={}, digest={})" , version, digest)
521+ }
522+ }
523+ }
524+ }
525+
395526/// Defines what happened to an ObjectId during execution
396527///
397528/// # BCS
0 commit comments