@@ -30,8 +30,8 @@ pub enum TokenInstruction {
30
30
InitializeMint {
31
31
/// Number of base 10 digits to the right of the decimal place.
32
32
decimals : u8 ,
33
- /// The authority/multisignature to mint tokens. If present, further minting is supported.
34
- mint_authority : COption < Pubkey > ,
33
+ /// The authority/multisignature to mint tokens.
34
+ mint_authority : Pubkey ,
35
35
/// The freeze authority/multisignature of the mint.
36
36
freeze_authority : COption < Pubkey > ,
37
37
} ,
@@ -226,7 +226,7 @@ impl TokenInstruction {
226
226
}
227
227
Ok ( match input[ 0 ] {
228
228
0 => {
229
- if input. len ( ) < size_of :: < u8 > ( ) + size_of :: < u8 > ( ) + size_of :: < bool > ( ) {
229
+ if input. len ( ) < size_of :: < u8 > ( ) + size_of :: < Pubkey > ( ) + size_of :: < bool > ( ) {
230
230
return Err ( TokenError :: InvalidInstruction . into ( ) ) ;
231
231
}
232
232
let mut input_len = 0 ;
@@ -235,11 +235,9 @@ impl TokenInstruction {
235
235
let decimals = unsafe { * ( & input[ input_len] as * const u8 ) } ;
236
236
input_len += size_of :: < u8 > ( ) ;
237
237
238
- let mint_authority = COption :: unpack_or (
239
- input,
240
- & mut input_len,
241
- Into :: < ProgramError > :: into ( TokenError :: InvalidInstruction ) ,
242
- ) ?;
238
+ let mint_authority = unsafe { * ( & input[ input_len] as * const u8 as * const Pubkey ) } ;
239
+ input_len += size_of :: < Pubkey > ( ) ;
240
+
243
241
let freeze_authority = COption :: unpack_or (
244
242
input,
245
243
& mut input_len,
@@ -338,7 +336,11 @@ impl TokenInstruction {
338
336
* value = * decimals;
339
337
output_len += size_of :: < u8 > ( ) ;
340
338
341
- mint_authority. pack ( & mut output, & mut output_len) ;
339
+ #[ allow( clippy:: cast_ptr_alignment) ]
340
+ let value = unsafe { & mut * ( & mut output[ output_len] as * mut u8 as * mut Pubkey ) } ;
341
+ * value = * mint_authority;
342
+ output_len += size_of :: < Pubkey > ( ) ;
343
+
342
344
freeze_authority. pack ( & mut output, & mut output_len) ;
343
345
}
344
346
Self :: InitializeAccount => {
@@ -468,10 +470,9 @@ pub fn initialize_mint(
468
470
freeze_authority_pubkey : Option < & Pubkey > ,
469
471
decimals : u8 ,
470
472
) -> Result < Instruction , ProgramError > {
471
- let mint_authority = COption :: Some ( * mint_authority_pubkey) ;
472
473
let freeze_authority = freeze_authority_pubkey. cloned ( ) . into ( ) ;
473
474
let data = TokenInstruction :: InitializeMint {
474
- mint_authority,
475
+ mint_authority : * mint_authority_pubkey ,
475
476
freeze_authority,
476
477
decimals,
477
478
}
@@ -806,23 +807,24 @@ mod test {
806
807
fn test_instruction_packing ( ) {
807
808
let check = TokenInstruction :: InitializeMint {
808
809
decimals : 2 ,
809
- mint_authority : COption :: None ,
810
+ mint_authority : Pubkey :: new ( & [ 1u8 ; 32 ] ) ,
810
811
freeze_authority : COption :: None ,
811
812
} ;
812
813
let packed = check. pack ( ) . unwrap ( ) ;
813
- let expect = Vec :: from ( [ 0u8 , 2 , 0 , 0 ] ) ;
814
+ let mut expect = Vec :: from ( [ 0u8 , 2 ] ) ;
815
+ expect. extend_from_slice ( & [ 1u8 ; 32 ] ) ;
816
+ expect. extend_from_slice ( & [ 0 ] ) ;
814
817
assert_eq ! ( packed, expect) ;
815
818
let unpacked = TokenInstruction :: unpack ( & expect) . unwrap ( ) ;
816
819
assert_eq ! ( unpacked, check) ;
817
820
818
821
let check = TokenInstruction :: InitializeMint {
819
822
decimals : 2 ,
820
- mint_authority : COption :: Some ( Pubkey :: new ( & [ 2u8 ; 32 ] ) ) ,
823
+ mint_authority : Pubkey :: new ( & [ 2u8 ; 32 ] ) ,
821
824
freeze_authority : COption :: Some ( Pubkey :: new ( & [ 3u8 ; 32 ] ) ) ,
822
825
} ;
823
826
let packed = check. pack ( ) . unwrap ( ) ;
824
827
let mut expect = vec ! [ 0u8 , 2 ] ;
825
- expect. extend_from_slice ( & [ 1 ] ) ;
826
828
expect. extend_from_slice ( & [ 2u8 ; 32 ] ) ;
827
829
expect. extend_from_slice ( & [ 1 ] ) ;
828
830
expect. extend_from_slice ( & [ 3u8 ; 32 ] ) ;
0 commit comments