Skip to main content

oil_chat_api/state/
mod.rs

1mod config;
2mod message;
3mod reaction;
4mod user_chat_config;
5
6pub use config::*;
7pub use message::*;
8pub use reaction::*;
9pub use user_chat_config::*;
10
11use crate::consts::*;
12use steel::*;
13
14#[repr(u8)]
15#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
16pub enum ChatAccount {
17    Config = 100,
18    Message = 101,
19    Reaction = 102,
20    UserChatConfig = 103,
21}
22
23pub fn config_pda() -> (Pubkey, u8) {
24    Pubkey::find_program_address(&[CONFIG], &crate::ID)
25}
26
27pub fn message_pda(authority: Pubkey, message_id: u64) -> (Pubkey, u8) {
28    Pubkey::find_program_address(
29        &[MESSAGE, &authority.to_bytes(), &message_id.to_le_bytes()],
30        &crate::ID,
31    )
32}
33
34pub fn reaction_pda(message_pda: Pubkey, authority: Pubkey, emoji: &[u8]) -> (Pubkey, u8) {
35    Pubkey::find_program_address(
36        &[REACTION, &message_pda.to_bytes(), &authority.to_bytes(), emoji],
37        &crate::ID,
38    )
39}
40
41pub fn user_chat_config_pda(authority: Pubkey) -> (Pubkey, u8) {
42    Pubkey::find_program_address(
43        &[b"user_chat_config", &authority.to_bytes()],
44        &crate::ID,
45    )
46}