Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
target
**/*.rs.bk
node_modules
test_ledger/
test-ledger/
.goki/
121 changes: 113 additions & 8 deletions programs/wordcel/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct CreateEditor<'info> {
init,
seeds = [
b"editor".as_ref(),
host_profile.authority.key().as_ref(),
editor_profile.authority.key().as_ref()
host_profile.key().as_ref(),
editor_profile.key().as_ref()
],
bump,
payer = authority,
Expand All @@ -47,8 +47,8 @@ pub struct RemoveEditor<'info> {
mut,
seeds = [
b"editor".as_ref(),
host_profile.authority.key().as_ref(),
editor_profile.authority.key().as_ref()
host_profile.key().as_ref(),
editor_profile.key().as_ref()
],
bump = editor.bump,
close = authority,
Expand All @@ -63,7 +63,7 @@ pub struct RemoveEditor<'info> {
}

#[derive(Accounts)]
#[instruction(metadata_uri: String)]
#[instruction(metadata_uri: String, random_hash: [u8;32])]
pub struct CreatePostAsEditor<'info> {
// Checks if the original profile was supplied and if the profile authority is the signer
#[account(
Expand All @@ -76,7 +76,61 @@ pub struct CreatePostAsEditor<'info> {
)]
pub editor_profile: Account<'info, Profile>,

// Checks if a post was supplied and it is part of the supplied profile.
#[account(
seeds = [
b"profile".as_ref(),
&host_profile.random_hash
],
bump = host_profile.bump
)]
pub host_profile: Account<'info, Profile>,

#[account(
has_one = host_profile,
seeds = [
b"editor".as_ref(),
host_profile.key().as_ref(),
editor_profile.key().as_ref()
],
bump = editor.bump
)]
pub editor: Account<'info, Editor>,

// Initializes a new post account and checks if the signer is the authority
#[account(
init,
constraint = editor_profile.to_account_info().key() == editor.host_profile || editor_profile.to_account_info().key() == editor.editor_profile,
seeds = [
b"post".as_ref(),
&random_hash
],
bump,
payer = authority,
space = Post::LEN
)]
pub post: Account<'info, Post>,

#[account(mut)]
pub authority: Signer<'info>,

pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
#[instruction(metadata_uri: String)]
pub struct UpdatePostAsEditor<'info> {
// Checks if the original profile was supplied and if the profile authority is the signer
#[account(
has_one = authority,
seeds = [
b"profile".as_ref(),
&editor_profile.random_hash
],
bump = editor_profile.bump
)]
pub editor_profile: Account<'info, Profile>,

// Mutable Account of Post that has to be updated
#[account(
mut,
constraint = post.profile == editor_profile.to_account_info().key() || post.profile == host_profile.to_account_info().key(),
Expand All @@ -101,8 +155,8 @@ pub struct CreatePostAsEditor<'info> {
has_one = host_profile,
seeds = [
b"editor".as_ref(),
host_profile.authority.key().as_ref(),
editor_profile.authority.key().as_ref()
host_profile.key().as_ref(),
editor_profile.key().as_ref()
],
bump = editor.bump
)]
Expand All @@ -114,6 +168,57 @@ pub struct CreatePostAsEditor<'info> {
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct DeletePostAsEditor<'info> {
// Checks if the original profile was supplied and if the profile authority is the signer
#[account(
has_one = authority,
seeds = [
b"profile".as_ref(),
&editor_profile.random_hash
],
bump = editor_profile.bump
)]
pub editor_profile: Account<'info, Profile>,

#[account(
seeds = [
b"profile".as_ref(),
&host_profile.random_hash
],
bump = host_profile.bump
)]
pub host_profile: Account<'info, Profile>,

#[account(
has_one = host_profile,
seeds = [
b"editor".as_ref(),
host_profile.key().as_ref(),
editor_profile.key().as_ref()
],
bump = editor.bump
)]
pub editor: Account<'info, Editor>,

// Mutable Account of Post that has to be deleted
#[account(
mut,
seeds = [
b"post".as_ref(),
&post.random_hash
],
bump = post.bump,
close = authority
)]
pub post: Account<'info, Post>,

#[account(mut)]
pub authority: Signer<'info>,

pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
#[instruction(metadata_uri: String, random_hash: [u8;32])]
pub struct CreatePost<'info> {
Expand Down
28 changes: 22 additions & 6 deletions programs/wordcel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use instructions::*;
use state::*;

#[cfg(not(any(feature = "mainnet", feature = "devnet")))]
declare_id!("v4enuof3drNvU2Y3b5m7K62hMq3QUP6qQSV2jjxAhkp");
declare_id!("6bxpSrHAc9zoWHKLJX3sfudTarFaHZoKQbM2XsyjJpMF");

#[cfg(feature = "devnet")]
declare_id!("D9JJgeRf2rKq5LNMHLBMb92g4ZpeMgCyvZkd7QKwSCzg");
Expand All @@ -37,7 +37,7 @@ pub mod wordcel {
metadata_uri: String,
random_hash: [u8; 32],
) -> Result<()> {
require_gt!(metadata_uri.len(), MAX_LEN_URI, PostError::URITooLarge);
require!(metadata_uri.len() < MAX_LEN_URI, PostError::URITooLarge);

let post = &mut ctx.accounts.post;
post.random_hash = random_hash;
Expand All @@ -56,7 +56,7 @@ pub mod wordcel {
}

pub fn update_post(ctx: Context<UpdatePost>, metadata_uri: String) -> Result<()> {
require_gt!(metadata_uri.len(), MAX_LEN_URI, PostError::URITooLarge);
require!(metadata_uri.len() < MAX_LEN_URI, PostError::URITooLarge);

let post = &mut ctx.accounts.post;
post.metadata_uri = metadata_uri;
Expand All @@ -68,7 +68,7 @@ pub mod wordcel {
metadata_uri: String,
random_hash: [u8; 32],
) -> Result<()> {
require_gt!(metadata_uri.len(), MAX_LEN_URI, PostError::URITooLarge);
require!(metadata_uri.len() < MAX_LEN_URI, PostError::URITooLarge);

let post = &mut ctx.accounts.post;
post.random_hash = random_hash;
Expand Down Expand Up @@ -122,11 +122,27 @@ pub mod wordcel {
Ok(())
}

pub fn update_post_as_editor(ctx: Context<PostAsEditor>, metadata_uri: String) -> Result<()> {
require_gt!(metadata_uri.len(), MAX_LEN_URI, PostError::URITooLarge);

pub fn create_post_as_editor(ctx: Context<CreatePostAsEditor>, metadata_uri: String, random_hash: [u8; 32]) -> Result<()> {
require!(metadata_uri.len() < MAX_LEN_URI, 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.host_profile.to_account_info().key;
Ok(())
}

pub fn update_post_as_editor(ctx: Context<UpdatePostAsEditor>, metadata_uri: String) -> Result<()> {
require!(metadata_uri.len() < MAX_LEN_URI, PostError::URITooLarge);

let post = &mut ctx.accounts.post;
post.metadata_uri = metadata_uri;
Ok(())
}

pub fn delete_post_as_editor(_ctx: Context<DeletePostAsEditor>) -> Result<()> {
Ok(())
}
}
Loading