|
1 | | -mod c_oracle_header; |
| 1 | +pub mod c_oracle_header; |
| 2 | +mod rust_oracle; |
2 | 3 | mod time_machine_types; |
| 4 | +<<<<<<< HEAD |
3 | 5 | mod error; |
4 | 6 | mod log; |
5 | 7 |
|
6 | 8 | use crate::log::{post_log, pre_log}; |
7 | 9 | use solana_program::entrypoint::deserialize; |
| 10 | +======= |
| 11 | +use borsh::{BorshDeserialize, BorshSerialize}; |
| 12 | +use solana_program::entrypoint::deserialize; |
| 13 | +use solana_program::pubkey::Pubkey; |
| 14 | +use solana_program::sysvar::slot_history::AccountInfo; |
| 15 | + |
| 16 | +>>>>>>> 4656a2b (add a new insctruction and interecepted update price calls) |
8 | 17 |
|
9 | 18 | //Below is a high lever description of the rust/c setup. |
10 | 19 |
|
@@ -45,7 +54,32 @@ pub extern "C" fn entrypoint(input: *mut u8) -> u64 { |
45 | 54 | _ => {} |
46 | 55 | } |
47 | 56 |
|
48 | | - let c_ret_val = unsafe { c_entrypoint(input) }; |
| 57 | + let cmd_hdr_size = ::std::mem::size_of::<c_oracle_header::cmd_hdr>(); |
| 58 | + if instruction_data.len() < cmd_hdr_size { |
| 59 | + panic!("insufficient data, could not parse instruction"); |
| 60 | + } |
| 61 | + |
| 62 | + let cmd_data = c_oracle_header::cmd_hdr::try_from_slice(&instruction_data[..cmd_hdr_size]).unwrap(); |
| 63 | + |
| 64 | + if cmd_data.ver_ != c_oracle_header::PC_VERSION { |
| 65 | + //FIXME: I am not sure what's best to do here (this is copied from C) |
| 66 | + // it seems to me like we should not break when version numbers change |
| 67 | + //instead we should maintain the update logic accross version in the |
| 68 | + //upd_account_version command |
| 69 | + panic!("incorrect version numbers"); |
| 70 | + } |
| 71 | + |
| 72 | + let c_ret_val = match cmd_data.cmd_ as u32 { |
| 73 | + c_oracle_header::command_t_e_cmd_upd_price |
| 74 | + | c_oracle_header::command_t_e_cmd_upd_price_no_fail_on_error |
| 75 | + | c_oracle_header::command_t_e_cmd_agg_price => { |
| 76 | + rust_oracle::update_price(program_id, accounts, instruction_data, input) |
| 77 | + } |
| 78 | + c_oracle_header::command_t_e_cmd_upd_account_version => { |
| 79 | + rust_oracle::update_version(program_id, accounts, instruction_data) |
| 80 | + } |
| 81 | + _ => unsafe { return c_entrypoint(input) }, |
| 82 | + } |
49 | 83 |
|
50 | 84 | match post_log(c_ret_val, &accounts) { |
51 | 85 | Err(error) => return error.into(), |
|
0 commit comments