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