1use anchor_lang::prelude::*;
2
3mod error;
4mod events;
5mod instructions;
6mod state;
7
8use error::*;
9use events::*;
10use instructions::*;
11use state::*;
12
13#[cfg(not(any(feature = "mainnet", feature = "devnet")))]
14declare_id!("v4enuof3drNvU2Y3b5m7K62hMq3QUP6qQSV2jjxAhkp");
15
16#[cfg(feature = "devnet")]
17declare_id!("D9JJgeRf2rKq5LNMHLBMb92g4ZpeMgCyvZkd7QKwSCzg");
18
19#[cfg(feature = "mainnet")]
20declare_id!("EXzAYHZ8xS6QJ6xGRsdKZXixoQBLsuMbmwJozm85jHp");
21
22#[program]
23pub mod wordcel {
24 use super::*;
25
26 pub fn initialize(ctx: Context<Initialize>, random_hash: [u8; 32]) -> Result<()> {
27 let profile = &mut ctx.accounts.profile;
28 profile.random_hash = random_hash;
29 profile.bump = *ctx.bumps.get("profile").unwrap();
30 profile.authority = *ctx.accounts.user.to_account_info().key;
31 Ok(())
32 }
33
34 pub fn create_post(
35 ctx: Context<CreatePost>,
36 metadata_uri: String,
37 random_hash: [u8; 32],
38 ) -> Result<()> {
39 if metadata_uri.len() > MAX_LEN_URI {
40 return Err(error!(PostError::URITooLarge));
41 }
42
43 let post = &mut ctx.accounts.post;
44 post.random_hash = random_hash;
45 post.bump = *ctx.bumps.get("post").unwrap();
46 post.metadata_uri = metadata_uri;
47 post.profile = *ctx.accounts.profile.to_account_info().key;
48 let clock = Clock::get()?;
49
50 emit!(NewPost {
51 post: *ctx.accounts.post.to_account_info().key,
52 profile: *ctx.accounts.profile.to_account_info().key,
53 created_at: clock.unix_timestamp
54 });
55
56 Ok(())
57 }
58
59 pub fn update_post(ctx: Context<UpdatePost>, metadata_uri: String) -> Result<()> {
60 if metadata_uri.len() > MAX_LEN_URI {
61 return Err(error!(PostError::URITooLarge));
62 }
63 let post = &mut ctx.accounts.post;
64 post.metadata_uri = metadata_uri;
65 Ok(())
66 }
67
68 pub fn comment(
69 ctx: Context<Comment>,
70 metadata_uri: String,
71 random_hash: [u8; 32],
72 ) -> Result<()> {
73 if metadata_uri.len() > MAX_LEN_URI {
74 return Err(error!(PostError::URITooLarge));
75 }
76
77 let post = &mut ctx.accounts.post;
78 post.random_hash = random_hash;
79 post.bump = *ctx.bumps.get("post").unwrap();
80 post.metadata_uri = metadata_uri;
81 post.reply_to = Some(*ctx.accounts.reply_to.to_account_info().key);
82 post.profile = *ctx.accounts.profile.to_account_info().key;
83 Ok(())
84 }
85
86 pub fn initialize_connection(ctx: Context<InitializeConnection>) -> Result<()> {
87 let connection = &mut ctx.accounts.connection;
88 connection.bump = *ctx.bumps.get("connection").unwrap();
89 connection.profile = *ctx.accounts.profile.to_account_info().key;
90 connection.authority = *ctx.accounts.authority.to_account_info().key;
91
92 let clock = Clock::get()?;
93
94 emit!(NewFollower {
95 user: *ctx.accounts.authority.to_account_info().key,
96 followed: *ctx.accounts.connection.to_account_info().key,
97 created_at: clock.unix_timestamp
98 });
99
100 Ok(())
101 }
102
103 pub fn close_connection(_ctx: Context<CloseConnection>) -> Result<()> {
104 Ok(())
105 }
106}