mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
miner migration
This commit is contained in:
@@ -2,6 +2,7 @@ mod claim;
|
||||
mod close;
|
||||
mod initialize;
|
||||
mod log;
|
||||
mod migrate_miner_account;
|
||||
mod mine;
|
||||
mod open;
|
||||
mod reset;
|
||||
@@ -17,6 +18,7 @@ use claim::*;
|
||||
use close::*;
|
||||
use initialize::*;
|
||||
use log::*;
|
||||
use migrate_miner_account::*;
|
||||
use mine::*;
|
||||
use open::*;
|
||||
use reset::*;
|
||||
@@ -54,6 +56,9 @@ pub fn process_instruction(
|
||||
OreInstruction::SetFeeCollector => process_set_fee_collector(accounts, data)?,
|
||||
OreInstruction::SetFeeRate => process_set_fee_rate(accounts, data)?,
|
||||
OreInstruction::SetSniperFeeDuration => process_set_sniper_fee_duration(accounts, data)?,
|
||||
|
||||
// Migration
|
||||
OreInstruction::MigrateMinerAccount => process_migrate_miner_account(accounts, data)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
42
program/src/migrate_miner_account.rs
Normal file
42
program/src/migrate_miner_account.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::mem::size_of;
|
||||
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::log::sol_log;
|
||||
use steel::*;
|
||||
|
||||
/// Migrates a miner account from the old format to the new format.
|
||||
pub fn process_migrate_miner_account(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, miner_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut(|c| c.admin == *signer_info.key)?;
|
||||
let miner = miner_info.as_account_mut::<MinerOLD>(&ore_api::ID)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Copy old data.
|
||||
let authority = miner.authority;
|
||||
let block_id = miner.block_id;
|
||||
let hashpower = miner.hashpower;
|
||||
let seed = miner.seed;
|
||||
let total_hashpower = miner.total_hashpower;
|
||||
let total_rewards = miner.total_rewards;
|
||||
|
||||
// Reallocate new account.
|
||||
miner_info.realloc(8 + size_of::<Miner>(), false)?;
|
||||
|
||||
// Copy new data.
|
||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
miner.authority = authority;
|
||||
miner.block_id = block_id;
|
||||
miner.executor = Pubkey::default();
|
||||
miner.hashpower = hashpower;
|
||||
miner.seed = seed;
|
||||
miner.total_hashpower = total_hashpower;
|
||||
miner.total_rewards = total_rewards;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user