miracle-api 0.6.0

Miracle is a pay2e protocol for sovereign individuals living in Mirascape Horizon.
Documentation
use serde::{Deserialize, Serialize};
use steel::*;

/// Epoch-specific data for accurate historical reward calculations.
/// This data is embedded in claim instructions to enable historical claims
/// without requiring on-chain storage of historical snapshots.
///
/// NOTE: Only includes fields actually needed for reward calculation.
/// Additional metadata fields are available in the SealProof structure
/// if needed for future enhancements.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable, Serialize, Deserialize)]
pub struct EpochClaimData {
    pub customer_reward_pool: [u8; 8], // u64 - Epoch-specific customer reward pool
    pub merchant_reward_pool: [u8; 8], // u64 - Epoch-specific merchant reward pool
    pub total_customer_activity: [u8; 8], // u64 - Epoch-specific total customer activity
    pub total_merchant_activity: [u8; 8], // u64 - Epoch-specific total merchant activity
}

impl EpochClaimData {
    /// Deserialize from bytes manually
    pub fn from_bytes(data: &[u8]) -> Result<Self, &'static str> {
        let expected_size = std::mem::size_of::<Self>();
        if data.len() < expected_size {
            return Err("Insufficient data for EpochClaimData");
        }

        let customer_reward_pool: [u8; 8] = data[0..8]
            .try_into()
            .map_err(|_| "Invalid customer_reward_pool")?;
        let merchant_reward_pool: [u8; 8] = data[8..16]
            .try_into()
            .map_err(|_| "Invalid merchant_reward_pool")?;
        let total_customer_activity: [u8; 8] = data[16..24]
            .try_into()
            .map_err(|_| "Invalid total_customer_activity")?;
        let total_merchant_activity: [u8; 8] = data[24..32]
            .try_into()
            .map_err(|_| "Invalid total_merchant_activity")?;

        Ok(Self {
            customer_reward_pool,
            merchant_reward_pool,
            total_customer_activity,
            total_merchant_activity,
        })
    }
}