use chia_sha2::Sha256;
use dig_protocol::Bytes32;
use serde::{Deserialize, Serialize};
use crate::appeal::ground::{AttesterSlashingAppeal, InvalidBlockAppeal, ProposerSlashingAppeal};
use crate::constants::DOMAIN_SLASH_APPEAL;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[allow(clippy::large_enum_variant)]
pub enum SlashAppealPayload {
Proposer(ProposerSlashingAppeal),
Attester(AttesterSlashingAppeal),
InvalidBlock(InvalidBlockAppeal),
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct SlashAppeal {
pub evidence_hash: Bytes32,
pub appellant_index: u32,
pub appellant_puzzle_hash: Bytes32,
pub filed_epoch: u64,
pub payload: SlashAppealPayload,
}
impl SlashAppeal {
pub fn hash(&self) -> Bytes32 {
let mut h = Sha256::new();
h.update(DOMAIN_SLASH_APPEAL);
let encoded = bincode::serialize(self).expect("SlashAppeal bincode must not fail");
h.update(&encoded);
let out: [u8; 32] = h.finalize();
Bytes32::new(out)
}
}