mod idx;
pub mod raw;
use serde::Deserialize;
use serde::Serialize;
pub use self::idx::ProofIdx;
use crate::types;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct CCProofId {
pub global_nonce: types::GlobalNonce,
pub difficulty: types::Difficulty,
pub idx: ProofIdx,
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct CCProof {
pub id: CCProofId,
pub local_nonce: types::LocalNonce,
pub cu_id: types::CUID,
pub result_hash: types::ResultHash,
}
impl CCProofId {
pub fn new(
global_nonce: types::GlobalNonce,
difficulty: types::Difficulty,
idx: ProofIdx,
) -> Self {
Self {
global_nonce,
difficulty,
idx,
}
}
pub fn after(&self, other: &Self) -> bool {
self.after_raw(other.idx)
}
pub fn after_raw(&self, proof_idx: ProofIdx) -> bool {
self.idx > proof_idx
}
}
impl CCProof {
pub fn new(
id: CCProofId,
local_nonce: types::LocalNonce,
cu_id: types::CUID,
result_hash: types::ResultHash,
) -> Self {
Self {
id,
local_nonce,
cu_id,
result_hash,
}
}
pub fn after(&self, other: &Self) -> bool {
self.id.idx > other.id.idx
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchRequest {
pub last_seen_proof_idx: ProofIdx,
pub proof_batch_size: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchResponse {
pub cu_id: types::CUID,
pub proof_batches: Vec<CCProof>,
}
impl BatchResponse {
pub fn new(cu_id: types::CUID, proof_batches: Vec<CCProof>) -> Self {
Self {
cu_id,
proof_batches,
}
}
}