Skip to content

Commit d2646c5

Browse files
authored
Rust instructions (#266)
* OracleCommand struct * Cleanup entrypoint: * Format * Cleanup * Additional comment * Delete accidental files * Cleanup rust oracle * Explicit instruction order * Fix rust oracle * Tests updated * Restore some functions for CI * Warning added * Restore oracle.h * Fix Pod * Publishing * Fix comments
1 parent 50a0e81 commit d2646c5

18 files changed

+401
-411
lines changed

program/rust/src/c_oracle_header.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ unsafe impl Zeroable for pc_price {
8484
unsafe impl Pod for pc_price {
8585
}
8686

87-
#[cfg(target_endian = "little")]
88-
unsafe impl Zeroable for cmd_hdr {
89-
}
90-
91-
#[cfg(target_endian = "little")]
92-
unsafe impl Pod for cmd_hdr {
93-
}
94-
9587
#[cfg(target_endian = "little")]
9688
unsafe impl Zeroable for pc_price_info {
9789
}
@@ -100,14 +92,6 @@ unsafe impl Zeroable for pc_price_info {
10092
unsafe impl Pod for pc_price_info {
10193
}
10294

103-
#[cfg(target_endian = "little")]
104-
unsafe impl Zeroable for cmd_upd_price {
105-
}
106-
107-
#[cfg(target_endian = "little")]
108-
unsafe impl Pod for cmd_upd_price {
109-
}
110-
11195
#[cfg(target_endian = "little")]
11296
unsafe impl Zeroable for pc_ema {
11397
}
@@ -116,44 +100,6 @@ unsafe impl Zeroable for pc_ema {
116100
unsafe impl Pod for pc_ema {
117101
}
118102

119-
#[cfg(target_endian = "little")]
120-
unsafe impl Zeroable for cmd_add_price_t {
121-
}
122-
123-
#[cfg(target_endian = "little")]
124-
unsafe impl Pod for cmd_add_price_t {
125-
}
126-
127-
#[cfg(target_endian = "little")]
128-
unsafe impl Zeroable for cmd_init_price_t {
129-
}
130-
131-
#[cfg(target_endian = "little")]
132-
unsafe impl Pod for cmd_init_price_t {
133-
}
134-
135-
#[cfg(target_endian = "little")]
136-
unsafe impl Zeroable for cmd_add_publisher_t {
137-
}
138-
139-
#[cfg(target_endian = "little")]
140-
unsafe impl Pod for cmd_add_publisher_t {
141-
}
142-
143-
#[cfg(target_endian = "little")]
144-
unsafe impl Zeroable for cmd_del_publisher_t {
145-
}
146-
147-
#[cfg(target_endian = "little")]
148-
unsafe impl Pod for cmd_del_publisher_t {
149-
}
150-
151-
unsafe impl Zeroable for cmd_set_min_pub_t {
152-
}
153-
154-
#[cfg(target_endian = "little")]
155-
unsafe impl Pod for cmd_set_min_pub_t {
156-
}
157103

158104
#[cfg(target_endian = "little")]
159105
unsafe impl Zeroable for pc_pub_key_t {

program/rust/src/instruction.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::c_oracle_header::PC_VERSION;
1+
use crate::c_oracle_header::{
2+
pc_pub_key_t,
3+
PC_VERSION,
4+
};
25
use crate::deserialize::load;
36
use crate::error::OracleError;
47
use bytemuck::{
@@ -105,3 +108,40 @@ pub fn load_command_header_checked(data: &[u8]) -> Result<OracleCommand, OracleE
105108
}
106109
OracleCommand::from_i32(command_header.command).ok_or(OracleError::UnrecognizedInstruction)
107110
}
111+
112+
#[repr(C)]
113+
#[derive(Zeroable, Pod, Copy, Clone)]
114+
pub struct AddPriceArgs {
115+
pub header: CommandHeader,
116+
pub exponent: i32,
117+
pub price_type: u32,
118+
}
119+
pub type InitPriceArgs = AddPriceArgs;
120+
121+
#[repr(C)]
122+
#[derive(Zeroable, Pod, Copy, Clone)]
123+
pub struct AddPublisherArgs {
124+
pub header: CommandHeader,
125+
pub publisher: pc_pub_key_t,
126+
}
127+
128+
pub type DelPublisherArgs = AddPublisherArgs;
129+
130+
#[repr(C)]
131+
#[derive(Zeroable, Clone, Copy, Pod)]
132+
pub struct SetMinPubArgs {
133+
pub header: CommandHeader,
134+
pub minimum_publishers: u8,
135+
pub unused_: [u8; 3],
136+
}
137+
138+
#[repr(C)]
139+
#[derive(Zeroable, Pod, Copy, Clone)]
140+
pub struct UpdPriceArgs {
141+
pub header: CommandHeader,
142+
pub status: u32,
143+
pub unused_: u32,
144+
pub price: i64,
145+
pub confidence: u64,
146+
pub publishing_slot: u64,
147+
}

0 commit comments

Comments
 (0)