solana_rpc_client/
spinner.rs

1#![cfg(feature = "spinner")]
2//! Spinner creator.
3//! This module is wrapped by the `spinner` feature, which is on by default.
4//! It can be disabled and the dependency on `indicatif` avoided by running
5//! with `default-features = false`
6
7use {
8    indicatif::{ProgressBar, ProgressStyle},
9    std::time::Duration,
10};
11
12pub fn new_progress_bar() -> ProgressBar {
13    let progress_bar = ProgressBar::new(42);
14    progress_bar.set_style(
15        ProgressStyle::default_spinner()
16            .template("{spinner:.green} {wide_msg}")
17            .expect("ProgressStyle::template direct input to be correct"),
18    );
19    progress_bar.enable_steady_tick(Duration::from_millis(100));
20    progress_bar
21}
22
23#[derive(Debug, Default)]
24pub struct SendTransactionProgress {
25    pub confirmed_transactions: usize,
26    pub total_transactions: usize,
27    pub block_height: u64,
28    pub last_valid_block_height: u64,
29}
30
31impl SendTransactionProgress {
32    pub fn set_message_for_confirmed_transactions(&self, progress_bar: &ProgressBar, status: &str) {
33        progress_bar.set_message(format!(
34            "{:>5.1}% | {:<40} [block height {}; re-sign in {} blocks]",
35            self.confirmed_transactions as f64 * 100. / self.total_transactions as f64,
36            status,
37            self.block_height,
38            self.last_valid_block_height
39                .saturating_sub(self.block_height),
40        ));
41    }
42}