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 6d3b1af
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
2 changes: 1 addition & 1 deletion token-group/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"

[dependencies]
bytemuck = "1.14.0"
solana-program = "1.16.3"
solana-program = "1.16.16"
spl-discriminator = { version = "0.1.0" , path = "../../libraries/discriminator" }
spl-pod = { version = "0.1.0" , path = "../../libraries/pod", features = ["borsh"] }
spl-program-error = { version = "0.3.0" , path = "../../libraries/program-error" }
Expand Down
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 6d3b1af

Please sign in to comment.