marsh-program 2.1.2

Marsh is a cryptocurrency for sovereign individuals living in Mirascape Horizon.
Documentation
use marsh_api::{instruction::Evolve, loaders::*, state::Config};
use marsh_utils::*;
use solana_program::{
    account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
};

/// Evolve updates the program's mars evolution settings. Its responsibilities include:
/// 1. Update the mars evolvable flag.
///
/// Safety requirements:
/// - Can only succeed if the signer is the evolver.
/// - Can only succeed if the provided config is valid.
pub fn process_evolve(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
    // Parse args
    let args = Evolve::try_from_bytes(data)?;

    // Load accounts.
    let [signer, config_info] = accounts else {
        return Err(ProgramError::NotEnoughAccountKeys);
    };
    load_signer(signer)?;
    load_config(config_info, true)?;

    // Validate signer is evolver.
    let mut config_data = config_info.data.borrow_mut();
    let config = Config::try_from_bytes_mut(&mut config_data)?;
    if config.evolver.ne(&signer.key) {
        return Err(ProgramError::MissingRequiredSignature);
    }

    // Update mars evolution flag.
    config.evolvable = args.evolvable as u64;
    // config.evolvable = args.evolvable;

    Ok(())
}