mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-05 07:36:50 +00:00
admin functions
This commit is contained in:
@@ -9,30 +9,15 @@ use crate::{
|
||||
BUS_COUNT, MINT_ADDRESS, TREASURY_ADDRESS,
|
||||
};
|
||||
|
||||
pub fn load_signer<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
|
||||
if !info.is_signer {
|
||||
return Err(ProgramError::MissingRequiredSignature);
|
||||
}
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_uninitialized_pda<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
seeds: &[&[u8]],
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
let key = Pubkey::create_program_address(seeds, &crate::id())?;
|
||||
if sol_memcmp(info.key.as_ref(), key.as_ref(), 32) != 0 {
|
||||
return Err(ProgramError::InvalidSeeds);
|
||||
}
|
||||
load_uninitialized_account(info)
|
||||
}
|
||||
|
||||
pub fn load_bus<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), crate::id().as_ref(), 32) != 0 {
|
||||
pub fn load_bus<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&crate::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
}
|
||||
if info.data_is_empty() {
|
||||
@@ -46,14 +31,14 @@ pub fn load_bus<'a, 'info>(
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_proof<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
signer: &Pubkey,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), crate::id().as_ref(), 32) != 0 {
|
||||
) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&crate::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
}
|
||||
if info.data_is_empty() {
|
||||
@@ -68,13 +53,11 @@ pub fn load_proof<'a, 'info>(
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_treasury<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), crate::id().as_ref(), 32) != 0 {
|
||||
pub fn load_treasury<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&crate::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
}
|
||||
if info.data_is_empty() {
|
||||
@@ -85,13 +68,11 @@ pub fn load_treasury<'a, 'info>(
|
||||
return Err(ProgramError::InvalidSeeds);
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_mint<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), spl_token::id().as_ref(), 32) != 0 {
|
||||
pub fn load_mint<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&spl_token::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
}
|
||||
if info.data_is_empty() {
|
||||
@@ -107,15 +88,15 @@ pub fn load_mint<'a, 'info>(
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_token_account<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
owner: &Pubkey,
|
||||
owner: Option<&Pubkey>,
|
||||
mint: &Pubkey,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), spl_token::id().as_ref(), 32) != 0 {
|
||||
) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&spl_token::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
}
|
||||
if info.data_is_empty() {
|
||||
@@ -126,20 +107,33 @@ pub fn load_token_account<'a, 'info>(
|
||||
let account = spl_token::state::Account::unpack_unchecked(&account_data)
|
||||
.or(Err(ProgramError::InvalidAccountData))?;
|
||||
|
||||
if sol_memcmp(account.mint.as_ref(), mint.as_ref(), 32) != 0 {
|
||||
if !account.mint.eq(&mint) {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
if sol_memcmp(account.owner.as_ref(), owner.as_ref(), 32) != 0 {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
if let Some(owner) = owner {
|
||||
if sol_memcmp(account.owner.as_ref(), owner.as_ref(), 32) != 0 {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_uninitialized_pda<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
seeds: &[&[u8]],
|
||||
) -> Result<(), ProgramError> {
|
||||
let key = Pubkey::create_program_address(seeds, &crate::id())?;
|
||||
if !info.key.eq(&key) {
|
||||
return Err(ProgramError::InvalidSeeds);
|
||||
}
|
||||
load_uninitialized_account(info)
|
||||
}
|
||||
|
||||
pub fn load_uninitialized_account<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.owner.as_ref(), system_program::id().as_ref(), 32) != 0 {
|
||||
) -> Result<(), ProgramError> {
|
||||
if !info.owner.eq(&system_program::id()) {
|
||||
return Err(ProgramError::AccountAlreadyInitialized);
|
||||
}
|
||||
if !info.data_is_empty() {
|
||||
@@ -148,15 +142,15 @@ pub fn load_uninitialized_account<'a, 'info>(
|
||||
if !info.is_writable {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_account<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
key: Pubkey,
|
||||
) -> Result<&'a AccountInfo<'info>, ProgramError> {
|
||||
if sol_memcmp(info.key.as_ref(), key.as_ref(), 32) != 0 {
|
||||
) -> Result<(), ProgramError> {
|
||||
if !info.key.eq(&key) {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
Ok(info)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user