rialo-feature-management-program-interface 0.8.0-alpha.0

Rialo Feature Management Program Interface
Documentation
// Copyright (c) Subzero Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Instruction types for the Feature Management Program

extern crate alloc;
use alloc::{string::String, vec::Vec};

use borsh::{BorshDeserialize, BorshSerialize};
use rialo_s_pubkey::Pubkey;

/// Instructions supported by the Feature Management Program
#[derive(Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub enum FeatureManagementInstruction {
    /// Upsert a feature entry (add or modify).
    ///
    /// Times are Unix epoch milliseconds, matching the unit Rialo writes
    /// into `Clock::unix_timestamp`. `end_time_ms = None` marks a sticky
    /// entry that never expires; the program enforces scheduled-phase /
    /// active-phase modification rules — see `state::FeaturesState::upsert`.
    ///
    /// Accounts expected:
    /// 0. `[writable]` Storage account (PDA)
    /// 1. `[signer]` The authority account
    Upsert {
        /// Name of the feature.
        name: String,
        /// Activation time (Unix epoch ms).
        start_time_ms: u64,
        /// Deactivation time (Unix epoch ms). `None` marks a sticky entry
        /// that remains active forever once `start_time_ms` is reached.
        end_time_ms: Option<u64>,
    },

    /// Update the authority.
    ///
    /// This instruction requires a valid signature from the current authority.
    ///
    /// Accounts expected:
    /// 0. `[writable]` Storage account (PDA)
    /// 1. `[signer]` The current authority account
    UpdateAuthority {
        /// The new authority that will control the feature management system.
        new_authority: Pubkey,
    },
}

#[cfg(not(target_os = "solana"))]
impl FeatureManagementInstruction {
    /// Serialize instruction data
    pub fn serialize(&self) -> Result<Vec<u8>, borsh::io::Error> {
        borsh::to_vec(self)
    }

    /// Deserialize instruction data
    pub fn deserialize(data: &[u8]) -> Result<Self, borsh::io::Error> {
        borsh::from_slice(data)
    }
}