Skip to content

Commit

Permalink
name-service: allow parent owner to transfer subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 authored and mvines committed Jan 16, 2022
1 parent 00b8a4b commit dd035ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion name-service/js/src/bindings.ts
Expand Up @@ -169,7 +169,8 @@ export async function transferNameOwnership(
nameAccountKey,
newOwner,
curentNameOwner,
nameClass
nameClass,
nameParent
);

return transferInstr;
Expand Down
11 changes: 10 additions & 1 deletion name-service/js/src/instructions.ts
Expand Up @@ -138,7 +138,8 @@ export function transferInstruction(
nameAccountKey: PublicKey,
newOwnerKey: PublicKey,
currentNameOwnerKey: PublicKey,
nameClassKey?: PublicKey
nameClassKey?: PublicKey,
nameParent?:PublicKey
): TransactionInstruction {
const buffers = [Buffer.from(Int8Array.from([2])), newOwnerKey.toBuffer()];

Expand All @@ -165,6 +166,14 @@ export function transferInstruction(
});
}

if(nameParent){
keys.push({
pubkey: nameParent,
isSigner: false,
isWritable: false,
});
}

return new TransactionInstruction({
keys,
programId: nameProgramId,
Expand Down
7 changes: 6 additions & 1 deletion name-service/program/src/instruction.rs
Expand Up @@ -70,8 +70,13 @@ pub enum NameRegistryInstruction {
/// * If account class is not `Pubkey::default()`:
/// 0. `[writeable]` Name record to be transferred
/// 1. `[signer]` Account owner
/// 1. `[signer]` Account class
/// 2. `[signer]` Account class
///
/// * If the signer is the parent name account owner
/// 0. `[writeable]` Name record to be transferred
/// 1. `[signer]` Account owner
/// 2. `[signer]` Account class
/// 3. `[]` Parent name record
Transfer { new_owner: Pubkey },

/// Delete a name record.
Expand Down
16 changes: 15 additions & 1 deletion name-service/program/src/processor.rs
Expand Up @@ -169,12 +169,26 @@ impl Processor {
let name_account = next_account_info(accounts_iter)?;
let name_owner = next_account_info(accounts_iter)?;
let name_class_opt = next_account_info(accounts_iter).ok();
let parent_name = next_account_info(accounts_iter).ok();

let mut name_record_header =
NameRecordHeader::unpack_from_slice(&name_account.data.borrow())?;

// Verifications
if !name_owner.is_signer || name_record_header.owner != *name_owner.key {
let is_parent_owner = if let Some(parent_name) = parent_name {
if name_record_header.parent_name != *parent_name.key {
msg!("Invalid parent name account");
return Err(ProgramError::InvalidArgument);
}
let parent_name_record_header =
NameRecordHeader::unpack_from_slice(&parent_name.data.borrow())?;
parent_name_record_header.owner == *name_owner.key
} else {
false
};
if !name_owner.is_signer
|| (name_record_header.owner != *name_owner.key && !is_parent_owner)
{
msg!("The given name owner is incorrect or not a signer.");
return Err(ProgramError::InvalidArgument);
}
Expand Down

0 comments on commit dd035ed

Please sign in to comment.