Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
Smol changes (#17)
Browse files Browse the repository at this point in the history
* add correct length, comments, and data checking

* remove todo
  • Loading branch information
crypt0miester authored Apr 26, 2023
1 parent 7b53a29 commit 99251ab
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions programs/gpl_nameservice/src/nameservice/ans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ pub struct ANSNameRecord {
// If `Pubkey::default()` the data is unspecified.
pub class: Pubkey,

//TODO: Check with ANS team for the right type here.
pub expires_at: u64,
}

impl ANSNameRecord {
pub const LEN: usize = 104;
pub const LEN: usize = 200;
}

pub struct ANSNameService;
Expand All @@ -31,8 +30,9 @@ impl NameServiceParser for ANSNameService {
}

fn unpack(record: &AccountInfo) -> Result<ANSNameRecord> {
// TODO: Check disciminator
let name_record = ANSNameRecord::try_from_slice(&mut &record.data.borrow_mut()[..])?;
// discriminators are unique to programs, since we have validations below.
// unless we hard code the discriminator value we will have to ignore them for now.
let name_record = ANSNameRecord::try_from_slice(&mut &record.data.borrow_mut()[8..])?;
Ok(name_record)
}

Expand All @@ -57,10 +57,16 @@ impl NameServiceParser for ANSNameService {
// Validate the owner
Self::validate_owner(record)?;

if record.data_len() != ANSNameRecord::LEN {
// Data size may be longer than the fixed ans record name.
if ANSNameRecord::LEN >= record.data_len() {
return Err(NameServiceError::InvalidDataLength.into());
}

// Check if the owner of the account is ANS program.
if record.owner.to_string() != Self::id_str() {
return Err(ProgramError::InvalidAccountData.into());
}

let name_record = Self::unpack(record)?;

// The authority should be the same as the owner in the record
Expand Down

0 comments on commit 99251ab

Please sign in to comment.