discriminator

This commit is contained in:
Hardhat Chad
2024-02-15 23:43:33 +00:00
parent 086a705a39
commit 754b18e21a
12 changed files with 215 additions and 176 deletions

View File

@@ -7,21 +7,21 @@ pub const START_AT: i64 = 0;
// SHA2 const stable
/// Bus pubkeys
pub const BUS_ADDRESSES: [Pubkey; BUS_COUNT] = [
pubkey!("2uwqyH2gKqstgAFCSniirx73X4iQek5ETc2vVJKUiNMg"),
pubkey!("FRMC6jVczm1cRaEs5EhDsfw7X8vsmSDpf3bJWVkawngu"),
pubkey!("9nWyycs4GHjnLujPR2sbA1A8K8CkiLc5VzxWUD4hg2uM"),
pubkey!("Kt7kqD3MyvxLbj4ek9urXUxkDoxaMuQn82K2VdYD1jM"),
pubkey!("8r9mXYnFQXhwrNfvatGUTxbbNSqxScuCwp4sBTSxDVTJ"),
pubkey!("D9cEH32k8p9uWc4w5RrStK9rWssU8NuX1Dg5YaUim4wL"),
pubkey!("H1RKMYADPzd4C1j1RZu51NvRSVktoTYEJyeVy98Kmdyu"),
pubkey!("3XbdZNbBjjp8qnDJjv1RxaKisyfx6ahznYkSigs6dayy"),
pubkey!("E2EJ9xxK78b5XJu9cBnYf6fDbJuLqXuLN5fhaUtEuPPf"),
pubkey!("4J3EHs3tMuW46iNAQEEkZESYTeaPcRxYarH2pheRM9ET"),
pubkey!("6CNKKLPgC7pouftqXP43yaCBssmDRXD7ww7jGxNLgz6n"),
pubkey!("94vZ1ErDFmUJqQkMBLNQQaczSU981g3U884WXgns1rxQ"),
pubkey!("6srtSHdy3GncfFPFyoa6gw3iY2mzp6aMS3naje2wLsd"),
pubkey!("4w2BYLwDu1EV3HiZnWsdNYfEwLwkkNZZbWyarSe2AnQ5"),
pubkey!("CtLrZCzr1BPDB75LTh381z9NtyTYzKEnupYUt37L8Jvu"),
pubkey!("EaACXDgdd6RKw4Wr4t2o9qFodFTH5m8cbuW3G4xmyUMw"),
];
/// The mint address of the ORE token.
pub const MINT_ADDRESS: Pubkey = pubkey!("DY4JVebraRXg9BGt4MRU4mvqHGDzmi2Ay1HGjDU5YeNf");
pub const MINT_ADDRESS: Pubkey = pubkey!("3jXYL3mCgf3Dh69NpG4adNX3jogjmFbz3RoqiuBmkrYN");
/// Treasury address
pub const TREASURY_ADDRESS: Pubkey = pubkey!("67PLJej6iZm915WbEu6NLeZtRZtnHc5nSVQvkHRZyPiC");
pub const TREASURY_ADDRESS: Pubkey = pubkey!("2kdcgA7hmKbGvKHZpLFJD9rgSD1Bgggc8UUeJWGMWSRo");
/// The initial reward rate to payout in the first epoch.
pub const INITIAL_REWARD_RATE: u64 = 10u64.pow(3u32);

View File

@@ -17,7 +17,7 @@ use solana_program::{
// TODO Test admin and difficulty adjustment functions
// TODO Increase decimals?
declare_id!("CeJShZEAzBLwtcLQvbZc7UT38e4nUTn63Za5UFyYYDTS");
declare_id!("ore2mSzJwAZhxLyCLbNEnFvYq9U8jvCMvUBrVvbmqDF");
#[cfg(not(feature = "no-entrypoint"))]
solana_program::entrypoint!(process_instruction);
@@ -28,12 +28,15 @@ pub fn process_instruction(
accounts: &[AccountInfo],
data: &[u8],
) -> ProgramResult {
if program_id.ne(&crate::id()) {
return Err(ProgramError::IncorrectProgramId);
}
let (tag, data) = data
.split_first()
.ok_or(ProgramError::InvalidInstructionData)?;
let ix = OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))?;
match ix {
match OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))? {
OreInstruction::Reset => process_reset(program_id, accounts, data)?,
OreInstruction::Register => process_register(program_id, accounts, data)?,
OreInstruction::Mine => process_mine(program_id, accounts, data)?,

View File

@@ -7,7 +7,7 @@ use spl_token::state::Mint;
use crate::{
state::{Bus, Proof},
utils::AccountDeserialize,
BUS_COUNT, MINT_ADDRESS, TREASURY_ADDRESS,
BUS_ADDRESSES, BUS_COUNT, MINT_ADDRESS, TREASURY_ADDRESS,
};
pub fn load_signer<'a, 'info>(info: &'a AccountInfo<'info>) -> Result<(), ProgramError> {
@@ -33,10 +33,14 @@ pub fn load_bus<'a, 'info>(
let bus_data = info.data.borrow();
let bus = Bus::try_from_bytes(&bus_data)?;
if !(0..BUS_COUNT).contains(&(bus.id as usize)) {
if bus.id.ge(&(BUS_COUNT as u64)) {
return Err(ProgramError::InvalidAccountData);
}
if info.key.ne(&BUS_ADDRESSES[bus.id as usize]) {
return Err(ProgramError::InvalidSeeds);
}
if is_writable && !info.is_writable {
return Err(ProgramError::InvalidAccountData);
}

View File

@@ -83,8 +83,8 @@ pub fn process_initialize<'a, 'info>(
let mut bus_data = bus_infos[i].try_borrow_mut_data()?;
bus_data[0] = Bus::discriminator() as u8;
let mut bus = Bus::try_from_bytes_mut(&mut bus_data)?;
bus.bump = bus_bumps[i] as u32;
bus.id = i as u32;
// bus.bump = bus_bumps[i] as u32;
bus.id = i as u64;
bus.available_rewards = 0;
}

View File

@@ -42,7 +42,7 @@ pub fn process_register<'a, 'info>(
let mut proof_data = proof_info.data.borrow_mut();
proof_data[0] = Proof::discriminator() as u8;
let mut proof = Proof::try_from_bytes_mut(&mut proof_data)?;
proof.bump = args.bump as u64;
// proof.bump = args.bump as u64;
proof.authority = *signer.key;
proof.claimable_rewards = 0;
proof.hash = hashv(&[&signer.key.to_bytes()]).into();

View File

@@ -39,7 +39,7 @@ pub fn process_reset<'a, 'info>(
true,
)?;
load_sysvar(token_program, spl_token::id())?;
let busses: [&AccountInfo; 8] = [
let busses: [&AccountInfo; BUS_COUNT] = [
bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info,
bus_7_info,
];

View File

@@ -8,11 +8,8 @@ use crate::{
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Bus {
/// The bump of the bus account PDA.
pub bump: u32,
/// The ID of the bus account.
pub id: u32,
pub id: u64,
/// The quantity of rewards this bus can issue in the current epoch epoch.
pub available_rewards: u64,

View File

@@ -10,9 +10,6 @@ use crate::{
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Proof {
/// The bump of the proof account PDA.
pub bump: u64,
/// The account (i.e. miner) authorized to use this proof.
pub authority: Pubkey,