From fb33d594341ce1284989eaa6f1e8866639b4bd31 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 28 Jun 2024 13:14:00 +0000 Subject: [PATCH] cleanup --- src/instruction.rs | 19 ++++--------------- src/processor/open.rs | 2 +- src/processor/update.rs | 12 +++++------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/instruction.rs b/src/instruction.rs index 0e9e5a7..304ce4c 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -158,12 +158,6 @@ pub struct StakeArgs { pub amount: [u8; 8], } -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct UpdateArgs { - pub new_miner: Pubkey, -} - #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct UpgradeArgs { @@ -175,7 +169,6 @@ impl_to_bytes!(OpenArgs); impl_to_bytes!(MineArgs); impl_to_bytes!(ClaimArgs); impl_to_bytes!(StakeArgs); -impl_to_bytes!(UpdateArgs); impl_to_bytes!(UpgradeArgs); impl_instruction_from_bytes!(InitializeArgs); @@ -183,7 +176,6 @@ impl_instruction_from_bytes!(OpenArgs); impl_instruction_from_bytes!(MineArgs); impl_instruction_from_bytes!(ClaimArgs); impl_instruction_from_bytes!(StakeArgs); -impl_instruction_from_bytes!(UpdateArgs); impl_instruction_from_bytes!(UpgradeArgs); /// Builds a reset instruction. @@ -221,7 +213,7 @@ pub fn open(signer: Pubkey, miner: Pubkey) -> Instruction { program_id: crate::id(), accounts: vec![ AccountMeta::new(signer, true), - AccountMeta::new(miner, true), + AccountMeta::new(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), @@ -333,19 +325,16 @@ pub fn stake(signer: Pubkey, sender: Pubkey, amount: u64) -> Instruction { } // Build an update instruction. -pub fn update(signer: Pubkey, new_miner: Pubkey) -> Instruction { +pub fn update(signer: Pubkey, miner: Pubkey) -> Instruction { let proof = Pubkey::find_program_address(&[PROOF, signer.as_ref()], &crate::id()).0; Instruction { program_id: crate::id(), accounts: vec![ AccountMeta::new(signer, true), + AccountMeta::new(miner, false), AccountMeta::new(proof, false), ], - data: [ - OreInstruction::Update.to_vec(), - UpdateArgs { new_miner }.to_bytes().to_vec(), - ] - .concat(), + data: OreInstruction::Update.to_vec(), } } diff --git a/src/processor/open.rs b/src/processor/open.rs index f9ea4a7..0ac2bd4 100644 --- a/src/processor/open.rs +++ b/src/processor/open.rs @@ -43,7 +43,7 @@ pub fn process_open<'a, 'info>( return Err(ProgramError::NotEnoughAccountKeys); }; load_signer(signer)?; - load_signer(miner_info)?; + load_uninitialized_account(miner_info)?; load_uninitialized_pda( proof_info, &[PROOF, signer.key.as_ref()], diff --git a/src/processor/update.rs b/src/processor/update.rs index fcb7b17..d8c95ad 100644 --- a/src/processor/update.rs +++ b/src/processor/update.rs @@ -3,28 +3,26 @@ use solana_program::{ pubkey::Pubkey, }; -use crate::{instruction::UpdateArgs, loaders::*, state::Proof, utils::AccountDeserialize}; +use crate::{loaders::*, state::Proof, utils::AccountDeserialize}; /// Update changes the miner authority on a proof account. pub fn process_update<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], - data: &[u8], + _data: &[u8], ) -> ProgramResult { - // Parse args - let args = UpdateArgs::try_from_bytes(data)?; - // Load accounts - let [signer, proof_info] = accounts else { + let [signer, miner_info, proof_info] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; load_signer(signer)?; + load_uninitialized_account(miner_info)?; 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; + proof.miner = *miner_info.key; Ok(()) }