Skip to main content

forest/lotus_json/
ticket.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use crate::blocks::{Ticket, VRFProof};
5
6use super::*;
7
8#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "PascalCase")]
10#[schemars(rename = "Ticket")]
11pub struct TicketLotusJson {
12    #[schemars(with = "LotusJson<VRFProof>")]
13    #[serde(with = "crate::lotus_json")]
14    v_r_f_proof: VRFProof,
15}
16
17impl HasLotusJson for Ticket {
18    type LotusJson = TicketLotusJson;
19
20    #[cfg(test)]
21    fn snapshots() -> Vec<(serde_json::Value, Self)> {
22        vec![(
23            json!({"VRFProof": "aGVsbG8gd29ybGQh"}),
24            Ticket {
25                vrfproof: crate::blocks::VRFProof(Vec::from_iter(*b"hello world!")),
26            },
27        )]
28    }
29
30    fn into_lotus_json(self) -> Self::LotusJson {
31        let Self { vrfproof } = self;
32        Self::LotusJson {
33            v_r_f_proof: vrfproof,
34        }
35    }
36
37    fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
38        let Self::LotusJson { v_r_f_proof } = lotus_json;
39        Self {
40            vrfproof: v_r_f_proof,
41        }
42    }
43}