Skip to content
Permalink
Browse files
name-service: allow parent owner to transfer subdomains
  • Loading branch information
dr497 authored and mvines committed Jan 16, 2022
1 parent 00b8a4b commit dd035edda0197e4a9f8fface770628dccfa3a452
Showing 4 changed files with 33 additions and 4 deletions.
@@ -169,7 +169,8 @@ export async function transferNameOwnership(
nameAccountKey,
newOwner,
curentNameOwner,
nameClass
nameClass,
nameParent
);

return transferInstr;
@@ -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()];

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

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

return new TransactionInstruction({
keys,
programId: nameProgramId,
@@ -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.
@@ -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);
}

0 comments on commit dd035ed

Please sign in to comment.