leo_bindings_core/
deployment_summary.rs1use colored::*;
2use num_format::{Locale, ToFormattedString};
3use snarkvm::{
4 ledger::store::helpers::memory::ConsensusMemory,
5 prelude::{
6 ConsensusVersion, Deployment, Execution, Network, Result, VM, deployment_cost,
7 execution_cost,
8 },
9};
10
11pub fn print_deployment_stats<N: Network>(
14 vm: &VM<N, ConsensusMemory<N>>,
15 program_id: &str,
16 deployment: &Deployment<N>,
17 priority_fee: Option<u64>,
18 consensus_version: ConsensusVersion,
19) -> Result<()> {
20 let variables = deployment.num_combined_variables()?;
22 let constraints = deployment.num_combined_constraints()?;
23 let (base_fee, (storage_cost, synthesis_cost, constructor_cost, namespace_cost)) =
24 deployment_cost(&vm.process().read(), deployment, consensus_version)?;
25
26 let base_fee_cr = base_fee as f64 / 1_000_000.0;
27 let prio_fee_cr = priority_fee.unwrap_or(0) as f64 / 1_000_000.0;
28 let total_fee_cr = base_fee_cr + prio_fee_cr;
29
30 log::info!(
32 "\n{} {}",
33 "📊 Deployment Summary for".bold(),
34 program_id.bold()
35 );
36 log::info!(
37 "{}",
38 "──────────────────────────────────────────────".dimmed()
39 );
40
41 log::info!(
43 " {:22}{}",
44 "Total Variables:".cyan(),
45 variables.to_formatted_string(&Locale::en).yellow()
46 );
47 log::info!(
48 " {:22}{}",
49 "Total Constraints:".cyan(),
50 constraints.to_formatted_string(&Locale::en).yellow()
51 );
52 log::info!(
53 " {:22}{}",
54 "Max Variables:".cyan(),
55 N::MAX_DEPLOYMENT_VARIABLES
56 .to_formatted_string(&Locale::en)
57 .green()
58 );
59 log::info!(
60 " {:22}{}",
61 "Max Constraints:".cyan(),
62 N::MAX_DEPLOYMENT_CONSTRAINTS
63 .to_formatted_string(&Locale::en)
64 .green()
65 );
66
67 log::info!("\n{}", "💰 Cost Breakdown (credits)".bold());
69 log::info!(
70 " {:22}{}{:.6}",
71 "Transaction Storage:".cyan(),
72 "".yellow(), storage_cost as f64 / 1_000_000.0
74 );
75 log::info!(
76 " {:22}{}{:.6}",
77 "Program Synthesis:".cyan(),
78 "".yellow(),
79 synthesis_cost as f64 / 1_000_000.0
80 );
81 log::info!(
82 " {:22}{}{:.6}",
83 "Namespace:".cyan(),
84 "".yellow(),
85 namespace_cost as f64 / 1_000_000.0
86 );
87 log::info!(
88 " {:22}{}{:.6}",
89 "Constructor:".cyan(),
90 "".yellow(),
91 constructor_cost as f64 / 1_000_000.0
92 );
93 log::info!(
94 " {:22}{}{:.6}",
95 "Priority Fee:".cyan(),
96 "".yellow(),
97 prio_fee_cr
98 );
99 log::info!(
100 " {:22}{}{:.6}",
101 "Total Fee:".cyan(),
102 "".yellow(),
103 total_fee_cr
104 );
105
106 log::info!(
108 "{}",
109 "──────────────────────────────────────────────".dimmed()
110 );
111
112 if variables > N::MAX_DEPLOYMENT_VARIABLES {
114 return Err(snarkvm::prelude::Error::msg(format!(
115 "Deployment exceeds maximum variables: {} > {}",
116 variables,
117 N::MAX_DEPLOYMENT_VARIABLES
118 )));
119 }
120
121 if constraints > N::MAX_DEPLOYMENT_CONSTRAINTS {
122 return Err(snarkvm::prelude::Error::msg(format!(
123 "Deployment exceeds maximum constraints: {} > {}",
124 constraints,
125 N::MAX_DEPLOYMENT_CONSTRAINTS
126 )));
127 }
128
129 Ok(())
130}
131
132pub fn print_execution_stats<N: Network>(
135 vm: &VM<N, ConsensusMemory<N>>,
136 program_name: &str,
137 execution: &Execution<N>,
138 priority_fee: Option<u64>,
139 consensus_version: ConsensusVersion,
140) -> Result<()> {
141 use colored::*;
142
143 let (base_fee, (storage_cost, execution_cost)) =
145 execution_cost(&vm.process().read(), execution, consensus_version)?;
146
147 let base_cr = base_fee as f64 / 1_000_000.0;
148 let prio_cr = priority_fee.unwrap_or(0) as f64 / 1_000_000.0;
149 let total_cr = base_cr + prio_cr;
150
151 log::info!(
153 "\n{} {}",
154 "📊 Execution Summary for".bold(),
155 program_name.bold()
156 );
157 log::info!(
158 "{}",
159 "──────────────────────────────────────────────".dimmed()
160 );
161
162 log::info!("{}", "💰 Cost Breakdown (credits)".bold());
164 log::info!(
165 " {:22}{}{:.6}",
166 "Transaction Storage:".cyan(),
167 "".yellow(),
168 storage_cost as f64 / 1_000_000.0
169 );
170 log::info!(
171 " {:22}{}{:.6}",
172 "On‑chain Execution:".cyan(),
173 "".yellow(),
174 execution_cost as f64 / 1_000_000.0
175 );
176 log::info!(
177 " {:22}{}{:.6}",
178 "Priority Fee:".cyan(),
179 "".yellow(),
180 prio_cr
181 );
182 log::info!(" {:22}{}{:.6}", "Total Fee:".cyan(), "".yellow(), total_cr);
183
184 log::info!(
186 "{}",
187 "──────────────────────────────────────────────".dimmed()
188 );
189 Ok(())
190}