Skip to main content

miner_api/
instruction.rs

1/// Instruction tags (first byte of instruction data).
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3#[repr(u8)]
4pub enum MinerInstruction {
5    /// Program initialization.
6    /// Accounts: [admin (signer, payer), config (PDA), mint, round0 (PDA),
7    ///           system_program]
8    /// Mint requirements (created outside the program before initialize):
9    /// decimals = 9, mint_authority = "treasury" PDA, freeze_authority = None.
10    Initialize = 0,
11
12    /// Miner registration.
13    /// Accounts: [authority (signer, payer), miner (PDA), slot_hashes,
14    ///           system_program]
15    Register = 1,
16
17    /// Set a session key (signs background submits).
18    /// Accounts: [authority (signer), miner]
19    /// Data: session_key [u8;32] (zeros = revoke)
20    AuthorizeSession = 2,
21
22    /// Hash submission (once per round): PoW verification, weight accrual,
23    /// lazy settlement of the previous round.
24    /// Accounts: [signer (authority or session), miner, config,
25    ///           current_round, prev_round, token_account (authority ATA),
26    ///           slot_hashes]
27    /// Data: nonce u64 LE
28    Mine = 3,
29
30    /// Claim accrued rewards (mint to the authority's ATA).
31    /// Accounts: [authority (signer), miner, config, prev_round, mint,
32    ///           treasury (PDA), token_account (authority ATA), token_program]
33    Claim = 4,
34
35    /// Close the current round and open the next (permissionless crank).
36    /// Accounts: [payer (signer), config, new_round (PDA), system_program]
37    Crank = 5,
38
39    /// Close an expired Round account after retention (rent to the caller).
40    /// Accounts: [recipient (signer), config, round]
41    CloseRound = 6,
42
43    /// Admin parameter change.
44    /// Accounts: [admin (signer), config]
45    /// Data: min_difficulty u64 LE, base_weight u64 LE, round_seconds u64 LE
46    UpdateConfig = 7,
47
48    /// Admin role handover (ultimately: a multisig with a timelock).
49    /// Accounts: [admin (signer), config]
50    /// Data: new_admin [u8;32]
51    SetAdmin = 8,
52}
53
54impl MinerInstruction {
55    pub fn from_u8(v: u8) -> Option<Self> {
56        Some(match v {
57            0 => Self::Initialize,
58            1 => Self::Register,
59            2 => Self::AuthorizeSession,
60            3 => Self::Mine,
61            4 => Self::Claim,
62            5 => Self::Crank,
63            6 => Self::CloseRound,
64            7 => Self::UpdateConfig,
65            8 => Self::SetAdmin,
66            _ => return None,
67        })
68    }
69}