-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transfer-switch/anchor - x metas for every mint fix
- Loading branch information
Showing
10 changed files
with
246 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
248 changes: 95 additions & 153 deletions
248
tokens/token-2022/transfer-hook/transfer-switch/anchor/pnpm-lock.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
...-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/configure_admin.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use {crate::state::AdminConfig, anchor_lang::prelude::*}; | ||
|
||
#[derive(Accounts)] | ||
pub struct ConfigureAdmin<'info> { | ||
#[account(mut)] | ||
pub admin: Signer<'info>, | ||
|
||
/// CHECK: the new admin | ||
#[account(mut)] | ||
pub new_admin: UncheckedAccount<'info>, | ||
|
||
/// To hold the address of the admin that controls switches | ||
#[account( | ||
init_if_needed, | ||
payer=admin, | ||
space=8+AdminConfig::INIT_SPACE, | ||
seeds=[b"admin-config"], | ||
bump | ||
)] | ||
pub admin_config: Account<'info, AdminConfig>, | ||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
impl<'info> ConfigureAdmin<'info> { | ||
pub fn is_admin(&self) -> Result<()> { | ||
// check if we are not creating the account for the first time, | ||
// ensure it's the admin that is making the change | ||
// | ||
if self.admin_config.is_initialised { | ||
// make sure it's the admin | ||
// | ||
require_keys_eq!(self.admin.key(), self.admin_config.admin,); | ||
|
||
// make sure the admin is not reentering their key | ||
// | ||
require_keys_neq!(self.admin.key(), self.new_admin.key()); | ||
} | ||
Ok(()) | ||
} | ||
|
||
pub fn configure_admin(&mut self) -> Result<()> { | ||
self.admin_config.set_inner(AdminConfig { | ||
admin: self.new_admin.key(), // set the admin pubkey that can switch transfers on/off | ||
is_initialised: true, // let us know an admin has been set | ||
}); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...022/transfer-hook/transfer-switch/anchor/programs/transfer-switch/src/instructions/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod initialise_extra_account_metas_list; | ||
pub mod switch; | ||
pub mod transfer_hook; | ||
pub mod configure_admin; | ||
|
||
pub use initialise_extra_account_metas_list::*; | ||
pub use switch::*; | ||
pub use transfer_hook::*; | ||
pub use configure_admin::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.