split miner authority

This commit is contained in:
Hardhat Chad
2024-06-27 15:49:45 +00:00
parent 410ad47662
commit 6bdc8cbca2
5 changed files with 42 additions and 3 deletions

View File

@@ -158,6 +158,39 @@ pub fn load_proof<'a, 'info>(
Ok(())
}
/// Errors if:
/// - Owner is not Ore program.
/// - Data is empty.
/// - Data cannot deserialize into a proof account.
/// - Proof miner does not match the expected address.
/// - Expected to be writable, but is not.
pub fn load_proof_with_miner<'a, 'info>(
info: &'a AccountInfo<'info>,
miner: &Pubkey,
is_writable: bool,
) -> Result<(), ProgramError> {
if info.owner.ne(&crate::id()) {
return Err(ProgramError::InvalidAccountOwner);
}
if info.data_is_empty() {
return Err(ProgramError::UninitializedAccount);
}
let proof_data = info.data.borrow();
let proof = Proof::try_from_bytes(&proof_data)?;
if proof.miner.ne(&miner) {
return Err(ProgramError::InvalidAccountData);
}
if is_writable && !info.is_writable {
return Err(ProgramError::InvalidAccountData);
}
Ok(())
}
/// Errors if:
/// - Owner is not Ore program.
/// - Address does not match the expected address.