ソースを参照

refactored integer type from_le_bytes to a try_from

Ayush Suresh 4 ヶ月 前
コミット
2bae09eb67
1 ファイル変更14 行追加5 行削除
  1. 14 5
      target_chains/stylus/contracts/pyth-receiver/src/lib.rs

+ 14 - 5
target_chains/stylus/contracts/pyth-receiver/src/lib.rs

@@ -290,8 +290,10 @@ impl PythReceiver {
                 }
             }
         }
-        Ok(U256::from(total_num_updates).saturating_mul(self.single_update_fee_in_wei.get())
-            + self.transaction_fee_in_wei.get())
+        Ok(
+            U256::from(total_num_updates).saturating_mul(self.single_update_fee_in_wei.get())
+                + self.transaction_fee_in_wei.get(),
+        )
     }
 
     pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
@@ -457,13 +459,20 @@ impl PythReceiver {
                                 }
                             }
 
+                            let expo = I32::try_from(price_feed_message.exponent)
+                                .map_err(|_| PythReceiverError::InvalidUpdateData)?;
+                            let price = I64::try_from(price_feed_message.price)
+                                .map_err(|_| PythReceiverError::InvalidUpdateData)?;
+                            let ema_price = I64::try_from(price_feed_message.ema_price)
+                                .map_err(|_| PythReceiverError::InvalidUpdateData)?;
+
                             let price_info_return = (
                                 price_id_fb,
                                 U64::from(publish_time),
-                                I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
-                                I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
+                                expo,
+                                price,
                                 U64::from(price_feed_message.conf),
-                                I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
+                                ema_price,
                                 U64::from(price_feed_message.ema_conf),
                             );