-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
2,182 additions
and
621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
anchor/programs/pubkey-protocol/src/instructions/community/community_signer_remove.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::constants::*; | ||
use crate::errors::*; | ||
use crate::state::*; | ||
use crate::utils::*; | ||
|
||
#[derive(Accounts)] | ||
#[instruction(args: CommunitySignerRemoveArgs)] | ||
pub struct CommunitySignerRemove<'info> { | ||
#[account( | ||
mut, | ||
seeds = [ | ||
PREFIX, | ||
COMMUNITY, | ||
&community.slug.as_bytes() | ||
], | ||
bump = community.bump, | ||
has_one = authority @ ProtocolError::UnAuthorized, | ||
)] | ||
pub community: Account<'info, Community>, | ||
|
||
#[account( | ||
mut, | ||
constraint = community.check_for_authority(&authority.key()) @ ProtocolError::UnAuthorized) | ||
] | ||
pub authority: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
pub fn community_signer_remove( | ||
ctx: Context<CommunitySignerRemove>, | ||
args: CommunitySignerRemoveArgs, | ||
) -> Result<()> { | ||
let community = &mut ctx.accounts.community; | ||
let signer = args.signer; | ||
|
||
// Ensure the signer is in the community.signers vector | ||
require!( | ||
community.signers.contains(&signer), | ||
ProtocolError::SignerDoesNotExist | ||
); | ||
|
||
// Ensure there is at least one signer left after removing this signer | ||
require!(community.signers.len() > 1, ProtocolError::SignerRequired); | ||
|
||
// Remove the signer from the community.signers vector | ||
community.signers.retain(|s| !s.eq(&signer)); | ||
|
||
// Calculate the new account size | ||
let new_account_size = Community::size(&community.signers, &community.providers); | ||
|
||
// Reallocate the account if necessary | ||
realloc_account( | ||
community.to_account_info(), | ||
new_account_size, | ||
ctx.accounts.authority.to_account_info(), | ||
ctx.accounts.system_program.to_account_info(), | ||
)?; | ||
|
||
// Validate the updated community | ||
community.validate()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct CommunitySignerRemoveArgs { | ||
pub signer: Pubkey, | ||
} |
6 changes: 4 additions & 2 deletions
6
anchor/programs/pubkey-protocol/src/instructions/community/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
pub mod community_create; | ||
pub mod community_provider_disable; | ||
pub mod community_provider_enable; | ||
pub mod community_signer_add; | ||
pub mod community_signer_remove; | ||
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 community_update_feepayers; | ||
pub mod verify_profile_identity; | ||
|
||
pub use community_create::*; | ||
pub use community_provider_disable::*; | ||
pub use community_provider_enable::*; | ||
pub use community_signer_add::*; | ||
pub use community_signer_remove::*; | ||
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 community_update_feepayers::*; | ||
pub use verify_profile_identity::*; |
41 changes: 41 additions & 0 deletions
41
anchor/programs/pubkey-protocol/src/instructions/config/config_init.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::constants::*; | ||
use crate::state::*; | ||
|
||
#[derive(Accounts)] | ||
#[instruction(args: ConfigInitArgs)] | ||
pub struct ConfigInit<'info> { | ||
#[account( | ||
init, | ||
payer = authority, | ||
space = Config::size(), | ||
seeds = [ PREFIX, CONFIG ], | ||
bump | ||
)] | ||
pub config: Account<'info, Config>, | ||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
pub fn config_init(ctx: Context<ConfigInit>, args: ConfigInitArgs) -> Result<()> { | ||
let config = &mut ctx.accounts.config; | ||
|
||
let authority = ctx.accounts.authority.key(); | ||
|
||
config.set_inner(Config { | ||
bump: ctx.bumps.config, | ||
community_authority: args.community_authority, | ||
config_authority: authority, | ||
}); | ||
|
||
config.validate()?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct ConfigInitArgs { | ||
pub community_authority: Pubkey, | ||
} |
3 changes: 3 additions & 0 deletions
3
anchor/programs/pubkey-protocol/src/instructions/config/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod config_init; | ||
|
||
pub use config_init::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod community; | ||
pub mod config; | ||
pub mod identity; | ||
pub mod profile; | ||
|
||
pub use community::*; | ||
pub use config::*; | ||
pub use identity::*; | ||
pub use profile::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.