mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-17 23:16:48 +00:00
continue migration
This commit is contained in:
@@ -6,7 +6,6 @@ use ore_api::{
|
||||
error::OreError,
|
||||
event::MineEvent,
|
||||
instruction::Mine,
|
||||
loaders::*,
|
||||
state::{Bus, Config, Proof},
|
||||
};
|
||||
use solana_program::program::set_return_data;
|
||||
@@ -37,9 +36,11 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer.is_signer()?;
|
||||
bus_info.is_type::<Bus>()?.is_writable()?;
|
||||
config_info.is_config()?;
|
||||
load_proof_with_miner(proof_info, signer.key, true)?;
|
||||
let bus = bus_info.to_account_mut::<Bus>(&ore_api::ID)?;
|
||||
let config = config_info.to_account::<Config>(&ore_api::ID)?;
|
||||
let proof = proof_info
|
||||
.to_account_mut::<Proof>(&ore_api::ID)?
|
||||
.check_mut(|p| p.authority.eq(signer.key))?;
|
||||
instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
|
||||
@@ -50,8 +51,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
|
||||
authenticate(&instructions_sysvar.data.borrow(), proof_info.key)?;
|
||||
|
||||
// Validate epoch is active.
|
||||
let config_data = config_info.data.borrow();
|
||||
let config = Config::try_from_bytes(&config_data)?;
|
||||
// let config_data = config_info.data.borrow();
|
||||
// let config = Config::try_from_bytes(&config_data)?;
|
||||
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
|
||||
if config
|
||||
.last_reset_at
|
||||
@@ -65,8 +66,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
|
||||
//
|
||||
// Here we use drillx to validate the provided solution is a valid hash of the challenge.
|
||||
// If invalid, we return an error.
|
||||
let mut proof_data = proof_info.data.borrow_mut();
|
||||
let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
|
||||
// let mut proof_data = proof_info.data.borrow_mut();
|
||||
// let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
|
||||
let solution = Solution::new(args.digest, args.nonce);
|
||||
if !solution.is_valid(&proof.challenge) {
|
||||
return Err(OreError::HashInvalid.into());
|
||||
@@ -110,8 +111,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
|
||||
// If user has greater than or equal to the max stake on the network, they receive 2x multiplier.
|
||||
// Any stake less than this will receives between 1x and 2x multipler. The multipler is only active
|
||||
// if the miner's last stake deposit was more than one minute ago to protect against flash loan attacks.
|
||||
let mut bus_data = bus_info.data.borrow_mut();
|
||||
let bus = Bus::try_from_bytes_mut(&mut bus_data)?;
|
||||
// let mut bus_data = bus_info.data.borrow_mut();
|
||||
// let bus = Bus::try_from_bytes_mut(&mut bus_data)?;
|
||||
if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) {
|
||||
// Calculate staking reward.
|
||||
if config.top_balance.gt(&0) {
|
||||
|
||||
Reference in New Issue
Block a user