Skip to content

Commit 24dcf7d

Browse files
committed
more import style changes
1 parent f26918f commit 24dcf7d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

program/rust/src/lib.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
pub mod c_oracle_header;
1+
mod c_oracle_header;
22
mod error;
33
mod log;
44
mod rust_oracle;
55
mod time_machine_types;
66

7-
use ::std::mem::size_of;
7+
use crate::c_oracle_header::{
8+
cmd_hdr, command_t_e_cmd_agg_price, command_t_e_cmd_upd_account_version,
9+
command_t_e_cmd_upd_price, command_t_e_cmd_upd_price_no_fail_on_error, PC_VERSION,
10+
SUCCESSFULLY_UPDATED_AGGREGATE,
11+
};
812
use crate::log::{post_log, pre_log};
13+
use crate::rust_oracle::{update_price, update_version};
14+
use ::std::mem::size_of;
915
use borsh::{BorshDeserialize, BorshSerialize};
10-
use solana_program::entrypoint::deserialize;
16+
use solana_program::{custom_heap_default, custom_panic_default, entrypoint::deserialize};
1117

1218
//Below is a high lever description of the rust/c setup.
1319

@@ -48,29 +54,28 @@ pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
4854
_ => {}
4955
}
5056

51-
let cmd_hdr_size = size_of::<c_oracle_header::cmd_hdr>();
57+
let cmd_hdr_size = size_of::<cmd_hdr>();
5258
if instruction_data.len() < cmd_hdr_size {
5359
panic!("insufficient data, could not parse instruction");
5460
}
5561

56-
let cmd_data =
57-
c_oracle_header::cmd_hdr::try_from_slice(&instruction_data[..cmd_hdr_size]).unwrap();
62+
let cmd_data = cmd_hdr::try_from_slice(&instruction_data[..cmd_hdr_size]).unwrap();
5863

59-
if cmd_data.ver_ != c_oracle_header::PC_VERSION {
64+
if cmd_data.ver_ != PC_VERSION {
6065
//FIXME: I am not sure what's best to do here (this is copied from C)
6166
// it seems to me like we should not break when version numbers change
6267
//instead we should log a message that asks users to call update_version
6368
panic!("incorrect version numbers");
6469
}
6570

6671
let c_ret_val = match cmd_data.cmd_ as u32 {
67-
c_oracle_header::command_t_e_cmd_upd_price
68-
| c_oracle_header::command_t_e_cmd_upd_price_no_fail_on_error
69-
| c_oracle_header::command_t_e_cmd_agg_price => {
70-
rust_oracle::update_price(program_id, &accounts, &instruction_data, input)
72+
command_t_e_cmd_upd_price
73+
| command_t_e_cmd_upd_price_no_fail_on_error
74+
| command_t_e_cmd_agg_price => {
75+
update_price(program_id, &accounts, &instruction_data, input)
7176
}
72-
c_oracle_header::command_t_e_cmd_upd_account_version => {
73-
rust_oracle::update_version(program_id, &accounts, &instruction_data)
77+
command_t_e_cmd_upd_account_version => {
78+
update_version(program_id, &accounts, &instruction_data)
7479
}
7580
_ => unsafe { return c_entrypoint(input) },
7681
};
@@ -80,13 +85,13 @@ pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
8085
_ => {}
8186
}
8287

83-
if c_ret_val == c_oracle_header::SUCCESSFULLY_UPDATED_AGGREGATE {
88+
if c_ret_val == SUCCESSFULLY_UPDATED_AGGREGATE {
8489
//0 is the SUCCESS value for solana
8590
return 0;
8691
} else {
8792
return c_ret_val;
8893
}
8994
}
9095

91-
solana_program::custom_heap_default!();
92-
solana_program::custom_panic_default!();
96+
custom_heap_default!();
97+
custom_panic_default!();

0 commit comments

Comments
 (0)