oil_api/state/code.rs
1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use super::OilAccount;
5
6/// Code tracks access codes for pre-mine phase.
7/// Each code is linked to a specific wallet (authority) to prevent abuse.
8/// One code per wallet - PDA includes both code_hash and authority.
9#[repr(C)]
10#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
11pub struct Code {
12 /// The code hash (first 32 bytes of keccak256 hash of the code string)
13 pub code_hash: [u8; 32],
14
15 /// The wallet (authority) this code is linked to
16 pub authority: Pubkey,
17
18 /// Number of times this code has been used (optional tracking)
19 pub usage_count: u64,
20}
21
22impl Code {
23 /// Derives the PDA for a Code account.
24 /// PDA seeds: [b"premine_code", code_hash, authority.to_bytes()]
25 /// This ensures one code per wallet (same code_hash + different authority = different PDA)
26 pub fn pda(code_hash: [u8; 32], authority: Pubkey) -> (Pubkey, u8) {
27 use crate::ID;
28 Pubkey::find_program_address(&[b"premine_code", &code_hash, &authority.to_bytes()], &ID)
29 }
30}
31
32account!(OilAccount, Code);