mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-24 23:16:49 +00:00
sol
This commit is contained in:
30
program/src/claim_sol.rs
Normal file
30
program/src/claim_sol.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Claims a block reward.
|
||||
pub fn process_claim_sol(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = ClaimSOL::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.authority == *signer_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Load amount.
|
||||
let amount = miner.rewards_sol.min(amount);
|
||||
|
||||
// Update miner.
|
||||
miner.rewards_sol -= amount;
|
||||
|
||||
// Transfer reward to recipient.
|
||||
miner_info.send(amount, signer_info);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user