coal_guilds_api/
instruction.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
#[rustfmt::skip]
pub enum GuildInstruction {
    // User
    Join = 100,
    Leave = 101,
    Stake = 102,
    Unstake = 103,
    // Guild
    NewMember = 104,
    NewGuild = 105,
    NewInvite = 106,
    // Admin
    Initialize = 200,
}

impl GuildInstruction {
    pub fn to_vec(&self) -> Vec<u8> {
        vec![*self as u8]
    }
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {
    pub config_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct NewGuild {
    pub guild_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct NewMember {
    pub member_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct NewInvite {
    pub invite_bump: u8,
    pub guild_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Join {
    pub invite_bump: u8,
    pub member_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Leave {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Stake {
    pub amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Unstake {
    pub amount: [u8; 8],
}

instruction!(GuildInstruction, Initialize);
instruction!(GuildInstruction, NewGuild);
instruction!(GuildInstruction, NewMember);
instruction!(GuildInstruction, NewInvite);
instruction!(GuildInstruction, Join);
instruction!(GuildInstruction, Leave);
instruction!(GuildInstruction, Stake);
instruction!(GuildInstruction, Unstake);