Skip to content

Commit

Permalink
feat: validating time deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Sep 20, 2024
1 parent 0fac451 commit 10ad1c1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,23 @@ impl Processor {
let offset = VestingScheduleHeader::LEN;
let mut total_amount: u64 = 0;

// NOTE: validate time delta to be 0 (unlocked), or a set of predefined values (1 month, 3 months, ...)
let release_time;
if schedule.time_delta == 0 {
release_time = 0;
} else {
let clock = Clock::from_account_info(&accounts[2])?;
// TODO: make test advance in time between initialize and unlock
// release_time = clock.unix_timestamp as u64 + schedule.time_delta; // TODO: uncomment
release_time = schedule.time_delta; // NOTE: For testing purposes, keeping previous behavior
match schedule.time_delta {
0 => {
release_time = 0;
},
1 | 100 | 300 => { // TODO: replace for validated values
// Valid time_delta values, do nothing
let clock = Clock::from_account_info(&accounts[2])?;
// TODO: make test advance in time between initialize and unlock
// release_time = clock.unix_timestamp as u64 + schedule.time_delta; // TODO: uncomment
release_time = schedule.time_delta; // NOTE: For testing purposes, keeping previous behavior
}
_ => {
msg!("Unsupported time delta");
return Err(ProgramError::InvalidInstructionData);
}
}

let state_schedule = VestingSchedule {
Expand Down

0 comments on commit 10ad1c1

Please sign in to comment.