Skip to content

Commit

Permalink
feat: profiles are managed by community
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Oct 21, 2024
1 parent 626268b commit 0bcef89
Show file tree
Hide file tree
Showing 57 changed files with 1,158 additions and 923 deletions.
2 changes: 1 addition & 1 deletion anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cluster = "Localnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "../node_modules/.bin/nx run anchor:jest"
test = "../node_modules/.bin/nx run anchor:jest --runInBand"

[test]
startup_wait = 5000
Expand Down
4 changes: 2 additions & 2 deletions anchor/programs/pubkey-protocol/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ pub enum ProtocolError {
CannotRemoveLastAuthority,
#[msg("Cannot remove the Solana provider")]
CannotRemoveSolanaProvider,
#[msg("Community verification already exists")]
CommunityVerificationAlreadyExists,
#[msg("Account not owned by program")]
InvalidAccountOwner,
#[msg("Account too large")]
Expand Down Expand Up @@ -86,4 +84,6 @@ pub enum ProtocolError {
UnauthorizedCommunityAction,
#[msg("Account is not defined in config.community_authority")]
UnAuthorizedCommunityAuthority,
#[msg("Account is not a signer for this community")]
UnAuthorizedCommunitySigner,
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod community_update_authority_approve;
pub mod community_update_authority_decline;
pub mod community_update_authority_request;
pub mod community_update_details;
pub mod verify_profile_identity;

pub use community_create::*;
pub use community_provider_disable::*;
Expand All @@ -18,4 +17,3 @@ pub use community_update_authority_approve::*;
pub use community_update_authority_decline::*;
pub use community_update_authority_request::*;
pub use community_update_details::*;
pub use verify_profile_identity::*;

This file was deleted.

2 changes: 0 additions & 2 deletions anchor/programs/pubkey-protocol/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pub mod community;
pub mod config;
pub mod identity;
pub mod profile;

pub use community::*;
pub use config::*;
pub use identity::*;
pub use profile::*;
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
pub mod profile_authority_add;
pub mod profile_authority_remove;
pub mod profile_create;
pub mod profile_identity_add;
pub mod profile_identity_remove;
pub mod profile_identity_verify;
pub mod profile_update_details;

pub use profile_authority_add::*;
pub use profile_authority_remove::*;
pub use profile_create::*;
pub use profile_identity_add::*;
pub use profile_identity_remove::*;
pub use profile_identity_verify::*;
pub use profile_update_details::*;
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ pub struct ProfileAuthorityAdd<'info> {
&profile.username.as_bytes()
],
bump = profile.bump,
has_one = fee_payer @ ProtocolError::UnAuthorized,
constraint = profile.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized
)]
pub profile: Account<'info, Profile>,

pub authority: Signer<'info>,

pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&authority.key()) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ pub struct ProfileAuthorityRemove<'info> {
&profile.username.as_bytes()
],
bump = profile.bump,
has_one = fee_payer @ ProtocolError::UnAuthorized,
// has_one = fee_payer @ ProtocolError::UnAuthorized,
constraint = profile.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized
)]
pub profile: Account<'info, Profile>,

pub authority: Signer<'info>,

pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&authority.key()) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ pub struct ProfileCreate<'info> {

pub authority: Signer<'info>,

pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&authority.key()) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,

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

pub fn profile_create(ctx: Context<ProfileCreate>, args: ProfileCreateArgs) -> Result<()> {
let profile = &mut ctx.accounts.profile;
let authority = ctx.accounts.authority.key();
let fee_payer = ctx.accounts.fee_payer.key();
let community = &ctx.accounts.community;
let profile = &mut ctx.accounts.profile;
let pointer = &mut ctx.accounts.pointer;

// Creating pointer account
Expand All @@ -69,15 +71,14 @@ pub fn profile_create(ctx: Context<ProfileCreate>, args: ProfileCreateArgs) -> R
provider: IdentityProvider::Solana,
provider_id: authority.key().to_string(),
name: "Primary Wallet".to_owned(),
communities: vec![],
communities: vec![community.key()],
};

profile.set_inner(Profile {
bump: ctx.bumps.profile,
username,
name,
avatar_url,
fee_payer,
authorities: vec![authority],
identities: vec![set_primary_wallet],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::state::*;
use crate::utils::*;

#[derive(Accounts)]
#[instruction(args: AddIdentityArgs)]
pub struct AddIdentity<'info> {
#[instruction(args: ProfileIdentityAddArgs)]
pub struct ProfileIdentityAdd<'info> {
#[account(
mut,
seeds = [
Expand All @@ -16,7 +16,6 @@ pub struct AddIdentity<'info> {
&profile.username.as_bytes()
],
bump = profile.bump,
has_one = fee_payer @ ProtocolError::UnAuthorized,
constraint = profile.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized
)]
pub profile: Account<'info, Profile>,
Expand All @@ -32,18 +31,24 @@ pub struct AddIdentity<'info> {

pub authority: Signer<'info>,

pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&authority.key()) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn add(ctx: Context<AddIdentity>, args: AddIdentityArgs) -> Result<()> {
let profile = &mut ctx.accounts.profile;
let pointer = &mut ctx.accounts.pointer;
pub fn profile_identity_add(
ctx: Context<ProfileIdentityAdd>,
args: ProfileIdentityAddArgs,
) -> Result<()> {
let community = &ctx.accounts.community;
let fee_payer = &ctx.accounts.fee_payer;
let pointer = &mut ctx.accounts.pointer;
let profile = &mut ctx.accounts.profile;
let system_program = &ctx.accounts.system_program;

// Initializing pointer account
Expand All @@ -60,7 +65,7 @@ pub fn add(ctx: Context<AddIdentity>, args: AddIdentityArgs) -> Result<()> {
provider: args.provider,
provider_id: args.provider_id,
name: args.name,
communities: vec![],
communities: vec![community.key()],
};

identity.validate()?;
Expand Down Expand Up @@ -89,7 +94,7 @@ pub fn add(ctx: Context<AddIdentity>, args: AddIdentityArgs) -> Result<()> {
}

#[derive(AnchorSerialize, AnchorDeserialize, Debug)]
pub struct AddIdentityArgs {
pub struct ProfileIdentityAddArgs {
provider: IdentityProvider,
provider_id: String,
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::errors::*;
use crate::state::*;

#[derive(Accounts)]
#[instruction(args: RemoveIdentityArgs)]
pub struct RemoveIdentity<'info> {
#[instruction(args: ProfileIdentityRemoveArgs)]
pub struct ProfileIdentityRemove<'info> {
#[account(
mut,
seeds = [
Expand All @@ -15,7 +15,6 @@ pub struct RemoveIdentity<'info> {
&profile.username.as_bytes()
],
bump = profile.bump,
has_one = fee_payer @ ProtocolError::UnAuthorized,
constraint = profile.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized
)]
pub profile: Account<'info, Profile>,
Expand All @@ -31,15 +30,20 @@ pub struct RemoveIdentity<'info> {

pub authority: Signer<'info>,

pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&authority.key()) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn remove(ctx: Context<RemoveIdentity>, args: RemoveIdentityArgs) -> Result<()> {
pub fn profile_identity_remove(
ctx: Context<ProfileIdentityRemove>,
args: ProfileIdentityRemoveArgs,
) -> Result<()> {
let profile = &mut ctx.accounts.profile;
let provider = ctx.accounts.pointer.provider.clone();

Expand All @@ -60,6 +64,6 @@ pub fn remove(ctx: Context<RemoveIdentity>, args: RemoveIdentityArgs) -> Result<
}

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct RemoveIdentityArgs {
pub struct ProfileIdentityRemoveArgs {
pub provider_id: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::errors::*;
use crate::state::*;

#[derive(Accounts)]
#[instruction(args: VerifyProfileIdentityArgs)]
pub struct VerifyProfileIdentity<'info> {
#[instruction(args: ProfileIdentityVerifyArgs)]
pub struct ProfileIdentityVerify<'info> {
#[account(mut)]
pub community: Account<'info, Community>,

Expand All @@ -25,9 +25,9 @@ pub struct VerifyProfileIdentity<'info> {
pub fee_payer: Signer<'info>,
}

pub fn verify_profile_identity(
ctx: Context<VerifyProfileIdentity>,
args: VerifyProfileIdentityArgs,
pub fn profile_identity_verify(
ctx: Context<ProfileIdentityVerify>,
args: ProfileIdentityVerifyArgs,
) -> Result<()> {
let community = &ctx.accounts.community;
let profile = &mut ctx.accounts.profile;
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn verify_profile_identity(
}

#[derive(AnchorSerialize, AnchorDeserialize, Debug)]
pub struct VerifyProfileIdentityArgs {
pub struct ProfileIdentityVerifyArgs {
provider: IdentityProvider,
provider_id: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::state::*;
use crate::utils::*;

#[derive(Accounts)]
#[instruction(args: UpdateProfileDetailsArgs)]
pub struct UpdateProfileDetails<'info> {
#[instruction(args: ProfileUpdateDetailsArgs)]
pub struct ProfileUpdateDetails<'info> {
#[account(
mut,
seeds = [
Expand All @@ -16,21 +16,23 @@ pub struct UpdateProfileDetails<'info> {
&profile.username.as_bytes()
],
bump = profile.bump,
has_one = fee_payer @ ProtocolError::UnAuthorized,
constraint = profile.check_for_authority(&args.authority) @ ProtocolError::UnAuthorized
constraint = profile.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized
)]
pub profile: Account<'info, Profile>,

pub authority: Signer<'info>,
pub community: Account<'info, Community>,

#[account(
mut,
constraint = fee_payer.key().ne(&args.authority) @ ProtocolError::InvalidFeePayer
constraint = community.check_for_signer(&fee_payer.key()) @ ProtocolError::UnAuthorizedCommunitySigner,
)]
pub fee_payer: Signer<'info>,
}

pub fn profile_update_details(
ctx: Context<UpdateProfileDetails>,
args: UpdateProfileDetailsArgs,
ctx: Context<ProfileUpdateDetails>,
args: ProfileUpdateDetailsArgs,
) -> Result<()> {
let profile = &mut ctx.accounts.profile;

Expand All @@ -53,8 +55,7 @@ pub fn profile_update_details(
}

#[derive(AnchorSerialize, AnchorDeserialize)]
pub struct UpdateProfileDetailsArgs {
pub authority: Pubkey,
pub struct ProfileUpdateDetailsArgs {
pub new_name: Option<String>,
pub new_avatar_url: Option<String>,
}
Loading

0 comments on commit 0bcef89

Please sign in to comment.