Skip to content

Commit 5014fb4

Browse files
Fix StorageGuard access in get_price_unsafe function
- Replace incorrect .try_read().ok_or() with proper .get() method calls - Add zero-value check for publish_time to determine if price data exists - Contract now compiles successfully without StorageGuard errors Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
1 parent 651b949 commit 5014fb4

File tree

1 file changed

+11
-7
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+11
-7
lines changed

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,19 @@ impl PythReceiver {
3636
pub fn get_price_unsafe(&self, _id: [u8; 32]) -> Result<PriceInfoReturn, PythReceiverError> {
3737
let id_fb = FixedBytes::<32>::from(_id);
3838

39-
let price_info = self.latest_price_info.get(id_fb).unwrap_or(PythReceiverError::PriceUnavailable)?;
39+
let price_info = self.latest_price_info.get(id_fb);
40+
41+
if price_info.publish_time.get() == U64::ZERO {
42+
return Err(PythReceiverError::PriceUnavailable);
43+
}
4044

4145
Ok((
42-
price_info.publish_time,
43-
price_info.expo,
44-
price_info.price,
45-
price_info.conf,
46-
price_info.ema_price,
47-
price_info.ema_conf,
46+
price_info.publish_time.get(),
47+
price_info.expo.get(),
48+
price_info.price.get(),
49+
price_info.conf.get(),
50+
price_info.ema_price.get(),
51+
price_info.ema_conf.get(),
4852
))
4953
}
5054

0 commit comments

Comments
 (0)