add DeclareProof instruction

This commit is contained in:
Kriptikz
2024-07-24 21:22:35 -05:00
parent 7cd26298b0
commit 0308bb9268
3 changed files with 41 additions and 0 deletions

View File

@@ -89,6 +89,10 @@ pub enum OreInstruction {
#[account(6, name = "mint_v1", desc = "Ore v1 token mint account", writable)]
#[account(7, name = "token_program", desc = "SPL token program")]
Upgrade = 7,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "proof", desc = "Ore proof account")]
DeclareProof = 8,
#[account(0, name = "ore_program", desc = "Ore program")]
#[account(1, name = "signer", desc = "Admin signer", signer)]

View File

@@ -0,0 +1,34 @@
use solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
program_error::ProgramError,
pubkey::Pubkey,
};
/// DeclareProof is used by other instructions in the same transaction.
/// - Other instructions will use transaction introspection to ensure they
/// only process the declared proof.
/// - Other instructions that need to validate the declared proof will only
/// look at the first and second instructions in the transaction
///
/// Safety requirements:
/// - No safety requirements are required in this instruction to keep cu's as
/// low as possible. Other instructions that use the declared proof handle
/// validation via the loader.
pub fn process_declare_proof<'a, 'info>(
_program_id: &Pubkey,
accounts: &'a [AccountInfo<'info>],
_data: &[u8],
) -> ProgramResult {
// Ensure one account info is provided
// Validation of this proof is handled by the mine ix
let [_proof_info] =
accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
};
Ok(())
}

View File

@@ -1,6 +1,7 @@
mod claim;
mod close;
mod initialize;
mod declare_proof;
mod mine;
mod open;
mod reset;
@@ -11,6 +12,7 @@ mod upgrade;
use claim::*;
use close::*;
use initialize::*;
use declare_proof::*;
use mine::*;
use open::*;
use reset::*;
@@ -45,6 +47,7 @@ pub fn process_instruction(
match OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))? {
OreInstruction::Claim => process_claim(program_id, accounts, data)?,
OreInstruction::Close => process_close(program_id, accounts, data)?,
OreInstruction::DeclareProof => process_declare_proof(program_id, accounts, data)?,
OreInstruction::Mine => process_mine(program_id, accounts, data)?,
OreInstruction::Open => process_open(program_id, accounts, data)?,
OreInstruction::Reset => process_reset(program_id, accounts, data)?,