@@ -56,19 +56,22 @@ pub fn check_valid_funding_account(account: &AccountInfo) -> Result<(), ProgramE
56
56
)
57
57
}
58
58
59
- pub fn valid_signable_account ( program_id : & Pubkey , account : & AccountInfo ) -> bool {
60
- account. is_signer
59
+ pub fn valid_signable_account (
60
+ program_id : & Pubkey ,
61
+ account : & AccountInfo ,
62
+ ) -> Result < bool , ProgramError > {
63
+ Ok ( account. is_signer
61
64
&& account. is_writable
62
65
&& account. owner == program_id
63
- && Rent :: default ( ) . is_exempt ( account. lamports ( ) , account. data_len ( ) )
66
+ && get_rent ( ) ? . is_exempt ( account. lamports ( ) , account. data_len ( ) ) )
64
67
}
65
68
66
69
pub fn check_valid_signable_account (
67
70
program_id : & Pubkey ,
68
71
account : & AccountInfo ,
69
72
) -> Result < ( ) , ProgramError > {
70
73
pyth_assert (
71
- valid_signable_account ( program_id, account) ,
74
+ valid_signable_account ( program_id, account) ? ,
72
75
OracleError :: InvalidSignableAccount . into ( ) ,
73
76
)
74
77
}
@@ -119,18 +122,21 @@ pub fn read_pc_str_t(source: &[u8]) -> Result<&[u8], ProgramError> {
119
122
}
120
123
}
121
124
122
- fn valid_writable_account ( program_id : & Pubkey , account : & AccountInfo ) -> bool {
123
- account. is_writable
125
+ fn valid_writable_account (
126
+ program_id : & Pubkey ,
127
+ account : & AccountInfo ,
128
+ ) -> Result < bool , ProgramError > {
129
+ Ok ( account. is_writable
124
130
&& account. owner == program_id
125
- && Rent :: default ( ) . is_exempt ( account. lamports ( ) , account. data_len ( ) )
131
+ && get_rent ( ) ? . is_exempt ( account. lamports ( ) , account. data_len ( ) ) )
126
132
}
127
133
128
134
pub fn check_valid_writable_account (
129
135
program_id : & Pubkey ,
130
136
account : & AccountInfo ,
131
137
) -> Result < ( ) , ProgramError > {
132
138
pyth_assert (
133
- valid_writable_account ( program_id, account) ,
139
+ valid_writable_account ( program_id, account) ? ,
134
140
OracleError :: InvalidWritableAccount . into ( ) ,
135
141
)
136
142
}
@@ -244,3 +250,14 @@ pub fn assign_owner<'a>(
244
250
) ?;
245
251
Ok ( ( ) )
246
252
}
253
+
254
+ #[ cfg( not( test) ) ]
255
+ pub fn get_rent ( ) -> Result < Rent , ProgramError > {
256
+ use solana_program:: sysvar:: Sysvar ;
257
+ Rent :: get ( )
258
+ }
259
+
260
+ #[ cfg( test) ]
261
+ pub fn get_rent ( ) -> Result < Rent , ProgramError > {
262
+ Ok ( Rent :: default ( ) )
263
+ }
0 commit comments