Skip to content

Commit bac3f50

Browse files
[cherry-pick][cli] Fixes pretty printing for tx output (#25480) (#25489)
## Description Fix pretty printing for transaction results, as well as json output format, to match what used to exist before 1.65.0. The JSON format has one slight difference, so not sure what's the best approach here: old: ``` "confirmedLocalExecution": true ``` new: ``` "timestampMs": "1771265071051", "checkpoint": "354" ``` ## Test plan Existing tests. --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] gRPC: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] Indexing Framework:
1 parent 1f85adf commit bac3f50

File tree

7 files changed

+435
-9
lines changed

7 files changed

+435
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sui-rpc-api/src/client/mod.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use bytes::Bytes;
5+
use fastcrypto::traits::ToFromBytes;
56
use futures::stream::Stream;
67
use futures::stream::TryStreamExt;
78
use prost_types::FieldMask;
9+
use prost_types::value::Kind as ProtoValueKind;
810
use std::time::Duration;
911
use sui_rpc::field::FieldMaskUtil;
1012
use sui_rpc::proto::TryFromProtoError;
@@ -16,6 +18,7 @@ use sui_types::effects::{TransactionEffects, TransactionEvents};
1618
use sui_types::full_checkpoint_content::Checkpoint;
1719
use sui_types::messages_checkpoint::{CertifiedCheckpointSummary, CheckpointSequenceNumber};
1820
use sui_types::object::Object;
21+
use sui_types::signature::GenericSignature;
1922
use sui_types::transaction::Transaction;
2023
use sui_types::transaction::TransactionData;
2124
use 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)]
610614
pub 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)]
698714
pub 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+
808867
fn 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;

crates/sui/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ sui-protocol-config.workspace = true
8282
shared-crypto.workspace = true
8383
sui-transaction-builder.workspace = true
8484
move-binary-format.workspace = true
85+
move-bytecode-utils.workspace = true
8586
move-trace-format.workspace = true
8687
move-bytecode-source-map.workspace = true
8788
mysten-common.workspace = true

0 commit comments

Comments
 (0)