@@ -7,6 +7,7 @@ use crate::{utils::pdas::seeds, ScopeError};
7
7
pub enum UpdateTokenMetadataMode {
8
8
Name = 0 ,
9
9
MaxPriceAgeSlots = 1 ,
10
+ GroupIds = 2 ,
10
11
}
11
12
12
13
impl UpdateTokenMetadataMode {
@@ -18,6 +19,7 @@ impl UpdateTokenMetadataMode {
18
19
match self {
19
20
UpdateTokenMetadataMode :: Name => 0 ,
20
21
UpdateTokenMetadataMode :: MaxPriceAgeSlots => 1 ,
22
+ UpdateTokenMetadataMode :: GroupIds => 2 ,
21
23
}
22
24
}
23
25
}
@@ -70,7 +72,33 @@ pub fn process(
70
72
let str_name = std:: str:: from_utf8 ( & token_metadata. name ) . unwrap ( ) ;
71
73
msg ! ( "Setting token name for index {} to {}" , index, str_name) ;
72
74
}
75
+ UpdateTokenMetadataMode :: GroupIds => {
76
+ let value = u64:: from_le_bytes ( value[ ..8 ] . try_into ( ) . unwrap ( ) ) ;
77
+ msg ! (
78
+ "Setting token group IDs for index {} to: raw {} == binary {:#b} == positions {:?}" ,
79
+ index,
80
+ value,
81
+ value,
82
+ list_set_bit_positions( value) ,
83
+ ) ;
84
+ token_metadata. group_ids_bitset = value;
85
+ }
73
86
}
74
87
75
88
Ok ( ( ) )
76
89
}
90
+
91
+ /// Lists the bit positions (where LSB == 0) of all the set bits (i.e. `1`s) in the given number's
92
+ /// binary representation.
93
+ /// NOTE: This is a non-critical helper used only for logging of the update operation; should *not*
94
+ /// be needed by business logic. The implementation is a compressed version of a crate
95
+ /// https://docs.rs/bit-iter/1.2.0/src/bit_iter/lib.rs.html.
96
+ fn list_set_bit_positions ( mut bits : u64 ) -> Vec < u8 > {
97
+ let mut positions = Vec :: with_capacity ( usize:: try_from ( bits. count_ones ( ) ) . unwrap ( ) ) ;
98
+ while bits != 0 {
99
+ let position = u8:: try_from ( bits. trailing_zeros ( ) ) . unwrap ( ) ;
100
+ positions. push ( position) ;
101
+ bits &= bits. wrapping_sub ( 1 ) ;
102
+ }
103
+ positions
104
+ }
0 commit comments