From b711639c4160abd21156ad83a78333302fed641f Mon Sep 17 00:00:00 2001 From: Luvkush_Sharma <121566305+LuvkushSharma@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:07:36 +0530 Subject: [PATCH] Update state.rs Changed U32 to U64. --- token-group/interface/src/state.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/token-group/interface/src/state.rs b/token-group/interface/src/state.rs index 9f73ecc442b..81c684f6526 100644 --- a/token-group/interface/src/state.rs +++ b/token-group/interface/src/state.rs @@ -5,7 +5,7 @@ use { bytemuck::{Pod, Zeroable}, solana_program::{program_error::ProgramError, pubkey::Pubkey}, spl_discriminator::SplDiscriminate, - spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU32}, + spl_pod::{error::PodSliceError, optional_keys::OptionalNonZeroPubkey, primitives::PodU64}, }; /// Data struct for a `TokenGroup` @@ -19,26 +19,26 @@ pub struct TokenGroup { /// belongs to a particular mint pub mint: Pubkey, /// The current number of group members - pub size: PodU32, + pub size: PodU64, /// The maximum number of group members - pub max_size: PodU32, + pub max_size: PodU64, } impl TokenGroup { /// Creates a new `TokenGroup` state - pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: u32) -> Self { + pub fn new(mint: &Pubkey, update_authority: OptionalNonZeroPubkey, max_size: U64) -> Self { Self { mint: *mint, update_authority, - size: PodU32::default(), // [0, 0, 0, 0] + size: PodU64::default(), // [0, 0, 0, 0] max_size: max_size.into(), } } /// Updates the max size for a group - pub fn update_max_size(&mut self, new_max_size: u32) -> Result<(), ProgramError> { + pub fn update_max_size(&mut self, new_max_size: U64) -> Result<(), ProgramError> { // The new max size cannot be less than the current size - if new_max_size < u32::from(self.size) { + if new_max_size < U64::from(self.size) { return Err(TokenGroupError::SizeExceedsNewMaxSize.into()); } self.max_size = new_max_size.into(); @@ -46,12 +46,12 @@ impl TokenGroup { } /// Increment the size for a group, returning the new size - pub fn increment_size(&mut self) -> Result { + pub fn increment_size(&mut self) -> Result { // The new size cannot be greater than the max size - let new_size = u32::from(self.size) + let new_size = U64::from(self.size) .checked_add(1) .ok_or::(PodSliceError::CalculationFailure.into())?; - if new_size > u32::from(self.max_size) { + if new_size > U64::from(self.max_size) { return Err(TokenGroupError::SizeExceedsMaxSize.into()); } self.size = new_size.into(); @@ -70,11 +70,11 @@ pub struct TokenGroupMember { /// The pubkey of the `TokenGroup` pub group: Pubkey, /// The member number - pub member_number: PodU32, + pub member_number: PodU64, } impl TokenGroupMember { /// Creates a new `TokenGroupMember` state - pub fn new(mint: &Pubkey, group: &Pubkey, member_number: u32) -> Self { + pub fn new(mint: &Pubkey, group: &Pubkey, member_number: U64) -> Self { Self { mint: *mint, group: *group, @@ -156,7 +156,7 @@ mod tests { let new_max_size = 30; group.update_max_size(new_max_size).unwrap(); - assert_eq!(u32::from(group.max_size), new_max_size); + assert_eq!(U64::from(group.max_size), new_max_size); // Change the current size to 30 group.size = 30.into(); @@ -170,7 +170,7 @@ mod tests { let new_max_size = 30; group.update_max_size(new_max_size).unwrap(); - assert_eq!(u32::from(group.max_size), new_max_size); + assert_eq!(U64::from(group.max_size), new_max_size); } #[test] @@ -183,7 +183,7 @@ mod tests { }; group.increment_size().unwrap(); - assert_eq!(u32::from(group.size), 1); + assert_eq!(U64::from(group.size), 1); // Try to increase the current size to 2, which is greater than the max size assert_eq!(