Skip to content

Commit

Permalink
format the results separately
Browse files Browse the repository at this point in the history
  • Loading branch information
lanvidr committed Mar 4, 2024
1 parent 23a9274 commit 3bf0047
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 47 deletions.
105 changes: 63 additions & 42 deletions crates/sui-replay/src/displays/transaction_displays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::displays::Pretty;
use crate::replay::LocalExec;
use move_core_types::annotated_value::{MoveTypeLayout, MoveValue};
use move_core_types::language_storage::TypeTag;
use std::fmt::{Display, Formatter};
use std::fmt::{format, Display, Formatter};
use std::sync::Arc;
use sui_execution::Executor;
use sui_types::execution_mode::ExecutionResult;
Expand Down Expand Up @@ -38,6 +38,8 @@ impl<'a> Display for Pretty<'a, FullPTB> {
let mut builder = TableBuilder::default();

let ProgrammableTransaction { inputs, commands } = ptb;

// write input objects section
if !inputs.is_empty() {
let mut builder = TableBuilder::default();
for (i, input) in inputs.iter().enumerate() {
Expand Down Expand Up @@ -90,23 +92,34 @@ impl<'a> Display for Pretty<'a, FullPTB> {
write!(f, "\n No input objects for this transaction")?;
}

let mut table = builder.build();
table.with(TablePanel::header("Input Objects"));
table.with(TableStyle::rounded().horizontals([HorizontalLine::new(
1,
TableStyle::modern().get_horizontal(),
)]));
write!(f, "\n{}\n", table)?;
// write command results section
if results.len() > 0 {
write!(f, "\n\n")?;
}
for (i, result) in results.iter().enumerate() {
if i == results.len() - 1 {
write!(
f,
"╭───────────────────╮\n│ Command {i:<2} Output │\n╰───────────────────╯{}\n\n\n",
Pretty(result)
)?
} else {
write!(
f,
"╭───────────────────╮\n│ Command {i:<2} Output │\n╰───────────────────╯{}\n",
Pretty(result)
)?
}
}

// write ptb functions section
let mut builder = TableBuilder::default();
if !commands.is_empty() {
let mut builder = TableBuilder::default();
for ((i, c), result) in commands.iter().enumerate().zip(results) {
for (i, c) in commands.iter().enumerate() {
if i == commands.len() - 1 {
builder.push_record(vec![format!("{i:<2} {}", Pretty(c),)]);
display_result(f, result.clone())?;
builder.push_record(vec![format!("{i:<2} {}", Pretty(c))]);
} else {
builder.push_record(vec![format!("{i:<2} {}\n", Pretty(c),)]);
display_result(f, result.clone())?;
builder.push_record(vec![format!("{i:<2} {}\n", Pretty(c))]);
}
}

Expand All @@ -116,10 +129,12 @@ impl<'a> Display for Pretty<'a, FullPTB> {
1,
TableStyle::modern().get_horizontal(),
)]));
write!(f, "\n{}\n", table)
write!(f, "\n{}\n", table)?;
} else {
write!(f, "\n No commands for this transaction")
}

Ok(())
}
}

Expand Down Expand Up @@ -221,37 +236,43 @@ impl<'a> Display for Pretty<'a, Argument> {
write!(f, "{}", output)
}
}
impl<'a> Display for Pretty<'a, ResolvedResults> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let Pretty(ResolvedResults {
mutable_reference_outputs,
return_values,
}) = self;

fn display_result(f: &mut Formatter<'_>, result: &ResolvedResults) -> std::fmt::Result {
let ResolvedResults {
mutable_reference_outputs,
return_values,
} = result;
let len_m_ref = mutable_reference_outputs.len();
let len_ret_vals = return_values.len();

let len_m_ref = mutable_reference_outputs.len();
let len_ret_vals = return_values.len();
if len_ret_vals > 0 || len_m_ref > 0 {
write!(f, "\n ┌ ")?;
}
if len_m_ref > 0 {
write!(f, "\n │ Mutable Reference Outputs:")?;
}
for (arg, value) in mutable_reference_outputs {
write!(f, "\n │ {} ", arg)?;
write!(f, "\n │ {} ", value)?;
}
if len_ret_vals > 0 {
write!(f, "\n │ Return Values:")?;
}
if len_ret_vals > 0 {
write!(f, "\n Return Values:\n ──────────────")?;
}

for (i, value) in return_values.iter().enumerate() {
write!(f, "\n │ {i:<2} ")?;
write!(f, "\n │ {} ", value)?;
}
if len_ret_vals > 0 || len_m_ref > 0 {
write!(f, "\n └")?;
for (i, value) in return_values.iter().enumerate() {
write!(f, "\n • Result {i:<2} ")?;
write!(f, "\n{}\n", value)?;
}

if len_m_ref > 0 {
write!(
f,
"\n Mutable Reference Outputs:\n ──────────────────────────"
)?;
}

for (arg, value) in mutable_reference_outputs {
write!(f, "\n • {} ", arg)?;
write!(f, "\n{}\n", value)?;
}

if len_ret_vals == 0 && len_m_ref == 0 {
write!(f, "\n No return values")?;
}

Ok(())
}
Ok(())
}

impl<'a> Display for Pretty<'a, TypeTag> {
Expand Down
5 changes: 0 additions & 5 deletions crates/sui-replay/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use sui_framework::BuiltInFramework;
use sui_json_rpc_types::{SuiTransactionBlockEffects, SuiTransactionBlockEffectsAPI};
use sui_protocol_config::{Chain, ProtocolConfig};
use sui_sdk::{SuiClient, SuiClientBuilder};
use sui_types::execution::TypeLayoutStore;
use sui_types::storage::{get_module, PackageObject};
use sui_types::transaction::TransactionKind::ProgrammableTransaction;
use sui_types::{
Expand Down Expand Up @@ -697,10 +696,6 @@ impl LocalExec {
Ok((succeeded, num as u64))
}

pub fn type_layout_store_factory(&self) -> Box<dyn TypeLayoutStore> {
Box::new(self.clone())
}

pub async fn execution_engine_execute_with_tx_info_impl(
&mut self,
tx_info: &OnChainTransactionInfo,
Expand Down

0 comments on commit 3bf0047

Please sign in to comment.