Skip to content

Commit 0132604

Browse files
committed
add a new insctruction and interecepted update price calls
1 parent 2651e81 commit 0132604

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

program/c/src/oracle/oracle.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ typedef enum {
269269
// key[1] price account [writable]
270270
// key[2] sysvar_clock account [readable]
271271
e_cmd_upd_price_no_fail_on_error,
272+
273+
// performs migation logic on the upgraded account. (resizes price accounts)
274+
// key[0] funding account [signer writable]
275+
// key[1] upgraded account [writable]
276+
// key[2] system program [readable]
277+
e_cmd_upd_account_version,
272278
} command_t;
273279

274280
typedef struct cmd_hdr

program/rust/src/lib.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
mod c_oracle_header;
1+
pub mod c_oracle_header;
2+
mod rust_oracle;
23
mod time_machine_types;
4+
<<<<<<< HEAD
35
mod error;
46
mod log;
57

68
use crate::log::{post_log, pre_log};
79
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)
817

918
//Below is a high lever description of the rust/c setup.
1019

@@ -45,7 +54,32 @@ pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
4554
_ => {}
4655
}
4756

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+
}
4983

5084
match post_log(c_ret_val, &accounts) {
5185
Err(error) => return error.into(),

program/rust/src/rust_oracle.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use super::c_entrypoint;
2+
use super::c_oracle_header;
3+
use solana_program::pubkey::Pubkey;
4+
use solana_program::sysvar::slot_history::AccountInfo;
5+
6+
///Calls the c oracle update_price, and updates the Time Machine if needed
7+
pub fn update_price(
8+
program_id: &Pubkey,
9+
accounts: Vec<AccountInfo>,
10+
instruction_data: &[u8],
11+
input: *mut u8,
12+
) -> u64 {
13+
//For now, we did not change the behavior of this. this is just to show the proposed structure of the
14+
//program
15+
let c_ret_val = unsafe { c_entrypoint(input) };
16+
if c_ret_val == c_oracle_header::SUCCESSFULLY_UPDATED_AGGREGATE {
17+
//0 is the SUCCESS value for solana
18+
return 0;
19+
} else {
20+
return c_ret_val;
21+
}
22+
}
23+
/// has version number/ account type dependant logic to make sure the given account is compatible
24+
/// with the current version
25+
/// updates the version number for all accounts, and resizes price accounts
26+
pub fn update_version(
27+
program_id: &Pubkey,
28+
accounts: Vec<AccountInfo>,
29+
instruction_data: &[u8],
30+
) -> u64 {
31+
panic!("Need to merge fix to pythd in order to implement this");
32+
0 //SUCCESS
33+
}

0 commit comments

Comments
 (0)