Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8cadd69

Browse files
Change max size to u64 in interface
1 parent d0eff43 commit 8cadd69

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

token-group/interface/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For a group:
9595

9696
```rust
9797
type OptionalNonZeroPubkey = Pubkey; // if all zeroes, interpreted as `None`
98-
type PodU32 = [u8; 4];
98+
type PodU64 = [u8; 8];
9999
type Pubkey = [u8; 32];
100100

101101
/// Type discriminant: [214, 15, 63, 132, 49, 119, 209, 40]
@@ -107,9 +107,9 @@ pub struct TokenGroup {
107107
/// belongs to a particular mint
108108
pub mint: Pubkey,
109109
/// The current number of group members
110-
pub size: PodU32,
110+
pub size: PodU64,
111111
/// The maximum number of group members
112-
pub max_size: PodU32,
112+
pub max_size: PodU64,
113113
}
114114
```
115115

@@ -125,7 +125,7 @@ pub struct TokenGroupMember {
125125
/// The pubkey of the `TokenGroup`
126126
pub group: Pubkey,
127127
/// The member number
128-
pub member_number: PodU32,
128+
pub member_number: PodU64,
129129
}
130130
```
131131

token-group/interface/src/instruction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use {
1111
spl_pod::{
1212
bytemuck::{pod_bytes_of, pod_from_bytes},
1313
optional_keys::OptionalNonZeroPubkey,
14-
primitives::PodU32,
14+
primitives::PodU64,
1515
},
1616
};
1717

@@ -23,7 +23,7 @@ pub struct InitializeGroup {
2323
/// Update authority for the group
2424
pub update_authority: OptionalNonZeroPubkey,
2525
/// The maximum number of group members
26-
pub max_size: PodU32,
26+
pub max_size: PodU64,
2727
}
2828

2929
/// Instruction data for updating the max size of a `Group`
@@ -32,7 +32,7 @@ pub struct InitializeGroup {
3232
#[discriminator_hash_input("spl_token_group_interface:update_group_max_size")]
3333
pub struct UpdateGroupMaxSize {
3434
/// New max size for the group
35-
pub max_size: PodU32,
35+
pub max_size: PodU64,
3636
}
3737

3838
/// Instruction data for updating the authority of a `Group`
@@ -155,7 +155,7 @@ pub fn initialize_group(
155155
mint: &Pubkey,
156156
mint_authority: &Pubkey,
157157
update_authority: Option<Pubkey>,
158-
max_size: u32,
158+
max_size: u64,
159159
) -> Instruction {
160160
let update_authority = OptionalNonZeroPubkey::try_from(update_authority)
161161
.expect("Failed to deserialize `Option<Pubkey>`");
@@ -180,7 +180,7 @@ pub fn update_group_max_size(
180180
program_id: &Pubkey,
181181
group: &Pubkey,
182182
update_authority: &Pubkey,
183-
max_size: u32,
183+
max_size: u64,
184184
) -> Instruction {
185185
let data = TokenGroupInstruction::UpdateGroupMaxSize(UpdateGroupMaxSize {
186186
max_size: max_size.into(),

token-group/interface/src/state.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
bytemuck::{Pod, Zeroable},
66
solana_program::{program_error::ProgramError, pubkey::Pubkey},
77
spl_discriminator::SplDiscriminate,
8-
spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU32},
8+
spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU64},
99
};
1010

1111
/// Data struct for a `TokenGroup`
@@ -19,39 +19,39 @@ pub struct TokenGroup {
1919
/// belongs to a particular mint
2020
pub mint: Pubkey,
2121
/// The current number of group members
22-
pub size: PodU32,
22+
pub size: PodU64,
2323
/// The maximum number of group members
24-
pub max_size: PodU32,
24+
pub max_size: PodU64,
2525
}
2626

2727
impl TokenGroup {
2828
/// Creates a new `TokenGroup` state
29-
pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: u32) -> Self {
29+
pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: u64) -> Self {
3030
Self {
3131
mint: *mint,
3232
update_authority,
33-
size: PodU32::default(), // [0, 0, 0, 0]
33+
size: PodU64::default(), // [0, 0, 0, 0, 0, 0, 0, 0]
3434
max_size: max_size.into(),
3535
}
3636
}
3737

3838
/// Updates the max size for a group
39-
pub fn update_max_size(&mut self, new_max_size: u32) -> Result<(), ProgramError> {
39+
pub fn update_max_size(&mut self, new_max_size: u64) -> Result<(), ProgramError> {
4040
// The new max size cannot be less than the current size
41-
if new_max_size < u32::from(self.size) {
41+
if new_max_size < u64::from(self.size) {
4242
return Err(TokenGroupError::SizeExceedsNewMaxSize.into());
4343
}
4444
self.max_size = new_max_size.into();
4545
Ok(())
4646
}
4747

4848
/// Increment the size for a group, returning the new size
49-
pub fn increment_size(&mut self) -> Result<u32, ProgramError> {
49+
pub fn increment_size(&mut self) -> Result<u64, ProgramError> {
5050
// The new size cannot be greater than the max size
51-
let new_size = u32::from(self.size)
51+
let new_size = u64::from(self.size)
5252
.checked_add(1)
5353
.ok_or::<ProgramError>(PodSliceError::CalculationFailure.into())?;
54-
if new_size > u32::from(self.max_size) {
54+
if new_size > u64::from(self.max_size) {
5555
return Err(TokenGroupError::SizeExceedsMaxSize.into());
5656
}
5757
self.size = new_size.into();
@@ -70,11 +70,11 @@ pub struct TokenGroupMember {
7070
/// The pubkey of the `TokenGroup`
7171
pub group: Pubkey,
7272
/// The member number
73-
pub member_number: PodU32,
73+
pub member_number: PodU64,
7474
}
7575
impl TokenGroupMember {
7676
/// Creates a new `TokenGroupMember` state
77-
pub fn new(mint: &Pubkey, group: &Pubkey, member_number: u32) -> Self {
77+
pub fn new(mint: &Pubkey, group: &Pubkey, member_number: u64) -> Self {
7878
Self {
7979
mint: *mint,
8080
group: *group,
@@ -156,7 +156,7 @@ mod tests {
156156

157157
let new_max_size = 30;
158158
group.update_max_size(new_max_size).unwrap();
159-
assert_eq!(u32::from(group.max_size), new_max_size);
159+
assert_eq!(u64::from(group.max_size), new_max_size);
160160

161161
// Change the current size to 30
162162
group.size = 30.into();
@@ -170,7 +170,7 @@ mod tests {
170170

171171
let new_max_size = 30;
172172
group.update_max_size(new_max_size).unwrap();
173-
assert_eq!(u32::from(group.max_size), new_max_size);
173+
assert_eq!(u64::from(group.max_size), new_max_size);
174174
}
175175

176176
#[test]
@@ -183,7 +183,7 @@ mod tests {
183183
};
184184

185185
group.increment_size().unwrap();
186-
assert_eq!(u32::from(group.size), 1);
186+
assert_eq!(u64::from(group.size), 1);
187187

188188
// Try to increase the current size to 2, which is greater than the max size
189189
assert_eq!(

0 commit comments

Comments
 (0)