proof of wager

This commit is contained in:
Hardhat Chad
2025-05-23 16:29:31 -07:00
parent 379ebae250
commit b5a50622a2
23 changed files with 312 additions and 805 deletions

View File

@@ -1,25 +1,21 @@
use ore_api::prelude::*;
use steel::*;
/// Close closes a proof account and returns the rent to the owner.
pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let [signer_info, proof_info, system_program] = accounts else {
let [signer_info, block_info, wager_info, system_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
proof_info
.is_writable()?
.as_account::<Proof>(&ore_api::ID)?
.assert_err(
|p| p.authority == *signer_info.key,
ProgramError::MissingRequiredSignature,
)?
.assert(|p| p.balance == 0)?;
let block = block_info.as_account::<Block>(&ore_api::ID)?;
wager_info
.as_account_mut::<Wager>(&ore_api::ID)?
.assert_mut(|w| w.authority == *signer_info.key)?
.assert_mut(|w| w.round < block.current_round)?;
system_program.is_program(&system_program::ID)?;
// Return rent to signer.
proof_info.close(signer_info)?;
// Close the wager account
wager_info.close(&signer_info)?;
Ok(())
}