2
2
3
3
use {
4
4
crate :: { error:: RecordError , instruction:: RecordInstruction , state:: RecordData } ,
5
- solana_program:: {
6
- account_info:: { next_account_info, AccountInfo } ,
7
- entrypoint:: ProgramResult ,
8
- msg,
9
- program_error:: ProgramError ,
10
- program_pack:: IsInitialized ,
11
- pubkey:: Pubkey ,
12
- } ,
13
- spl_pod:: bytemuck:: { pod_from_bytes, pod_from_bytes_mut, pod_get_packed_len} ,
5
+ solana_account_info:: { next_account_info, AccountInfo } ,
6
+ solana_msg:: msg,
7
+ solana_program_error:: { ProgramError , ProgramResult } ,
8
+ solana_program_pack:: IsInitialized ,
9
+ solana_pubkey:: Pubkey ,
14
10
} ;
15
11
16
12
fn check_authority ( authority_info : & AccountInfo , expected_authority : & Pubkey ) -> ProgramResult {
@@ -46,9 +42,10 @@ pub fn process_instruction(
46
42
return Err ( ProgramError :: InvalidAccountData ) ;
47
43
}
48
44
49
- let account_data = pod_from_bytes_mut :: < RecordData > (
45
+ let account_data = bytemuck :: try_from_bytes_mut :: < RecordData > (
50
46
& mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
51
- ) ?;
47
+ )
48
+ . map_err ( |_| ProgramError :: InvalidArgument ) ?;
52
49
if account_data. is_initialized ( ) {
53
50
msg ! ( "Record account already initialized" ) ;
54
51
return Err ( ProgramError :: AccountAlreadyInitialized ) ;
@@ -68,8 +65,10 @@ pub fn process_instruction(
68
65
if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
69
66
return Err ( ProgramError :: InvalidAccountData ) ;
70
67
}
71
- let account_data =
72
- pod_from_bytes :: < RecordData > ( & raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ) ?;
68
+ let account_data = bytemuck:: try_from_bytes :: < RecordData > (
69
+ & raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
70
+ )
71
+ . map_err ( |_| ProgramError :: InvalidArgument ) ?;
73
72
if !account_data. is_initialized ( ) {
74
73
msg ! ( "Record account not initialized" ) ;
75
74
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -95,9 +94,10 @@ pub fn process_instruction(
95
94
if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
96
95
return Err ( ProgramError :: InvalidAccountData ) ;
97
96
}
98
- let account_data = pod_from_bytes_mut :: < RecordData > (
97
+ let account_data = bytemuck :: try_from_bytes_mut :: < RecordData > (
99
98
& mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
100
- ) ?;
99
+ )
100
+ . map_err ( |_| ProgramError :: InvalidArgument ) ?;
101
101
if !account_data. is_initialized ( ) {
102
102
msg ! ( "Record account not initialized" ) ;
103
103
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -116,9 +116,10 @@ pub fn process_instruction(
116
116
if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
117
117
return Err ( ProgramError :: InvalidAccountData ) ;
118
118
}
119
- let account_data = pod_from_bytes_mut :: < RecordData > (
119
+ let account_data = bytemuck :: try_from_bytes_mut :: < RecordData > (
120
120
& mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
121
- ) ?;
121
+ )
122
+ . map_err ( |_| ProgramError :: InvalidArgument ) ?;
122
123
if !account_data. is_initialized ( ) {
123
124
msg ! ( "Record not initialized" ) ;
124
125
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -143,9 +144,10 @@ pub fn process_instruction(
143
144
if raw_data. len ( ) < RecordData :: WRITABLE_START_INDEX {
144
145
return Err ( ProgramError :: InvalidAccountData ) ;
145
146
}
146
- let account_data = pod_from_bytes_mut :: < RecordData > (
147
+ let account_data = bytemuck :: try_from_bytes_mut :: < RecordData > (
147
148
& mut raw_data[ ..RecordData :: WRITABLE_START_INDEX ] ,
148
- ) ?;
149
+ )
150
+ . map_err ( |_| ProgramError :: InvalidArgument ) ?;
149
151
if !account_data. is_initialized ( ) {
150
152
msg ! ( "Record not initialized" ) ;
151
153
return Err ( ProgramError :: UninitializedAccount ) ;
@@ -155,7 +157,7 @@ pub fn process_instruction(
155
157
156
158
// needed account length is the sum of the meta data length and the specified
157
159
// data length
158
- let needed_account_length = pod_get_packed_len :: < RecordData > ( )
160
+ let needed_account_length = std :: mem :: size_of :: < RecordData > ( )
159
161
. checked_add (
160
162
usize:: try_from ( data_length) . map_err ( |_| ProgramError :: InvalidArgument ) ?,
161
163
)
0 commit comments