Skip to content

Commit

Permalink
feat: implement config_delete_pointer and config_delete_profile
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Nov 4, 2024
1 parent 52a5c81 commit 8daced7
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anchor_lang::prelude::*;

use crate::errors::*;
use crate::state::*;

#[derive(Accounts)]
#[instruction()]
pub struct ConfigDeletePointer<'info> {
#[account(mut)]
pub config: Account<'info, Config>,
#[account(
mut,
constraint = config.check_for_config_authority(&config_authority.key()) @ ProtocolError::UnAuthorizedCommunityAuthority
)]
pub config_authority: Signer<'info>,
#[account(
mut,
close = config_authority,
)]
pub pointer: Account<'info, Pointer>,
}

pub fn config_delete_pointer(_ctx: Context<ConfigDeletePointer>) -> Result<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anchor_lang::prelude::*;

use crate::errors::*;
use crate::state::*;

#[derive(Accounts)]
#[instruction()]
pub struct ConfigDeleteProfile<'info> {
#[account(mut)]
pub config: Account<'info, Config>,
#[account(
mut,
constraint = config.check_for_config_authority(&config_authority.key()) @ ProtocolError::UnAuthorizedCommunityAuthority
)]
pub config_authority: Signer<'info>,
#[account(
mut,
close = config_authority,
)]
pub profile: Account<'info, Profile>,
}

pub fn config_delete_profile(_ctx: Context<ConfigDeleteProfile>) -> Result<()> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pub mod config_delete_pointer;
pub mod config_delete_profile;
pub mod config_init;

pub use config_delete_pointer::*;
pub use config_delete_profile::*;
pub use config_init::*;
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ pub fn profile_update(
pub struct ProfileUpdateArgs {
pub new_name: Option<String>,
pub new_avatar_url: Option<String>,
pub new_bio: Option<String>,
pub new_bio: Option<String>,
}
8 changes: 8 additions & 0 deletions anchor/programs/pubkey-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ pub mod pubkey_protocol {
community::community_update(ctx, args)
}

pub fn config_delete_pointer(ctx: Context<ConfigDeletePointer>) -> Result<()> {
config::config_delete_pointer(ctx)
}

pub fn config_delete_profile(ctx: Context<ConfigDeleteProfile>) -> Result<()> {
config::config_delete_profile(ctx)
}

pub fn config_init(ctx: Context<ConfigInit>, args: ConfigInitArgs) -> Result<()> {
config::config_init(ctx, args)
}
Expand Down
58 changes: 58 additions & 0 deletions anchor/target/idl/pubkey_protocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,64 @@
}
]
},
{
"name": "config_delete_pointer",
"discriminator": [
127,
151,
20,
152,
180,
177,
230,
96
],
"accounts": [
{
"name": "config",
"writable": true
},
{
"name": "config_authority",
"writable": true,
"signer": true
},
{
"name": "pointer",
"writable": true
}
],
"args": []
},
{
"name": "config_delete_profile",
"discriminator": [
28,
66,
90,
94,
127,
245,
235,
199
],
"accounts": [
{
"name": "config",
"writable": true
},
{
"name": "config_authority",
"writable": true,
"signer": true
},
{
"name": "profile",
"writable": true
}
],
"args": []
},
{
"name": "config_init",
"discriminator": [
Expand Down
58 changes: 58 additions & 0 deletions anchor/target/types/pubkey_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,64 @@ export type PubkeyProtocol = {
}
]
},
{
"name": "configDeletePointer",
"discriminator": [
127,
151,
20,
152,
180,
177,
230,
96
],
"accounts": [
{
"name": "config",
"writable": true
},
{
"name": "configAuthority",
"writable": true,
"signer": true
},
{
"name": "pointer",
"writable": true
}
],
"args": []
},
{
"name": "configDeleteProfile",
"discriminator": [
28,
66,
90,
94,
127,
245,
235,
199
],
"accounts": [
{
"name": "config",
"writable": true
},
{
"name": "configAuthority",
"writable": true,
"signer": true
},
{
"name": "profile",
"writable": true
}
],
"args": []
},
{
"name": "configInit",
"discriminator": [
Expand Down
22 changes: 22 additions & 0 deletions anchor/tests/pubkey-protocol-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,26 @@ describe('pubkey-protocol-config', () => {
expect(config.configAuthority).toEqual(feePayer.publicKey)
})
})

