miracle_api/dmt/
epoch_claim_data.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4/// Epoch-specific data for accurate historical reward calculations.
5/// This data is embedded in claim instructions to enable historical claims
6/// without requiring on-chain storage of historical snapshots.
7///
8/// NOTE: Only includes fields actually needed for reward calculation.
9/// Additional metadata fields are available in the SealProof structure
10/// if needed for future enhancements.
11#[repr(C)]
12#[derive(Debug, Clone, Copy, Pod, Zeroable, Serialize, Deserialize)]
13pub struct EpochClaimData {
14    pub customer_reward_pool: [u8; 8], // u64 - Epoch-specific customer reward pool
15    pub merchant_reward_pool: [u8; 8], // u64 - Epoch-specific merchant reward pool
16    pub total_customer_activity: [u8; 8], // u64 - Epoch-specific total customer activity
17    pub total_merchant_activity: [u8; 8], // u64 - Epoch-specific total merchant activity
18}
19
20impl EpochClaimData {
21    /// Deserialize from bytes manually
22    pub fn from_bytes(data: &[u8]) -> Result<Self, &'static str> {
23        let expected_size = std::mem::size_of::<Self>();
24        if data.len() < expected_size {
25            return Err("Insufficient data for EpochClaimData");
26        }
27
28        let customer_reward_pool: [u8; 8] = data[0..8]
29            .try_into()
30            .map_err(|_| "Invalid customer_reward_pool")?;
31        let merchant_reward_pool: [u8; 8] = data[8..16]
32            .try_into()
33            .map_err(|_| "Invalid merchant_reward_pool")?;
34        let total_customer_activity: [u8; 8] = data[16..24]
35            .try_into()
36            .map_err(|_| "Invalid total_customer_activity")?;
37        let total_merchant_activity: [u8; 8] = data[24..32]
38            .try_into()
39            .map_err(|_| "Invalid total_merchant_activity")?;
40
41        Ok(Self {
42            customer_reward_pool,
43            merchant_reward_pool,
44            total_customer_activity,
45            total_merchant_activity,
46        })
47    }
48}