miner_api/instruction.rs
1/// Tagi instrukcji (pierwszy bajt danych).
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u8)]
4pub enum MinerInstruction {
5 /// Inicjalizacja programu.
6 /// Konta: [admin (signer, payer), config (PDA), mint, round0 (PDA),
7 /// system_program]
8 /// Wymagania wobec minta (tworzonego poza programem przed initialize):
9 /// decimals = 9, mint_authority = PDA "treasury", freeze_authority = None.
10 Initialize = 0,
11
12 /// Rejestracja minera.
13 /// Konta: [authority (signer, payer), miner (PDA), slot_hashes, system_program]
14 Register = 1,
15
16 /// Ustawienie session keya (podpisuje submity w tle).
17 /// Konta: [authority (signer), miner]
18 /// Dane: session_key [u8;32] (zera = odwołanie)
19 AuthorizeSession = 2,
20
21 /// Submit hasha (raz na rundę): weryfikacja PoW, naliczenie wagi,
22 /// rozliczenie poprzedniej rundy (lazy).
23 /// Konta: [signer (authority lub session), miner, config,
24 /// current_round, prev_round, token_account (ATA authority),
25 /// slot_hashes]
26 /// Dane: nonce u64 LE
27 Mine = 3,
28
29 /// Odbiór naliczonych nagród (mint do ATA authority).
30 /// Konta: [authority (signer), miner, config, prev_round, mint,
31 /// treasury (PDA), token_account (ATA authority), token_program]
32 Claim = 4,
33
34 /// Zamknięcie rundy i otwarcie kolejnej (permissionless crank).
35 /// Konta: [payer (signer), config, new_round (PDA), system_program]
36 Crank = 5,
37
38 /// Zamknięcie starego konta rundy po retencji (rent dla wołającego).
39 /// Konta: [recipient (signer), config, round]
40 CloseRound = 6,
41
42 /// Zmiana parametrów przez admina.
43 /// Konta: [admin (signer), config]
44 /// Dane: min_difficulty u64 LE, base_weight u64 LE, round_seconds u64 LE
45 UpdateConfig = 7,
46
47 /// Przekazanie roli admina (docelowo: multisig z timelockiem).
48 /// Konta: [admin (signer), config]
49 /// Dane: new_admin [u8;32]
50 SetAdmin = 8,
51}
52
53impl MinerInstruction {
54 pub fn from_u8(v: u8) -> Option<Self> {
55 Some(match v {
56 0 => Self::Initialize,
57 1 => Self::Register,
58 2 => Self::AuthorizeSession,
59 3 => Self::Mine,
60 4 => Self::Claim,
61 5 => Self::Crank,
62 6 => Self::CloseRound,
63 7 => Self::UpdateConfig,
64 8 => Self::SetAdmin,
65 _ => return None,
66 })
67 }
68}