iota_replay/displays/
gas_status_displays.rs

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