sui_replay/displays/
gas_status_displays.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::displays::Pretty;
5use std::fmt::{Display, Formatter};
6use sui_types::gas::SuiGasStatus;
7use sui_types::gas_model::gas_v2::SuiGasStatus as GasStatusV2;
8use tabled::{
9    builder::Builder as TableBuilder,
10    settings::{Style as TableStyle, style::HorizontalLine},
11};
12
13impl Display for Pretty<'_, SuiGasStatus> {
14    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15        let Pretty(sui_gas_status) = self;
16        match sui_gas_status {
17            SuiGasStatus::V2(s) => {
18                display_info(f, s)?;
19                per_object_storage_table(f, s)?;
20            }
21        };
22        Ok(())
23    }
24}
25
26fn per_object_storage_table(f: &mut Formatter, sui_gas_status: &GasStatusV2) -> std::fmt::Result {
27    let mut builder = TableBuilder::default();
28    builder.push_record(vec!["Object ID", "Bytes", "Old Rebate", "New Rebate"]);
29    for (object_id, per_obj_storage) in sui_gas_status.per_object_storage() {
30        builder.push_record(vec![
31            object_id.to_string(),
32            per_obj_storage.new_size.to_string(),
33            per_obj_storage.storage_rebate.to_string(),
34            per_obj_storage.storage_cost.to_string(),
35        ]);
36    }
37    let mut table = builder.build();
38
39    table.with(TableStyle::rounded().horizontals([HorizontalLine::new(
40        1,
41        TableStyle::modern().get_horizontal(),
42    )]));
43    write!(f, "\n{}\n", table)
44}
45
46fn display_info(f: &mut Formatter<'_>, sui_gas_status: &GasStatusV2) -> std::fmt::Result {
47    let mut builder = TableBuilder::default();
48    builder.push_record(vec!["Gas Info".to_string()]);
49    builder.push_record(vec![format!(
50        "Reference Gas Price: {}",
51        sui_gas_status.reference_gas_price()
52    )]);
53    builder.push_record(vec![format!(
54        "Gas Price: {}",
55        sui_gas_status.gas_status.gas_price()
56    )]);
57
58    builder.push_record(vec![format!(
59        "Max Gas Stack Height: {}",
60        sui_gas_status.gas_status.stack_height_high_water_mark()
61    )]);
62
63    builder.push_record(vec![format!(
64        "Max Gas Stack Size: {}",
65        sui_gas_status.gas_status.stack_size_high_water_mark()
66    )]);
67
68    builder.push_record(vec![format!(
69        "Number of Bytecode Instructions Executed: {}",
70        sui_gas_status.gas_status.instructions_executed()
71    )]);
72
73    let mut table = builder.build();
74    table.with(TableStyle::rounded());
75
76    write!(f, "\n{}\n", table)
77}