initialize

This commit is contained in:
Hardhat Chad
2024-02-13 17:36:36 +00:00
parent cb30817447
commit 68bb762e5c
14 changed files with 565 additions and 440 deletions

20
src/state/bus.rs Normal file
View File

@@ -0,0 +1,20 @@
use bytemuck::{Pod, Zeroable};
#[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,
/// The quantity of rewards this bus can issue in the current epoch epoch.
pub available_rewards: u64,
}
impl Bus {
pub fn to_bytes(&self) -> &[u8] {
bytemuck::bytes_of(self)
}
}

20
src/state/hash.rs Normal file
View File

@@ -0,0 +1,20 @@
use std::mem::transmute;
use bytemuck::{Pod, Zeroable};
use solana_program::keccak::{Hash as KeccakHash, HASH_BYTES};
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Hash(pub [u8; HASH_BYTES]);
impl From<KeccakHash> for Hash {
fn from(value: KeccakHash) -> Self {
unsafe { transmute(value) }
}
}
impl From<Hash> for KeccakHash {
fn from(value: Hash) -> Self {
unsafe { transmute(value) }
}
}

7
src/state/mod.rs Normal file
View File

@@ -0,0 +1,7 @@
mod bus;
mod hash;
mod treasury;
pub use bus::*;
pub use hash::*;
pub use treasury::*;

32
src/state/treasury.rs Normal file
View File

@@ -0,0 +1,32 @@
use bytemuck::{Pod, Zeroable};
use solana_program::pubkey::Pubkey;
use super::Hash;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Treasury {
/// The bump of the treasury account PDA.
pub bump: u64,
/// The admin authority with permission to update the difficulty.
pub admin: Pubkey,
/// The hash difficulty.
pub difficulty: Hash,
/// The timestamp of the start of the current epoch.
pub epoch_start_at: i64,
/// The reward rate to payout to miners for submiting valid hashes.
pub reward_rate: u64,
/// The total lifetime claimed rewards.
pub total_claimed_rewards: u64,
}
impl Treasury {
pub fn to_bytes(&self) -> &[u8] {
bytemuck::bytes_of(self)
}
}