use borsh::{BorshDeserialize, BorshSerialize};
#[cfg(feature = "serde-feature")]
use serde::{Deserialize, Serialize};
use solana_program::instruction::{AccountMeta, Instruction};
use super::{InstructionBuilder, MetadataInstruction};
use crate::processor::AuthorizationData;
#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
pub enum LockArgs {
V1 {
authorization_data: Option<AuthorizationData>,
},
}
#[repr(C)]
#[cfg_attr(feature = "serde-feature", derive(Serialize, Deserialize))]
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
pub enum UnlockArgs {
V1 {
authorization_data: Option<AuthorizationData>,
},
}
impl InstructionBuilder for super::builders::Lock {
fn instruction(&self) -> solana_program::instruction::Instruction {
let mut accounts = vec![
AccountMeta::new_readonly(self.authority, true),
AccountMeta::new_readonly(self.token_owner.unwrap_or(crate::ID), false),
AccountMeta::new(self.token, false),
AccountMeta::new_readonly(self.mint, false),
AccountMeta::new(self.metadata, false),
AccountMeta::new_readonly(self.edition.unwrap_or(crate::ID), false),
if let Some(token_record) = self.token_record {
AccountMeta::new(token_record, false)
} else {
AccountMeta::new_readonly(crate::ID, false)
},
AccountMeta::new(self.payer, true),
AccountMeta::new_readonly(self.system_program, false),
AccountMeta::new_readonly(self.sysvar_instructions, false),
AccountMeta::new_readonly(self.spl_token_program.unwrap_or(crate::ID), false),
];
if let Some(rules) = &self.authorization_rules {
accounts.push(AccountMeta::new_readonly(mpl_token_auth_rules::ID, false));
accounts.push(AccountMeta::new_readonly(*rules, false));
} else {
accounts.push(AccountMeta::new_readonly(crate::ID, false));
accounts.push(AccountMeta::new_readonly(crate::ID, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: MetadataInstruction::Lock(self.args.clone())
.try_to_vec()
.unwrap(),
}
}
}
impl InstructionBuilder for super::builders::Unlock {
fn instruction(&self) -> solana_program::instruction::Instruction {
let mut accounts = vec![
AccountMeta::new_readonly(self.authority, true),
AccountMeta::new_readonly(self.token_owner.unwrap_or(crate::ID), false),
AccountMeta::new(self.token, false),
AccountMeta::new_readonly(self.mint, false),
AccountMeta::new(self.metadata, false),
AccountMeta::new_readonly(self.edition.unwrap_or(crate::ID), false),
if let Some(token_record) = self.token_record {
AccountMeta::new(token_record, false)
} else {
AccountMeta::new_readonly(crate::ID, false)
},
AccountMeta::new(self.payer, true),
AccountMeta::new_readonly(self.system_program, false),
AccountMeta::new_readonly(self.sysvar_instructions, false),
AccountMeta::new_readonly(self.spl_token_program.unwrap_or(crate::ID), false),
];
if let Some(rules) = &self.authorization_rules {
accounts.push(AccountMeta::new_readonly(mpl_token_auth_rules::ID, false));
accounts.push(AccountMeta::new_readonly(*rules, false));
} else {
accounts.push(AccountMeta::new_readonly(crate::ID, false));
accounts.push(AccountMeta::new_readonly(crate::ID, false));
}
Instruction {
program_id: crate::ID,
accounts,
data: MetadataInstruction::Unlock(self.args.clone())
.try_to_vec()
.unwrap(),
}
}
}