1mod idx;
18pub mod raw;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23pub use self::idx::ProofIdx;
24use crate::types;
25
26#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
28#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
29pub struct CCProofId {
30 pub global_nonce: types::GlobalNonce,
31 pub difficulty: types::Difficulty,
32 pub idx: ProofIdx,
34}
35
36#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
38#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
39pub struct CCProof {
40 pub id: CCProofId,
41 pub local_nonce: types::LocalNonce,
42 pub cu_id: types::CUID,
43 pub result_hash: types::ResultHash,
44}
45
46impl CCProofId {
47 pub fn new(
48 global_nonce: types::GlobalNonce,
49 difficulty: types::Difficulty,
50 idx: ProofIdx,
51 ) -> Self {
52 Self {
53 global_nonce,
54 difficulty,
55 idx,
56 }
57 }
58
59 pub fn after(&self, other: &Self) -> bool {
61 self.after_raw(other.idx)
62 }
63
64 pub fn after_raw(&self, proof_idx: ProofIdx) -> bool {
66 self.idx > proof_idx
67 }
68}
69
70impl CCProof {
71 pub fn new(
72 id: CCProofId,
73 local_nonce: types::LocalNonce,
74 cu_id: types::CUID,
75 result_hash: types::ResultHash,
76 ) -> Self {
77 Self {
78 id,
79 local_nonce,
80 cu_id,
81 result_hash,
82 }
83 }
84
85 pub fn after(&self, other: &Self) -> bool {
87 self.id.idx > other.id.idx
88 }
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct BatchRequest {
93 pub last_seen_proof_idx: ProofIdx,
94 pub proof_batch_size: usize,
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct BatchResponse {
99 pub cu_id: types::CUID,
100 pub proof_batches: Vec<CCProof>,
101}
102
103impl BatchResponse {
104 pub fn new(cu_id: types::CUID, proof_batches: Vec<CCProof>) -> Self {
105 Self {
106 cu_id,
107 proof_batches,
108 }
109 }
110}