@@ -17,24 +17,28 @@ pub fn process_instruction(
17
17
// Create in iterator to safety reference accounts in the slice
18
18
let account_info_iter = & mut accounts. iter ( ) ;
19
19
20
- // The first account is the clock sysvar
20
+ // Get the clock sysvar via syscall
21
+ let clock_via_sysvar = Clock :: get ( ) ?;
22
+ // Or deserialize the account into a clock struct
21
23
let clock_sysvar_info = next_account_info ( account_info_iter) ?;
22
- // The second account is the rent sysvar
23
- let rent_sysvar_info = next_account_info ( account_info_iter) ?;
24
-
25
- // Deserialize the account into a clock struct
26
- let clock = Clock :: from_account_info ( & clock_sysvar_info) ?;
27
-
28
- // Deserialize the account into a rent struct
29
- let rent = Rent :: from_account_info ( & rent_sysvar_info) ?;
30
-
24
+ let clock_via_account = Clock :: from_account_info ( & clock_sysvar_info) ?;
25
+ // Both produce the same sysvar
26
+ assert_eq ! ( clock_via_sysvar, clock_via_account) ;
31
27
// Note: `format!` can be very expensive, use cautiously
32
- msg ! ( "{:?}" , clock) ;
28
+ msg ! ( "{:?}" , clock_via_sysvar) ;
29
+
30
+ // Get the rent sysvar via syscall
31
+ let rent_via_sysvar = Rent :: get ( ) ?;
32
+ // Or deserialize the account into a rent struct
33
+ let rent_sysvar_info = next_account_info ( account_info_iter) ?;
34
+ let rent_via_account = Rent :: from_account_info ( & rent_sysvar_info) ?;
35
+ // Both produce the same sysvar
36
+ assert_eq ! ( rent_via_sysvar, rent_via_account) ;
33
37
// Can't print `exemption_threshold` because BPF does not support printing floats
34
38
msg ! (
35
39
"Rent: lamports_per_byte_year: {:?}, burn_percent: {:?}" ,
36
- rent . lamports_per_byte_year,
37
- rent . burn_percent
40
+ rent_via_sysvar . lamports_per_byte_year,
41
+ rent_via_sysvar . burn_percent
38
42
) ;
39
43
40
44
Ok ( ( ) )
0 commit comments