forest/lotus_json/
election_proof.rs1use crate::blocks::{ElectionProof, VRFProof};
5
6use super::*;
7
8#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "PascalCase")]
10#[schemars(rename = "ElectionProof")]
11pub struct ElectionProofLotusJson {
12 #[schemars(with = "LotusJson<VRFProof>")]
13 #[serde(with = "crate::lotus_json")]
14 v_r_f_proof: VRFProof,
15 win_count: i64,
16}
17
18impl HasLotusJson for ElectionProof {
19 type LotusJson = ElectionProofLotusJson;
20
21 #[cfg(test)]
22 fn snapshots() -> Vec<(serde_json::Value, Self)> {
23 vec![(
24 json!({
25 "WinCount": 0,
26 "VRFProof": null
27 }),
28 ElectionProof::default(),
29 )]
30 }
31
32 fn into_lotus_json(self) -> Self::LotusJson {
33 let Self {
34 win_count,
35 vrfproof,
36 } = self;
37 Self::LotusJson {
38 v_r_f_proof: vrfproof,
39 win_count,
40 }
41 }
42
43 fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
44 let Self::LotusJson {
45 v_r_f_proof,
46 win_count,
47 } = lotus_json;
48 Self {
49 win_count,
50 vrfproof: v_r_f_proof,
51 }
52 }
53}