Skip to content

Commit

Permalink
use recipient endpoint for v1 v2
Browse files Browse the repository at this point in the history
  • Loading branch information
docongminh committed Jan 19, 2025
1 parent 627b234 commit 1e7d01e
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct CreateVestingEscrowMetadataParameters {
pub name: String,
pub description: String,
pub creator_email: String,
pub recipient_email: String,
pub recipient_endpoint: String,
}

/// Accounts for [locker::create_vesting_escrow_metadata].
Expand Down Expand Up @@ -45,6 +45,6 @@ pub fn handle_create_vesting_escrow_metadata(
escrow_metadata.name = params.name.clone();
escrow_metadata.description = params.description.clone();
escrow_metadata.creator_email = params.creator_email.clone();
escrow_metadata.recipient_email = params.recipient_email.clone();
escrow_metadata.recipient_endpoint = params.recipient_endpoint.clone();
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ pub struct UpdateVestingEscrowRecipientCtx<'info> {
pub fn handle_update_vesting_escrow_recipient(
ctx: Context<UpdateVestingEscrowRecipientCtx>,
new_recipient: Pubkey,
new_recipient_email: Option<String>,
new_recipient_endpoint: Option<String>,
) -> Result<()> {
let mut escrow = ctx.accounts.escrow.load_mut()?;
let old_recipient = escrow.recipient;
let signer = ctx.accounts.signer.key();
escrow.validate_update_actor(signer)?;
escrow.update_recipient(new_recipient);

if let Some(recipient_email) = new_recipient_email {
if let Some(recipient_endpoint) = new_recipient_endpoint {
if let Some(escrow_metadata) = &mut ctx.accounts.escrow_metadata {
require!(
escrow_metadata.escrow == ctx.accounts.escrow.key(),
Expand All @@ -46,7 +46,7 @@ pub fn handle_update_vesting_escrow_recipient(
name: escrow_metadata.name.clone(),
description: escrow_metadata.description.clone(),
creator_email: escrow_metadata.creator_email.clone(),
recipient_email: recipient_email.clone(),
recipient_endpoint: recipient_endpoint.clone(),
});

// update rent fee
Expand All @@ -66,7 +66,7 @@ pub fn handle_update_vesting_escrow_recipient(
// realloc
escrow_metadata_info.realloc(new_len, false)?;
// update new recipient_email
escrow_metadata.recipient_email = recipient_email;
escrow_metadata.recipient_endpoint = recipient_endpoint;
} else {
return Err(LockerError::InvalidEscrowMetadata.into());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ pub fn handle_create_vesting_escrow_metadata_v3(
escrow_metadata.name = params.name.clone();
escrow_metadata.description = params.description.clone();
escrow_metadata.creator_email = params.creator_email.clone();
escrow_metadata.recipient_email = String::from("");
escrow_metadata.recipient_endpoint = params.recipient_endpoint.clone();
Ok(())
}
6 changes: 3 additions & 3 deletions programs/locker/src/state/vesting_escrow_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub struct VestingEscrowMetadata {
pub description: String,
/// Email of creator
pub creator_email: String,
/// Email of recipient
pub recipient_email: String,
/// endpoint of recipient: email or api url.
pub recipient_endpoint: String,
}

impl VestingEscrowMetadata {
Expand All @@ -27,6 +27,6 @@ impl VestingEscrowMetadata {
+ 4
+ metadata.creator_email.as_bytes().len()
+ 4
+ metadata.recipient_email.as_bytes().len()
+ metadata.recipient_endpoint.as_bytes().len()
}
}
32 changes: 16 additions & 16 deletions tests/locker_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export interface CreateEscrowMetadataParams {
name: string;
description: string;
creatorEmail: string;
recipientEmail: string;
recipientEndpoint: string;
}

export async function createEscrowMetadata(params: CreateEscrowMetadataParams) {
Expand All @@ -251,7 +251,7 @@ export async function createEscrowMetadata(params: CreateEscrowMetadataParams) {
name,
description,
creatorEmail,
recipientEmail,
recipientEndpoint,
creator,
} = params;
const program = createLockerProgram(new Wallet(creator));
Expand All @@ -261,7 +261,7 @@ export async function createEscrowMetadata(params: CreateEscrowMetadataParams) {
name,
description,
creatorEmail,
recipientEmail,
recipientEndpoint,
})
.accounts({
escrow,
Expand All @@ -284,8 +284,8 @@ export async function createEscrowMetadata(params: CreateEscrowMetadataParams) {
expect(escrowMetadataState.creatorEmail.toString()).eq(
creatorEmail.toString()
);
expect(escrowMetadataState.recipientEmail.toString()).eq(
recipientEmail.toString()
expect(escrowMetadataState.recipientEndpoint.toString()).eq(
recipientEndpoint.toString()
);
}
}
Expand All @@ -299,7 +299,7 @@ export async function createEscrowMetadataV3(
name,
description,
creatorEmail,
recipientEmail,
recipientEndpoint,
creator,
} = params;
const program = createLockerProgram(new Wallet(creator));
Expand All @@ -309,7 +309,7 @@ export async function createEscrowMetadataV3(
name,
description,
creatorEmail,
recipientEmail,
recipientEndpoint,
})
.accounts({
escrow,
Expand All @@ -332,8 +332,8 @@ export async function createEscrowMetadataV3(
expect(escrowMetadataState.creatorEmail.toString()).eq(
creatorEmail.toString()
);
expect(escrowMetadataState.recipientEmail.toString()).eq(
recipientEmail.toString()
expect(escrowMetadataState.recipientEndpoint.toString()).eq(
recipientEndpoint.toString()
);
}
}
Expand All @@ -343,18 +343,18 @@ export interface UpdateRecipientParams {
signer: web3.Keypair;
escrow: web3.PublicKey;
newRecipient: web3.PublicKey;
newRecipientEmail: null | string;
newrecipientEndpoint: null | string;
}

export async function updateRecipient(params: UpdateRecipientParams) {
let { isAssertion, escrow, signer, newRecipient, newRecipientEmail } = params;
let { isAssertion, escrow, signer, newRecipient, newrecipientEndpoint } = params;
const program = createLockerProgram(new Wallet(signer));
let escrowMetadata = null;
if (newRecipientEmail != null) {
if (newrecipientEndpoint != null) {
[escrowMetadata] = deriveEscrowMetadata(escrow, program.programId);
}
await program.methods
.updateVestingEscrowRecipient(newRecipient, newRecipientEmail)
.updateVestingEscrowRecipient(newRecipient, newrecipientEndpoint)
.accounts({
escrow,
escrowMetadata,
Expand All @@ -367,12 +367,12 @@ export async function updateRecipient(params: UpdateRecipientParams) {
if (isAssertion) {
const escrowState = await program.account.vestingEscrow.fetch(escrow);
expect(escrowState.recipient.toString()).eq(newRecipient.toString());
if (newRecipientEmail != null) {
if (newrecipientEndpoint != null) {
[escrowMetadata] = deriveEscrowMetadata(escrow, program.programId);
const escrowMetadataState =
await program.account.vestingEscrowMetadata.fetch(escrowMetadata);
expect(escrowMetadataState.recipientEmail.toString()).eq(
newRecipientEmail.toString()
expect(escrowMetadataState.recipientEndpoint.toString()).eq(
newrecipientEndpoint.toString()
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_close_vesting_escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("Close vesting escrow", () => {
name: "Jupiter lock",
description: "This is jupiter lock",
creatorEmail: "[email protected]",
recipientEmail: "[email protected]",
recipientEndpoint: "[email protected]",
creator: UserKP,
isAssertion: true,
});
Expand Down Expand Up @@ -295,7 +295,7 @@ describe("Close vesting escrow", () => {
name: "Jupiter lock",
description: "This is jupiter lock",
creatorEmail: "[email protected]",
recipientEmail: "[email protected]",
recipientEndpoint: "[email protected]",
creator: UserKP,
isAssertion: true,
});
Expand Down
2 changes: 1 addition & 1 deletion tests/test_escrow_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe("Escrow metadata", () => {
name: "Jupiter lock",
description: "This is jupiter lock",
creatorEmail: "[email protected]",
recipientEmail: "[email protected]",
recipientEndpoint: "[email protected]",
creator: UserKP,
isAssertion: true,
});
Expand Down
28 changes: 14 additions & 14 deletions tests/test_update_recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
},
"Not permit to do this action",
Expand All @@ -146,7 +146,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: RecipientKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
},
"Not permit to do this action",
Expand Down Expand Up @@ -184,7 +184,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: RecipientKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
},
"Not permit to do this action",
Expand All @@ -196,7 +196,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
});

Expand Down Expand Up @@ -230,7 +230,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
},
"Not permit to do this action",
Expand All @@ -242,7 +242,7 @@ describe("Update recipient", () => {
newRecipient: newRecipient.publicKey,
isAssertion: true,
signer: RecipientKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
});

Expand Down Expand Up @@ -273,19 +273,19 @@ describe("Update recipient", () => {
newRecipient: RecipientKP.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});

await updateRecipient({
escrow,
newRecipient: RecipientKP.publicKey,
isAssertion: true,
signer: RecipientKP,
newRecipientEmail: null,
newrecipientEndpoint: null,
});
});

it("Update both recipient and recipient email", async () => {
it("Update both recipient and recipient endpoint", async () => {
console.log("Create vesting plan");
const program = createLockerProgram(new anchor.Wallet(UserKP));
let currentBlockTime = await getCurrentBlockTime(
Expand Down Expand Up @@ -313,12 +313,12 @@ describe("Update recipient", () => {
name: "Jupiter lock",
description: "This is jupiter lock",
creatorEmail: "[email protected]",
recipientEmail: "[email protected]",
recipientEndpoint: "[email protected]",
creator: UserKP,
isAssertion: true,
});

it("Update both recipient and recipient email", async () => {
it("Update both recipient and recipient endpoint", async () => {
console.log("Create vesting plan");
const program = createLockerProgram(new anchor.Wallet(UserKP));
let currentBlockTime = await getCurrentBlockTime(
Expand Down Expand Up @@ -346,7 +346,7 @@ describe("Update recipient", () => {
name: "Jupiter lock",
description: "This is jupiter lock",
creatorEmail: "[email protected]",
recipientEmail: "[email protected]",
recipientEndpoint: "[email protected]",
creator: UserKP,
isAssertion: true,
});
Expand All @@ -357,7 +357,7 @@ describe("Update recipient", () => {
newRecipient: RecipientKP.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: "[email protected]",
newrecipientEndpoint: "[email protected]",
});

console.log("Update recipient with smaller email size");
Expand All @@ -366,7 +366,7 @@ describe("Update recipient", () => {
newRecipient: RecipientKP.publicKey,
isAssertion: true,
signer: UserKP,
newRecipientEmail: "[email protected]",
newrecipientEndpoint: "[email protected]",
});
});
});
Expand Down
Loading

0 comments on commit 1e7d01e

Please sign in to comment.