snark/
snark_event.rs

1use ledger::scan_state::transaction_logic::valid;
2use serde::{Deserialize, Serialize};
3
4use super::{
5    block_verify::{SnarkBlockVerifyError, SnarkBlockVerifyId},
6    work_verify::{SnarkWorkVerifyError, SnarkWorkVerifyId},
7};
8use crate::user_command_verify::SnarkUserCommandVerifyId;
9
10#[derive(Serialize, Deserialize, Debug, Clone)]
11pub enum SnarkEvent {
12    BlockVerify(SnarkBlockVerifyId, Result<(), SnarkBlockVerifyError>),
13    WorkVerify(SnarkWorkVerifyId, Result<(), SnarkWorkVerifyError>),
14    UserCommandVerify(
15        SnarkUserCommandVerifyId,
16        Result<Vec<valid::UserCommand>, String>,
17    ),
18}
19
20fn res_kind<T, E>(res: &Result<T, E>) -> &'static str {
21    match res {
22        Err(_) => "Err",
23        Ok(_) => "Ok",
24    }
25}
26
27impl std::fmt::Display for SnarkEvent {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        write!(f, "Snark, ")?;
30        match self {
31            Self::BlockVerify(id, res) => {
32                write!(f, "BlockVerify, {id}, {}", res_kind(res))
33            }
34            Self::WorkVerify(id, res) => {
35                write!(f, "WorkVerify, {id}, {}", res_kind(res))
36            }
37            Self::UserCommandVerify(id, res) => {
38                //let n_failed = res.iter().filter(|res| res.is_err()).count();
39                //let n_success = res.len() - n_failed;
40                write!(f, "UserCommandVerify, {id}, success={}", res.is_err())
41            }
42        }
43    }
44}