2022-07-05 10:31:47 -07:00
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
use crate::accounts_ix::*;
|
2022-08-12 07:05:32 -07:00
|
|
|
use crate::error::MangoError;
|
2022-07-05 10:31:47 -07:00
|
|
|
use crate::state::*;
|
2022-08-12 07:05:32 -07:00
|
|
|
use crate::util::fill_from_str;
|
2022-07-05 10:31:47 -07:00
|
|
|
|
2022-07-06 05:51:15 -07:00
|
|
|
pub fn account_edit(
|
|
|
|
ctx: Context<AccountEdit>,
|
2022-07-05 10:31:47 -07:00
|
|
|
name_opt: Option<String>,
|
|
|
|
// note: can also be used to unset by using the default pubkey here as a param
|
|
|
|
delegate_opt: Option<Pubkey>,
|
|
|
|
) -> Result<()> {
|
|
|
|
require!(
|
|
|
|
name_opt.is_some() || delegate_opt.is_some(),
|
|
|
|
MangoError::SomeError
|
|
|
|
);
|
|
|
|
|
2022-12-29 02:48:46 -08:00
|
|
|
let mut account = ctx.accounts.account.load_full_mut()?;
|
2022-07-05 10:31:47 -07:00
|
|
|
|
|
|
|
// note: unchanged fields are inline, and match exact definition in create_account
|
|
|
|
// please maintain, and don't remove, makes it easy to reason about which support modification by owner
|
|
|
|
|
|
|
|
if let Some(name) = name_opt {
|
2022-08-12 07:05:32 -07:00
|
|
|
account.fixed.name = fill_from_str(&name)?;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// unchanged -
|
|
|
|
// owner
|
|
|
|
// account_num
|
|
|
|
// bump
|
|
|
|
|
|
|
|
if let Some(delegate) = delegate_opt {
|
2022-07-25 07:07:53 -07:00
|
|
|
account.fixed.delegate = delegate;
|
2022-07-05 10:31:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// unchanged -
|
|
|
|
// tokens
|
|
|
|
// serum3
|
|
|
|
// perps
|
|
|
|
// being_liquidated
|
|
|
|
// is_bankrupt
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|