newton-core 0.5.4

newton protocol core sdk
Documentation
/// Immutable policy runtime snapshot resolved at request entry.
///
/// Superset of all policy inputs needed across data generation + evaluation:
/// - Data gen: policy_address, policy_id, policy_cid, current_block, expire_block, policy_code_hash, policy_data_infos
/// - Eval: policy_config, entrypoint, schema
///
/// Resolved ONCE per createTask commit, eliminating redundant sequential RPC reads.
use alloy::primitives::{Address, Bytes, B256};
use serde::{Deserialize, Serialize};

/// Per-PolicyData metadata for data generation fan-out.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PolicyDataInfo {
    /// On-chain policy data contract address.
    pub policy_data_address: Address,
    /// IPFS CID of the WASM component binary.
    pub wasm_cid: String,
    /// IPFS CID of the secrets JSON schema (empty if no secrets).
    pub secrets_schema_cid: String,
}

/// Immutable snapshot of all policy inputs for a single task evaluation.
#[derive(Debug, Clone)]
pub struct PolicyRuntime {
    /// Source/target chain ID where policy contracts live.
    pub chain_id: u64,
    /// Policy client address.
    pub policy_client: Address,
    /// Content-addressed policy generation hash.
    pub policy_id: B256,
    /// Resolved policy contract address for this client.
    pub policy_address: Address,
    /// ABI-encoded policy parameters + expireAfter.
    pub policy_config: crate::newton_policy::INewtonPolicy::PolicyConfig,
    /// Rego entrypoint returned by policy contract.
    pub entrypoint: String,
    /// Schema JSON fetched from IPFS.
    pub schema: serde_json::Value,
    /// IPFS CID of the Rego policy source.
    pub policy_cid: String,
    /// On-chain keccak256(policy_bytes) for integrity binding.
    pub policy_code_hash: B256,
    /// Block number at resolution time.
    pub current_block: u32,
    /// Expiration block = current_block + policy_config.expireAfter.
    pub expire_block: u32,
    /// Per-PolicyData metadata for data generation (WASM CIDs, secrets schema).
    pub policy_data_infos: Vec<PolicyDataInfo>,
}