Skip to content

Commit

Permalink
bump instruction discriminators
Browse files Browse the repository at this point in the history
  • Loading branch information
buffalojoec committed Oct 17, 2023
1 parent df16485 commit 3185a0e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
43 changes: 20 additions & 23 deletions token-group/interface/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use {
/// Instruction data for initializing a new `Group`
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, SplDiscriminate)]
#[discriminator_hash_input("spl_token_group_interface:initialize_group")]
#[discriminator_hash_input("spl_token_group_interface:initialize_token_group")]
pub struct InitializeGroup {
/// Update authority for the group
pub update_authority: OptionalNonZeroPubkey,
Expand All @@ -38,7 +38,7 @@ pub struct UpdateGroupMaxSize {
/// Instruction data for updating the authority of a `Group`
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, SplDiscriminate)]
#[discriminator_hash_input("spl_token_group_interface:update_group_authority")]
#[discriminator_hash_input("spl_token_group_interface:update_authority")]
pub struct UpdateGroupAuthority {
/// New authority for the group, or unset if `None`
pub new_authority: OptionalNonZeroPubkey,
Expand Down Expand Up @@ -89,7 +89,8 @@ pub enum TokenGroupInterfaceInstruction {
/// Accounts expected by this instruction:
///
/// 0. `[w]` Member
/// 1. `[s]` Member update authority
/// 1. `[]` Member mint
/// 1. `[s]` Member mint authority
/// 2. `[w]` Group
/// 3. `[s]` Group update authority
InitializeMember(InitializeMember),
Expand Down Expand Up @@ -155,7 +156,6 @@ pub fn initialize_group(
mint_authority: &Pubkey,
update_authority: Option<Pubkey>,
max_size: u32,
extra_account_metas: &[AccountMeta],
) -> Instruction {
let update_authority = OptionalNonZeroPubkey::try_from(update_authority)
.expect("Failed to deserialize `Option<Pubkey>`");
Expand All @@ -164,16 +164,13 @@ pub fn initialize_group(
max_size: max_size.into(),
})
.pack();
let mut accounts = vec![
AccountMeta::new(*group, false),
AccountMeta::new_readonly(*mint, false),
AccountMeta::new_readonly(*mint_authority, true),
];
accounts.extend_from_slice(extra_account_metas);

Instruction {
program_id: *program_id,
accounts,
accounts: vec![
AccountMeta::new(*group, false),
AccountMeta::new_readonly(*mint, false),
AccountMeta::new_readonly(*mint_authority, true),
],
data,
}
}
Expand Down Expand Up @@ -227,21 +224,21 @@ pub fn update_group_authority(
pub fn initialize_member(
program_id: &Pubkey,
member: &Pubkey,
member_update_authority: &Pubkey,
member_mint: &Pubkey,
member_mint_authority: &Pubkey,
group: &Pubkey,
group_update_authority: &Pubkey,
) -> Instruction {
let data = TokenGroupInterfaceInstruction::InitializeMember(InitializeMember {}).pack();
let accounts = vec![
AccountMeta::new(*member, false),
AccountMeta::new_readonly(*member_update_authority, true),
AccountMeta::new(*group, false),
AccountMeta::new_readonly(*group_update_authority, true),
];

Instruction {
program_id: *program_id,
accounts,
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_update_authority, true),
],
data,
}
}
Expand Down Expand Up @@ -278,7 +275,7 @@ mod test {
max_size: 100.into(),
};
let instruction = TokenGroupInterfaceInstruction::InitializeGroup(data);
let preimage = hash::hashv(&[format!("{NAMESPACE}:initialize_group").as_bytes()]);
let preimage = hash::hashv(&[format!("{NAMESPACE}:initialize_token_group").as_bytes()]);
let discriminator = &preimage.as_ref()[..ArrayDiscriminator::LENGTH];
instruction_pack_unpack::<InitializeGroup>(instruction, discriminator, data);
}
Expand All @@ -300,7 +297,7 @@ mod test {
new_authority: OptionalNonZeroPubkey::default(),
};
let instruction = TokenGroupInterfaceInstruction::UpdateGroupAuthority(data);
let preimage = hash::hashv(&[format!("{NAMESPACE}:update_group_authority").as_bytes()]);
let preimage = hash::hashv(&[format!("{NAMESPACE}:update_authority").as_bytes()]);
let discriminator = &preimage.as_ref()[..ArrayDiscriminator::LENGTH];
instruction_pack_unpack::<UpdateGroupAuthority>(instruction, discriminator, data);
}
Expand Down
6 changes: 3 additions & 3 deletions token-group/interface/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ pub struct Member {
/// The pubkey of the `Group`
pub group: Pubkey,
/// The member number
pub member_number: u32,
pub member_number: PodU32,
}
impl Member {
/// Creates a new `Member` state
pub fn new(group: Pubkey, member_number: u32) -> Self {
Self {
group,
member_number,
member_number: member_number.into(),
}
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ mod tests {

let member = Member {
group: Pubkey::new_unique(),
member_number: 0,
member_number: 0.into(),
};

let account_size = TlvStateBorrowed::get_base_len()
Expand Down

0 comments on commit 3185a0e

Please sign in to comment.