mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-30 07:36:47 +00:00
account meta
This commit is contained in:
@@ -213,7 +213,7 @@ pub fn open(signer: Pubkey, miner: Pubkey) -> Instruction {
|
||||
program_id: crate::id(),
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(miner, false),
|
||||
AccountMeta::new_readonly(miner, false),
|
||||
AccountMeta::new(proof_pda.0, false),
|
||||
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
||||
@@ -331,7 +331,7 @@ pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction {
|
||||
program_id: crate::id(),
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(miner, false),
|
||||
AccountMeta::new_readonly(miner, false),
|
||||
AccountMeta::new(proof, false),
|
||||
],
|
||||
data: OreInstruction::Update.to_vec(),
|
||||
|
||||
@@ -319,15 +319,16 @@ pub fn load_uninitialized_pda<'a, 'info>(
|
||||
return Err(ProgramError::InvalidSeeds);
|
||||
}
|
||||
|
||||
load_uninitialized_account(info)
|
||||
load_system_account(info, true)
|
||||
}
|
||||
|
||||
/// Errors if:
|
||||
/// - Owner is not the system program.
|
||||
/// - Data is not empty.
|
||||
/// - Account is not writable.
|
||||
pub fn load_uninitialized_account<'a, 'info>(
|
||||
pub fn load_system_account<'a, 'info>(
|
||||
info: &'a AccountInfo<'info>,
|
||||
is_writable: bool,
|
||||
) -> Result<(), ProgramError> {
|
||||
if info.owner.ne(&system_program::id()) {
|
||||
return Err(ProgramError::InvalidAccountOwner);
|
||||
@@ -337,7 +338,7 @@ pub fn load_uninitialized_account<'a, 'info>(
|
||||
return Err(ProgramError::AccountAlreadyInitialized);
|
||||
}
|
||||
|
||||
if !info.is_writable {
|
||||
if is_writable && !info.is_writable {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ pub fn process_initialize<'a, 'info>(
|
||||
&crate::id(),
|
||||
)?;
|
||||
load_uninitialized_pda(treasury_info, &[TREASURY], args.treasury_bump, &crate::id())?;
|
||||
load_uninitialized_account(treasury_tokens_info)?;
|
||||
load_system_account(treasury_tokens_info, true)?;
|
||||
load_program(system_program, system_program::id())?;
|
||||
load_program(token_program, spl_token::id())?;
|
||||
load_program(associated_token_program, spl_associated_token_account::id())?;
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn process_open<'a, 'info>(
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
load_signer(signer)?;
|
||||
load_uninitialized_account(miner_info)?;
|
||||
load_system_account(miner_info, false)?;
|
||||
load_uninitialized_pda(
|
||||
proof_info,
|
||||
&[PROOF, signer.key.as_ref()],
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn process_update<'a, 'info>(
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
load_signer(signer)?;
|
||||
load_uninitialized_account(miner_info)?;
|
||||
load_system_account(miner_info, false)?;
|
||||
load_proof(proof_info, signer.key, true)?;
|
||||
|
||||
// Update the proof
|
||||
|
||||
Reference in New Issue
Block a user