ccp_shared/types/
epoch_parameters.rs

1/*
2 * Copyright 2024 Fluence DAO
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use serde::Deserialize;
18use serde::Serialize;
19
20use crate::proof::CCProofId;
21use crate::types::Difficulty;
22use crate::types::GlobalNonce;
23
24/// Describes a single epoch, contains global parameters, which come from the on-chain part.
25#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
26#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
27pub struct EpochParameters {
28    pub global_nonce: GlobalNonce,
29    pub difficulty: Difficulty,
30}
31
32impl EpochParameters {
33    pub const fn new(global_nonce: GlobalNonce, difficulty: Difficulty) -> Self {
34        Self {
35            global_nonce,
36            difficulty,
37        }
38    }
39}
40
41impl From<CCProofId> for EpochParameters {
42    fn from(id: CCProofId) -> Self {
43        Self {
44            global_nonce: id.global_nonce,
45            difficulty: id.difficulty,
46        }
47    }
48}
49
50use std::fmt;
51
52impl fmt::Display for EpochParameters {
53    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54        writeln!(f, "global nonce: {}", self.global_nonce)?;
55        writeln!(f, "difficulty: {}", self.difficulty)
56    }
57}