forest/lotus_json/
allocation.rs

1// Copyright 2019-2025 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use super::*;
5use crate::shim::actors::verifreg::Allocation;
6use ::cid::Cid;
7use fvm_shared4::ActorID;
8use fvm_shared4::clock::ChainEpoch;
9use fvm_shared4::piece::PaddedPieceSize;
10
11#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
12#[serde(rename_all = "PascalCase")]
13#[schemars(rename = "Allocation")]
14pub struct AllocationLotusJson {
15    // The verified client which allocated the DataCap.
16    pub client: ActorID,
17    // The provider (miner actor) which may claim the allocation.
18    pub provider: ActorID,
19    // Identifier of the data to be committed.
20    #[schemars(with = "LotusJson<Cid>")]
21    #[serde(with = "crate::lotus_json")]
22    pub data: Cid,
23    // The (padded) size of data.
24    #[schemars(with = "u64")]
25    pub size: PaddedPieceSize,
26    // The minimum duration which the provider must commit to storing the piece to avoid
27    // early-termination penalties (epochs).
28    pub term_min: ChainEpoch,
29    // The maximum period for which a provider can earn quality-adjusted power
30    // for the piece (epochs).
31    pub term_max: ChainEpoch,
32    // The latest epoch by which a provider must commit data before the allocation expires.
33    pub expiration: ChainEpoch,
34}
35
36impl HasLotusJson for Allocation {
37    type LotusJson = AllocationLotusJson;
38    #[cfg(test)]
39    fn snapshots() -> Vec<(serde_json::Value, Self)> {
40        vec![(
41            json! {{
42                "TermMin": 0,
43                "TermMax": 0,
44                "Provider": 0,
45                "Client": 0,
46                "Expiration": 0,
47                "Size": 0,
48                "Data": {"/":"baeaaaaa"},
49            }},
50            Allocation {
51                term_min: 0,
52                term_max: 0,
53                provider: 0,
54                client: 0,
55                expiration: 0,
56                size: PaddedPieceSize(0),
57                data: Cid::default(),
58            },
59        )]
60    }
61    fn into_lotus_json(self) -> Self::LotusJson {
62        AllocationLotusJson {
63            client: self.client,
64            provider: self.provider,
65            data: self.data,
66            size: self.size,
67            term_min: self.term_min,
68            term_max: self.term_max,
69            expiration: self.expiration,
70        }
71    }
72    fn from_lotus_json(lotus_json: Self::LotusJson) -> Self {
73        Allocation {
74            client: lotus_json.client,
75            provider: lotus_json.provider,
76            data: lotus_json.data,
77            size: lotus_json.size,
78            term_min: lotus_json.term_min,
79            term_max: lotus_json.term_max,
80            expiration: lotus_json.expiration,
81        }
82    }
83}
84
85#[test]
86fn snapshots() {
87    assert_all_snapshots::<Allocation>();
88}