introduce update ix

This commit is contained in:
Hardhat Chad
2024-06-28 12:42:54 +00:00
parent 50a4cf8dc4
commit cddcd493a8
4 changed files with 99 additions and 48 deletions

View File

@@ -5,6 +5,7 @@ mod mine;
mod open;
mod reset;
mod stake;
mod update;
mod upgrade;
pub use claim::*;
@@ -14,4 +15,5 @@ pub use mine::*;
pub use open::*;
pub use reset::*;
pub use stake::*;
pub use update::*;
pub use upgrade::*;

30
src/processor/update.rs Normal file
View File

@@ -0,0 +1,30 @@
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
pubkey::Pubkey,
};
use crate::{instruction::UpdateArgs, loaders::*, state::Proof, utils::AccountDeserialize};
/// Update updates a proof account.
pub fn process_update<'a, 'info>(
_program_id: &Pubkey,
accounts: &'a [AccountInfo<'info>],
data: &[u8],
) -> ProgramResult {
// Parse args
let args = UpdateArgs::try_from_bytes(data)?;
// Load accounts
let [signer, proof_info] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
load_signer(signer)?;
load_proof(proof_info, signer.key, true)?;
// Update the proof
let mut proof_data = proof_info.data.borrow_mut();
let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
proof.miner = args.new_miner;
Ok(())
}