use crate::states::{Amount, Factor};
use anchor_lang::prelude::*;
use crate::{states::Store, utils::internal};
#[derive(Accounts)]
pub struct InsertConfig<'info> {
#[account(mut)]
pub authority: Signer<'info>,
#[account(mut)]
pub store: AccountLoader<'info, Store>,
}
impl<'info> internal::Authentication<'info> for InsertConfig<'info> {
fn authority(&self) -> &Signer<'info> {
&self.authority
}
fn store(&self) -> &AccountLoader<'info, Store> {
&self.store
}
}
pub(crate) fn unchecked_insert_amount(
ctx: Context<InsertConfig>,
key: &str,
amount: Amount,
) -> Result<()> {
*ctx.accounts.store.load_mut()?.get_amount_mut(key)? = amount;
Ok(())
}
pub(crate) fn unchecked_insert_factor(
ctx: Context<InsertConfig>,
key: &str,
factor: Factor,
) -> Result<()> {
*ctx.accounts.store.load_mut()?.get_factor_mut(key)? = factor;
Ok(())
}
pub(crate) fn unchecked_insert_address(
ctx: Context<InsertConfig>,
key: &str,
address: Pubkey,
) -> Result<()> {
*ctx.accounts.store.load_mut()?.get_address_mut(key)? = address;
Ok(())
}