use solana_instruction::Instruction;
use solana_program_error::ProgramError;
use solana_pubkey::Pubkey;
use super::CreateInstBuilder;
use crate::{TLDomain, derive_domain};
#[derive(Debug)]
pub struct CreateDomainInstBuilder {
payer: Pubkey,
tld: TLDomain,
owner: Option<Pubkey>,
class: Option<Pubkey>,
name: String,
space: Option<u32>,
}
impl CreateDomainInstBuilder {
pub fn new(payer: Pubkey, tld: TLDomain, name: String) -> Self {
Self { payer, tld, owner: None, class: None, name, space: None }
}
pub fn owner(mut self, owner: Option<Pubkey>) -> Self {
self.owner = owner;
self
}
pub fn class(mut self, class: Option<Pubkey>) -> Self {
self.class = class;
self
}
pub fn space(mut self, space: Option<u32>) -> Self {
self.space = space;
self
}
pub fn build(self) -> Result<Instruction, ProgramError> {
let Self { payer, tld: parent, owner, class, name, space } = self;
let account = derive_domain(&parent.pda, class.as_ref(), &name);
let builder =
CreateInstBuilder { payer, account, parent: parent.into(), owner, class, space };
builder.build()
}
}