mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-10 15:11:57 +00:00
set executor
This commit is contained in:
@@ -6,9 +6,9 @@ mod claim_sol;
|
||||
mod deploy;
|
||||
mod initialize;
|
||||
mod log;
|
||||
mod reimburse;
|
||||
mod reset;
|
||||
mod set_admin;
|
||||
mod set_executor;
|
||||
mod set_fee_collector;
|
||||
mod whitelist;
|
||||
|
||||
@@ -20,9 +20,9 @@ use claim_sol::*;
|
||||
use deploy::*;
|
||||
use initialize::*;
|
||||
use log::*;
|
||||
use reimburse::*;
|
||||
use reset::*;
|
||||
use set_admin::*;
|
||||
use set_executor::*;
|
||||
use set_fee_collector::*;
|
||||
|
||||
use ore_api::instruction::*;
|
||||
@@ -44,7 +44,7 @@ pub fn process_instruction(
|
||||
OreInstruction::Log => process_log(accounts, data)?,
|
||||
OreInstruction::Initialize => process_initialize(accounts, data)?,
|
||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||
OreInstruction::Reimburse => process_reimburse(accounts, data)?,
|
||||
OreInstruction::SetExecutor => process_set_executor(accounts, data)?,
|
||||
|
||||
// Admin
|
||||
OreInstruction::SetAdmin => process_set_admin(accounts, data)?,
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::rent::Rent;
|
||||
use steel::*;
|
||||
|
||||
/// Reimburses an executor keypair for their tx fee expenses.
|
||||
pub fn process_reimburse(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Reimburse::try_from_bytes(data)?;
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, miner_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.executor == *signer_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Check if miner can charge.// Check total amount.
|
||||
let account_size = 8 + std::mem::size_of::<Miner>();
|
||||
let min_rent = Rent::get()?.minimum_balance(account_size);
|
||||
let claimable_sol = miner.rewards_sol;
|
||||
let obligations = min_rent + claimable_sol;
|
||||
let new_lamports = miner_info.lamports().saturating_sub(amount);
|
||||
if new_lamports < obligations {
|
||||
return Err(trace(
|
||||
"Miner account has insufficient SOL",
|
||||
ProgramError::InsufficientFunds,
|
||||
));
|
||||
}
|
||||
|
||||
// Send reimbursement.
|
||||
miner_info.send(amount, signer_info);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
27
program/src/set_executor.rs
Normal file
27
program/src/set_executor.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Sets the executor.
|
||||
pub fn process_set_executor(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = SetExecutor::try_from_bytes(data)?;
|
||||
let new_executor = Pubkey::new_from_array(args.executor);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, miner_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|m| m.authority == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Set executor.
|
||||
miner.executor = new_executor;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user