Bläddra i källkod

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>
Devin AI 5 månader sedan
förälder
incheckning
5014fb40eb
1 ändrade filer med 11 tillägg och 7 borttagningar
  1. 11 7
      target_chains/stylus/contracts/pyth-receiver/src/lib.rs

+ 11 - 7
target_chains/stylus/contracts/pyth-receiver/src/lib.rs

@@ -36,15 +36,19 @@ impl PythReceiver {
     pub fn get_price_unsafe(&self, _id: [u8; 32]) -> Result<PriceInfoReturn, PythReceiverError> {
         let id_fb = FixedBytes::<32>::from(_id);
         
-        let price_info = self.latest_price_info.get(id_fb).unwrap_or(PythReceiverError::PriceUnavailable)?;
+        let price_info = self.latest_price_info.get(id_fb);
+        
+        if price_info.publish_time.get() == U64::ZERO {
+            return Err(PythReceiverError::PriceUnavailable);
+        }
 
         Ok((
-            price_info.publish_time,
-            price_info.expo,
-            price_info.price,
-            price_info.conf,
-            price_info.ema_price,
-            price_info.ema_conf,
+            price_info.publish_time.get(),
+            price_info.expo.get(),
+            price_info.price.get(),
+            price_info.conf.get(),
+            price_info.ema_price.get(),
+            price_info.ema_conf.get(),
         ))
     }