anvil_zksync_core/formatter/
pubdata_bytes.rs

1use crate::utils::to_human_size;
2
3/// Amount of pubdata that given write has cost.
4/// Used when displaying Storage Logs.
5pub enum PubdataBytesInfo {
6    // This slot is free
7    FreeSlot,
8    // This slot costs this much.
9    Paid(u32),
10    // This happens when we already paid a little for this slot in the past.
11    // This slots costs additional X, the total cost is Y.
12    AdditionalPayment(u32, u32),
13    // We already paid for this slot in this transaction.
14    PaidAlready,
15}
16
17impl std::fmt::Display for PubdataBytesInfo {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            PubdataBytesInfo::FreeSlot => write!(f, "Free Slot (no cost)"),
21            PubdataBytesInfo::Paid(cost) => {
22                write!(f, "Paid: {} bytes", to_human_size((*cost).into()))
23            }
24            PubdataBytesInfo::AdditionalPayment(additional_cost, total_cost) => write!(
25                f,
26                "Additional Payment: {} bytes (Total: {} bytes)",
27                to_human_size((*additional_cost).into()),
28                to_human_size((*total_cost).into())
29            ),
30            PubdataBytesInfo::PaidAlready => write!(f, "Already Paid (no additional cost)"),
31        }
32    }
33}
34
35impl PubdataBytesInfo {
36    // Whether the slot incurs any cost
37    pub fn does_cost(&self) -> bool {
38        match self {
39            PubdataBytesInfo::FreeSlot => false,
40            PubdataBytesInfo::Paid(_) => true,
41            PubdataBytesInfo::AdditionalPayment(_, _) => true,
42            PubdataBytesInfo::PaidAlready => false,
43        }
44    }
45}