mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-15 15:10:19 +00:00
scaffold deregister
This commit is contained in:
36
src/processor/deregister.rs
Normal file
36
src/processor/deregister.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
||||
pubkey::Pubkey, system_program,
|
||||
};
|
||||
|
||||
use crate::{instruction::RegisterArgs, loaders::*};
|
||||
|
||||
/// Register generates a new hash chain for a prospective miner. Its responsibilities include:
|
||||
/// 1. Initialize a new proof account.
|
||||
/// 2. Generate an initial hash from the signer's key.
|
||||
///
|
||||
/// Safety requirements:
|
||||
/// - Register is a permissionless instruction and can be invoked by any singer.
|
||||
/// - Can only succeed if the provided proof acount PDA is valid (associated with the signer).
|
||||
/// - Can only succeed once per signer.
|
||||
/// - The provided system program must be valid.
|
||||
pub fn process_deregister<'a, 'info>(
|
||||
_program_id: &Pubkey,
|
||||
accounts: &'a [AccountInfo<'info>],
|
||||
data: &[u8],
|
||||
) -> ProgramResult {
|
||||
// Load accounts
|
||||
let [signer, proof_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
load_signer(signer)?;
|
||||
load_proof(proof_info, signer.key, true)?;
|
||||
load_program(system_program, system_program::id())?;
|
||||
|
||||
// TODO Ensure proof.balance == 0
|
||||
// TODO Send lamports to signer
|
||||
// TODO Realloc data to 0
|
||||
// TODO Reassign back to system program
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod claim;
|
||||
mod deregister;
|
||||
mod initialize;
|
||||
mod mine;
|
||||
mod pause;
|
||||
@@ -10,6 +11,7 @@ mod update_tolerance;
|
||||
mod upgrade;
|
||||
|
||||
pub use claim::*;
|
||||
pub use deregister::*;
|
||||
pub use initialize::*;
|
||||
pub use mine::*;
|
||||
pub use pause::*;
|
||||
|
||||
@@ -64,6 +64,7 @@ pub fn process_register<'a, 'info>(
|
||||
&slot_hashes_info.data.borrow()[0..size_of::<SlotHash>()],
|
||||
])
|
||||
.0;
|
||||
proof.last_deposit_slot = 0;
|
||||
proof.last_hash_at = 0;
|
||||
proof.total_hashes = 0;
|
||||
proof.total_rewards = 0;
|
||||
|
||||
@@ -5,7 +5,7 @@ use solana_program::{
|
||||
|
||||
use crate::{
|
||||
error::OreError, instruction::UpdateToleranceArgs, loaders::*, state::Config,
|
||||
utils::AccountDeserialize,
|
||||
utils::AccountDeserialize, ONE_MINUTE,
|
||||
};
|
||||
|
||||
pub fn process_update_tolerance<'a, 'info>(
|
||||
@@ -30,11 +30,11 @@ pub fn process_update_tolerance<'a, 'info>(
|
||||
return Err(ProgramError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
// Overflow checks
|
||||
if args.tolerance_liveness.gt(&(i64::MAX as u64)) {
|
||||
// Sanity checks
|
||||
if args.tolerance_liveness.ge(&(ONE_MINUTE as u64)) {
|
||||
return Err(OreError::ToleranceOverflow.into());
|
||||
}
|
||||
if args.tolerance_spam.gt(&(i64::MAX as u64)) {
|
||||
if args.tolerance_spam.ge(&(ONE_MINUTE as u64)) {
|
||||
return Err(OreError::ToleranceOverflow.into());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user