This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlib.rs
106 lines (87 loc) · 3.15 KB
/
lib.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use anchor_lang::prelude::*;
mod error;
mod events;
mod instructions;
mod state;
use error::*;
use events::*;
use instructions::*;
use state::*;
#[cfg(not(any(feature = "mainnet", feature = "devnet")))]
declare_id!("v4enuof3drNvU2Y3b5m7K62hMq3QUP6qQSV2jjxAhkp");
#[cfg(feature = "devnet")]
declare_id!("D9JJgeRf2rKq5LNMHLBMb92g4ZpeMgCyvZkd7QKwSCzg");
#[cfg(feature = "mainnet")]
declare_id!("EXzAYHZ8xS6QJ6xGRsdKZXixoQBLsuMbmwJozm85jHp");
#[program]
pub mod wordcel {
use super::*;
pub fn initialize(ctx: Context<Initialize>, random_hash: [u8; 32]) -> Result<()> {
let profile = &mut ctx.accounts.profile;
profile.random_hash = random_hash;
profile.bump = *ctx.bumps.get("profile").unwrap();
profile.authority = *ctx.accounts.user.to_account_info().key;
Ok(())
}
pub fn create_post(
ctx: Context<CreatePost>,
metadata_uri: String,
random_hash: [u8; 32],
) -> Result<()> {
if metadata_uri.len() > MAX_LEN_URI {
return Err(error!(PostError::URITooLarge));
}
let post = &mut ctx.accounts.post;
post.random_hash = random_hash;
post.bump = *ctx.bumps.get("post").unwrap();
post.metadata_uri = metadata_uri;
post.profile = *ctx.accounts.profile.to_account_info().key;
let clock = Clock::get()?;
emit!(NewPost {
post: *ctx.accounts.post.to_account_info().key,
profile: *ctx.accounts.profile.to_account_info().key,
created_at: clock.unix_timestamp
});
Ok(())
}
pub fn update_post(ctx: Context<UpdatePost>, metadata_uri: String) -> Result<()> {
if metadata_uri.len() > MAX_LEN_URI {
return Err(error!(PostError::URITooLarge));
}
let post = &mut ctx.accounts.post;
post.metadata_uri = metadata_uri;
Ok(())
}
pub fn comment(
ctx: Context<Comment>,
metadata_uri: String,
random_hash: [u8; 32],
) -> Result<()> {
if metadata_uri.len() > MAX_LEN_URI {
return Err(error!(PostError::URITooLarge));
}
let post = &mut ctx.accounts.post;
post.random_hash = random_hash;
post.bump = *ctx.bumps.get("post").unwrap();
post.metadata_uri = metadata_uri;
post.reply_to = Some(*ctx.accounts.reply_to.to_account_info().key);
post.profile = *ctx.accounts.profile.to_account_info().key;
Ok(())
}
pub fn initialize_connection(ctx: Context<InitializeConnection>) -> Result<()> {
let connection = &mut ctx.accounts.connection;
connection.bump = *ctx.bumps.get("connection").unwrap();
connection.profile = *ctx.accounts.profile.to_account_info().key;
connection.authority = *ctx.accounts.authority.to_account_info().key;
let clock = Clock::get()?;
emit!(NewFollower {
user: *ctx.accounts.authority.to_account_info().key,
followed: *ctx.accounts.connection.to_account_info().key,
created_at: clock.unix_timestamp
});
Ok(())
}
pub fn close_connection(_ctx: Context<CloseConnection>) -> Result<()> {
Ok(())
}
}