Skip to content

Commit bacc9f0

Browse files
committed
Pubkey assign
1 parent 81142a1 commit bacc9f0

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

program/rust/src/c_oracle_header.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ unsafe impl Zeroable for cmd_add_price_t {
6363
#[cfg(target_endian = "little")]
6464
unsafe impl Pod for cmd_add_price_t {
6565
}
66+
67+
#[cfg(target_endian = "little")]
68+
unsafe impl Zeroable for pc_pub_key_t {
69+
}
70+
71+
#[cfg(target_endian = "little")]
72+
unsafe impl Pod for pc_pub_key_t {
73+
}

program/rust/src/rust_oracle.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::mem::{
99
};
1010

1111
use bytemuck::{
12+
bytes_of,
1213
try_from_bytes,
1314
try_from_bytes_mut,
1415
Pod,
@@ -27,6 +28,7 @@ use crate::c_oracle_header::{
2728
pc_map_table_t,
2829
pc_price_t,
2930
pc_prod_t,
31+
pc_pub_key_t,
3032
PC_ACCTYPE_MAPPING,
3133
PC_ACCTYPE_PRICE,
3234
PC_ACCTYPE_PRODUCT,
@@ -110,20 +112,15 @@ pub fn add_mapping(
110112
}?;
111113

112114
let hdr = load::<cmd_hdr_t>(instruction_data)?;
113-
let mut cur_mapping = load_mapping_account_mut(cur_mapping, hdr.ver_)?;
115+
let cur_mapping = load_mapping_account_mut(cur_mapping, hdr.ver_)?;
114116
pyth_assert(
115117
cur_mapping.num_ == PC_MAP_TABLE_SIZE
116118
&& unsafe { cur_mapping.next_.k8_.iter().all(|x| *x == 0) },
117119
ProgramError::InvalidArgument,
118120
)?;
119121

120122
initialize_mapping_account(next_mapping, hdr.ver_)?;
121-
unsafe {
122-
cur_mapping
123-
.next_
124-
.k1_
125-
.copy_from_slice(&next_mapping.key.to_bytes());
126-
}
123+
pubkey_assign(cur_mapping.next_, &next_mapping.key.to_bytes());
127124

128125
Ok(SUCCESS)
129126
}
@@ -158,7 +155,7 @@ pub fn add_price(
158155
_ => Err(ProgramError::InvalidArgument),
159156
}?;
160157

161-
let mut product_data = load_product_account_mut(product_account, cmd_args.ver_)?;
158+
let product_data = load_product_account_mut(product_account, cmd_args.ver_)?;
162159

163160
clear_account(price_account)?;
164161

@@ -169,9 +166,9 @@ pub fn add_price(
169166
price_data.size_ = (size_of::<pc_price_t>() - size_of_val(&price_data.comp_)) as u32;
170167
price_data.expo_ = cmd_args.expo_;
171168
price_data.ptype_ = cmd_args.ptype_;
172-
price_data.prod_.k1_ = product_account.key.to_bytes();
173-
price_data.next_ = product_data.px_acc_;
174-
product_data.px_acc_.k1_ = price_account.key.to_bytes();
169+
pubkey_assign(price_data.prod_, &product_account.key.to_bytes());
170+
pubkey_assign(price_data.next_, bytes_of(&product_data.px_acc_));
171+
pubkey_assign(product_data.px_acc_, &price_account.key.to_bytes());
175172

176173
Ok(SUCCESS)
177174
}
@@ -293,3 +290,7 @@ fn load_product_account_mut<'a>(
293290

294291
Ok(product_data)
295292
}
293+
294+
fn pubkey_assign(mut target: pc_pub_key_t, source: &[u8]) {
295+
unsafe { target.k1_.copy_from_slice(source) }
296+
}

0 commit comments

Comments
 (0)