// pass this to Context#[derive(Accounts)]pub struct CreatePost<'info> { // add other properties pub post: Account<'info, PostAccount>, // Clock to save time of post pub clock: Sysvar<'info, Clock>,}
PostAccount struct:
#[account]pub struct PostAccount { // add other properties // post time pub post_time: i64,}
Define function in mod
pub fn create_post(ctx: Context<CreatePost>) -> ProgramResult { let post = &mut ctx.accounts.post; // get the timestamp of post post.post_time = ctx.accounts.clock.unix_timestamp; }