describe('delete operations', () => {
xit('should delete a pointer', async () => {
// FIXME: implement this test
const res = await createOrGetTestConfig(program, feePayer.publicKey)
const config = await program.account.config.fetch(res.config)

// TBD

expect(true).toBe(true)
})

xit('should delete a profile', async () => {
// FIXME: implement this test
const res = await createOrGetTestConfig(program, feePayer.publicKey)
const config = await program.account.config.fetch(res.config)

// TBD

expect(true).toBe(true)
})
})
})
30 changes: 30 additions & 0 deletions cli/src/commands/get-config-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ import { createOrGetConfig } from './create-or-get-config'
export function getConfigCommand(): Command {
const command = new Command('config').description('Manage config')

command
.command('delete-pointer <pointer>')
.description('Delete a pointer')
.action(async (pointer: string) => {
const { configAuthority, cluster, connection, endpoint, sdk } = await getConfig()
const { tx: transaction } = await sdk.configDeletePointer({
configAuthority: configAuthority.publicKey,
pointer,
})
transaction.sign([configAuthority])
const s = await connection.sendRawTransaction(transaction.serialize(), { skipPreflight: true })
console.log(`Created pointer: ${pointer}`, s)
console.log(getExplorerUrl(`tx/${s}?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899`, cluster, endpoint))
})

command
.command('delete-profile <profile>')
.description('Delete a profile')
.action(async (profile: string) => {
const { configAuthority, cluster, connection, endpoint, sdk } = await getConfig()
const { tx: transaction } = await sdk.configDeleteProfile({
configAuthority: configAuthority.publicKey,
profile,
})
transaction.sign([configAuthority])
const s = await connection.sendRawTransaction(transaction.serialize(), { skipPreflight: true })
console.log(`Created profile: ${profile}`, s)
console.log(getExplorerUrl(`tx/${s}?cluster=custom&customUrl=http%3A%2F%2Flocalhost%3A8899`, cluster, endpoint))
})

command
.command('get')
.description('Get the config')
Expand Down
4 changes: 3 additions & 1 deletion cli/src/utils/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export async function getConfig() {
const programId = new PublicKey(process.env.PUBKEY_PROTOCOL_PROGRAM_ID || PUBKEY_PROTOCOL_PROGRAM_ID)
const connection = new Connection(endpoint, 'confirmed')
const sdk = await getPubkeyProtocolSdk({ connection, programId })
const configAuthority = getConfigKeypair()
const configAuthority = process.env.CONFIG_KEYPAIR_PATH
? await getKeypairFromFile(process.env.CONFIG_KEYPAIR_PATH)
: getConfigKeypair()
const authority = await getKeypairFromFile(process.env.AUTHORITY_KEYPAIR_PATH)

console.log(`Endpoint: ${endpoint}`)
Expand Down
37 changes: 37 additions & 0 deletions sdk/src/lib/pubkey-protocol-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,43 @@ export class PubKeyProtocolSdk {

return { input, tx }
}
async configDeletePointer(options: { configAuthority: PublicKeyString; pointer: PublicKeyString }) {
const [config] = this.pdaConfig()
const pointer = new PublicKey(options.pointer)
const configAuthority = new PublicKey(options.configAuthority)

const ix = await this.program.methods
.configDeletePointer()
.accounts({
config,
configAuthority,
pointer,
})
.instruction()

const tx = await this.createTransaction({ feePayer: configAuthority, ix })

return { tx }
}

async configDeleteProfile(options: { configAuthority: PublicKeyString; profile: PublicKeyString }) {
const [config] = this.pdaConfig()
const profile = this.profileGetPda({ profile: new PublicKey(options.profile) })
const configAuthority = new PublicKey(options.configAuthority)

const ix = await this.program.methods
.configDeleteProfile()
.accounts({
config,
configAuthority,
profile,
})
.instruction()

const tx = await this.createTransaction({ feePayer: configAuthority, ix })

return { tx }
}

async configGet(options: { nullable?: boolean }): Promise<PubKeyConfig | null> {
const [config] = this.pdaConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useQueryGetProgramAccount } from './use-query-get-program-account'
export interface PubKeyProfileProviderContext {
authority: PublicKeyString
cluster: Cluster
connection: Connection
feePayer: PublicKeyString
getExplorerUrl: (path: string) => string
getIdentityUrl: (identity: PubKeyIdentity) => string | undefined
Expand Down Expand Up @@ -129,6 +130,7 @@ export function PubKeyProtocolProvider({
const value: PubKeyProfileProviderContext = {
authority: publicKey,
cluster,
connection,
feePayer,
getExplorerUrl,
getIdentityUrl,
Expand Down
Loading

0 comments on commit 8daced7

Please sign in to comment.