Skip to content

Commit

Permalink
reworked init member instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 13, 2023
1 parent 67e2b1e commit 1cd80d0
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions token-group/interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,7 @@ pub struct UpdateGroupAuthority {
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, SplDiscriminate)]
#[discriminator_hash_input("spl_token_group_interface:initialize_member")]
pub struct InitializeMember {
/// The pubkey of the `Group`
pub group: Pubkey,
/// The member number
pub member_number: u32,
}
pub struct InitializeMember;

/// All instructions that must be implemented in the SPL Token Group Interface
#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -93,10 +88,8 @@ pub enum TokenGroupInterfaceInstruction {
/// Accounts expected by this instruction:
///
/// 0. `[w]` Member
/// 1. `[]` Member Mint
/// 2. `[w]` Group
/// 3. `[]` Group Mint
/// 4. `[s]` Group Mint authority
/// 1. `[w]` Group
/// 2. `[s]` Group update authority
InitializeMember(InitializeMember),
}
impl TokenGroupInterfaceInstruction {
Expand Down Expand Up @@ -230,28 +223,15 @@ pub fn update_group_authority(
pub fn initialize_member(
program_id: &Pubkey,
group: &Pubkey,
group_mint: &Pubkey,
group_mint_authority: &Pubkey,
group_update_authority: &Pubkey,
member: &Pubkey,
member_mint: &Pubkey,
member_mint_authority: &Pubkey,
member_number: u32,
extra_account_metas: &[AccountMeta],
) -> Instruction {
let data = TokenGroupInterfaceInstruction::InitializeMember(InitializeMember {
group: *group,
member_number,
})
.pack();
let mut accounts = vec![
let data = TokenGroupInterfaceInstruction::InitializeMember(InitializeMember {}).pack();
let accounts = vec![
AccountMeta::new(*member, false),
AccountMeta::new_readonly(*member_mint, false),
AccountMeta::new_readonly(*member_mint_authority, true),
AccountMeta::new(*group, false),
AccountMeta::new_readonly(*group_mint, false),
AccountMeta::new_readonly(*group_mint_authority, true),
AccountMeta::new_readonly(*group_update_authority, true),
];
accounts.extend_from_slice(extra_account_metas);

Instruction {
program_id: *program_id,
Expand Down Expand Up @@ -319,10 +299,7 @@ mod test {

#[test]
fn initialize_member_pack() {
let data = InitializeMember {
group: Pubkey::new_unique(),
member_number: 100,
};
let data = InitializeMember {};
let instruction = TokenGroupInterfaceInstruction::InitializeMember(data);
let preimage = hash::hashv(&[format!("{NAMESPACE}:initialize_member").as_bytes()]);
let discriminator = &preimage.as_ref()[..ArrayDiscriminator::LENGTH];
Expand Down

0 comments on commit 1cd80d0

Please sign in to comment.