22// SPDX-License-Identifier: Apache-2.0
33
44use bytes:: Bytes ;
5+ use fastcrypto:: traits:: ToFromBytes ;
56use futures:: stream:: Stream ;
67use futures:: stream:: TryStreamExt ;
78use prost_types:: FieldMask ;
9+ use prost_types:: value:: Kind as ProtoValueKind ;
810use std:: time:: Duration ;
911use sui_rpc:: field:: FieldMaskUtil ;
1012use sui_rpc:: proto:: TryFromProtoError ;
@@ -16,6 +18,7 @@ use sui_types::effects::{TransactionEffects, TransactionEvents};
1618use sui_types:: full_checkpoint_content:: Checkpoint ;
1719use sui_types:: messages_checkpoint:: { CertifiedCheckpointSummary , CheckpointSequenceNumber } ;
1820use sui_types:: object:: Object ;
21+ use sui_types:: signature:: GenericSignature ;
1922use sui_types:: transaction:: Transaction ;
2023use sui_types:: transaction:: TransactionData ;
2124use tap:: Pipe ;
@@ -276,6 +279,7 @@ impl Client {
276279 Ok ( SimulateTransactionResponse {
277280 transaction,
278281 command_outputs : response. command_outputs ,
282+ suggested_gas_price : response. suggested_gas_price ,
279283 } )
280284 }
281285
@@ -609,9 +613,11 @@ impl Client {
609613#[ derive( Clone , Debug , serde:: Serialize ) ]
610614pub struct ExecutedTransaction {
611615 pub transaction : TransactionData ,
616+ pub signatures : Vec < GenericSignature > ,
612617 pub effects : TransactionEffects ,
613618 pub clever_error : Option < proto:: CleverError > ,
614619 pub events : Option < TransactionEvents > ,
620+ pub event_json : Vec < Option < serde_json:: Value > > ,
615621 pub changed_objects : Vec < proto:: ChangedObject > ,
616622 #[ allow( unused) ]
617623 unchanged_loaded_runtime_objects : Vec < proto:: ObjectReference > ,
@@ -630,6 +636,10 @@ impl ExecutedTransaction {
630636 . transaction ( )
631637 . bcs ( )
632638 . finish ( ) ,
639+ ExecutedTransaction :: path_builder ( )
640+ . signatures ( )
641+ . bcs ( )
642+ . finish ( ) ,
633643 ExecutedTransaction :: path_builder ( ) . effects ( ) . bcs ( ) . finish ( ) ,
634644 ExecutedTransaction :: path_builder ( )
635645 . effects ( )
@@ -647,6 +657,7 @@ impl ExecutedTransaction {
647657 . changed_objects ( )
648658 . finish ( ) ,
649659 ExecutedTransaction :: path_builder ( ) . events ( ) . bcs ( ) . finish ( ) ,
660+ ExecutedTransaction :: path_builder ( ) . events ( ) . events ( ) . json ( ) ,
650661 ExecutedTransaction :: path_builder ( )
651662 . balance_changes ( )
652663 . finish ( ) ,
@@ -692,12 +703,18 @@ impl ExecutedTransaction {
692703 Some ( ( id, version, digest) )
693704 } )
694705 }
706+
707+ pub fn timestamp_ms ( & self ) -> Option < u64 > {
708+ self . timestamp
709+ . and_then ( |timestamp| sui_rpc:: proto:: proto_to_timestamp_ms ( timestamp) . ok ( ) )
710+ }
695711}
696712
697713#[ derive( Clone , Debug , serde:: Serialize ) ]
698714pub struct SimulateTransactionResponse {
699715 pub transaction : ExecutedTransaction ,
700716 pub command_outputs : Vec < proto:: CommandResult > ,
717+ pub suggested_gas_price : Option < u64 > ,
701718}
702719
703720/// Attempts to parse `CertifiedCheckpointSummary` from a proto::Checkpoint
@@ -767,6 +784,14 @@ fn executed_transaction_try_from_proto(
767784 . bcs ( )
768785 . deserialize ( )
769786 . map_err ( |e| TryFromProtoError :: invalid ( "effects.bcs" , e) ) ?;
787+ let signatures = executed_transaction
788+ . signatures ( )
789+ . iter ( )
790+ . map ( |sig| {
791+ GenericSignature :: from_bytes ( sig. bcs ( ) . value ( ) )
792+ . map_err ( |e| TryFromProtoError :: invalid ( "signatures.bcs" , e) )
793+ } )
794+ . collect :: < Result < _ , _ > > ( ) ?;
770795 let clever_error = executed_transaction
771796 . effects ( )
772797 . status ( )
@@ -781,6 +806,16 @@ fn executed_transaction_try_from_proto(
781806 . map ( |bcs| bcs. deserialize ( ) )
782807 . transpose ( )
783808 . map_err ( |e| TryFromProtoError :: invalid ( "events.bcs" , e) ) ?;
809+ let event_json = executed_transaction
810+ . events_opt ( )
811+ . map ( |events| {
812+ events
813+ . events ( )
814+ . iter ( )
815+ . map ( |event| event. json_opt ( ) . map ( proto_value_to_json_value) )
816+ . collect :: < Vec < _ > > ( )
817+ } )
818+ . unwrap_or_default ( ) ;
784819
785820 let balance_changes = executed_transaction
786821 . balance_changes
@@ -790,9 +825,11 @@ fn executed_transaction_try_from_proto(
790825
791826 ExecutedTransaction {
792827 transaction,
828+ signatures,
793829 effects,
794830 clever_error,
795831 events,
832+ event_json,
796833 balance_changes,
797834 checkpoint : executed_transaction. checkpoint ,
798835 changed_objects : executed_transaction. effects ( ) . changed_objects ( ) . to_owned ( ) ,
@@ -805,6 +842,28 @@ fn executed_transaction_try_from_proto(
805842 . pipe ( Ok )
806843}
807844
845+ fn proto_value_to_json_value ( proto : & prost_types:: Value ) -> serde_json:: Value {
846+ match proto. kind . as_ref ( ) {
847+ Some ( ProtoValueKind :: NullValue ( _) ) | None => serde_json:: Value :: Null ,
848+ Some ( ProtoValueKind :: NumberValue ( n) ) => serde_json:: Value :: from ( * n) ,
849+ Some ( ProtoValueKind :: StringValue ( s) ) => serde_json:: Value :: from ( s. clone ( ) ) ,
850+ Some ( ProtoValueKind :: BoolValue ( b) ) => serde_json:: Value :: from ( * b) ,
851+ Some ( ProtoValueKind :: StructValue ( map) ) => serde_json:: Value :: Object (
852+ map. fields
853+ . iter ( )
854+ . map ( |( k, v) | ( k. clone ( ) , proto_value_to_json_value ( v) ) )
855+ . collect ( ) ,
856+ ) ,
857+ Some ( ProtoValueKind :: ListValue ( list_value) ) => serde_json:: Value :: Array (
858+ list_value
859+ . values
860+ . iter ( )
861+ . map ( proto_value_to_json_value)
862+ . collect ( ) ,
863+ ) ,
864+ }
865+ }
866+
808867fn status_from_error_with_metadata < T : Into < BoxError > > ( err : T , metadata : MetadataMap ) -> Status {
809868 let mut status = Status :: from_error ( err. into ( ) ) ;
810869 * status. metadata_mut ( ) = metadata;
0 commit comments