marsh-program 2.1.2

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

/// UpdateEvolver updates the mars' evolver account. Its responsibilities include:
/// 1. Update/change the mars evolver address.
///
/// Safety requirements:
/// - Can only succeed if the signer is the mars evolver.
/// - Can only succeed if the provided config is valid.
pub fn process_update_evolver(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
    // Parse args.
    let args = UpdateEvolver::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 evolver.
    config.evolver = args.new_evolver;

    Ok(())
}