|
1 | | -mod c_oracle_header; |
| 1 | +pub mod c_oracle_header; |
| 2 | +mod rust_oracle; |
2 | 3 | mod time_machine_types; |
| 4 | +use borsh::{BorshDeserialize, BorshSerialize}; |
| 5 | +use solana_program::entrypoint::deserialize; |
| 6 | +use solana_program::pubkey::Pubkey; |
| 7 | +use solana_program::sysvar::slot_history::AccountInfo; |
| 8 | + |
3 | 9 |
|
4 | 10 | //Below is a high lever description of the rust/c setup. |
5 | 11 |
|
@@ -33,11 +39,31 @@ pub extern "C" fn c_entrypoint(input: *mut u8) -> u64 { |
33 | 39 |
|
34 | 40 | #[no_mangle] |
35 | 41 | pub extern "C" fn entrypoint(input: *mut u8) -> u64 { |
36 | | - let c_ret_val = unsafe { c_entrypoint(input) }; |
37 | | - if c_ret_val == c_oracle_header::SUCCESSFULLY_UPDATED_AGGREGATE { |
38 | | - //0 is the SUCCESS value for solana |
39 | | - return 0; |
40 | | - } else { |
41 | | - return c_ret_val; |
| 42 | + let (program_id, accounts, instruction_data) = unsafe { deserialize(input) }; |
| 43 | + let cmd_hdr_size = ::std::mem::size_of::<c_oracle_header::cmd_hdr>(); |
| 44 | + if instruction_data.len() < cmd_hdr_size { |
| 45 | + panic!("insufficient data, could not parse instruction"); |
| 46 | + } |
| 47 | + |
| 48 | + let cmd_data = c_oracle_header::cmd_hdr::try_from_slice(&instruction_data[..cmd_hdr_size]).unwrap(); |
| 49 | + |
| 50 | + if cmd_data.ver_ != c_oracle_header::PC_VERSION { |
| 51 | + //FIXME: I am not sure what's best to do here (this is copied from C) |
| 52 | + // it seems to me like we should not break when version numbers change |
| 53 | + //instead we should maintain the update logic accross version in the |
| 54 | + //upd_account_version command |
| 55 | + panic!("incorrect version numbers"); |
| 56 | + } |
| 57 | + |
| 58 | + match cmd_data.cmd_ as u32 { |
| 59 | + c_oracle_header::command_t_e_cmd_upd_price |
| 60 | + | c_oracle_header::command_t_e_cmd_upd_price_no_fail_on_error |
| 61 | + | c_oracle_header::command_t_e_cmd_agg_price => { |
| 62 | + rust_oracle::update_price(program_id, accounts, instruction_data, input) |
| 63 | + } |
| 64 | + c_oracle_header::command_t_e_cmd_upd_account_version => { |
| 65 | + rust_oracle::update_version(program_id, accounts, instruction_data) |
| 66 | + } |
| 67 | + _ => unsafe { return c_entrypoint(input) }, |
42 | 68 | } |
43 | 69 | } |
0 commit comments