Skip to content

Commit 2bae09e

Browse files
committed
refactored integer type from_le_bytes to a try_from
1 parent 49b00cf commit 2bae09e

File tree

1 file changed

+14
-5
lines changed
  • target_chains/stylus/contracts/pyth-receiver/src

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,10 @@ impl PythReceiver {
290290
}
291291
}
292292
}
293-
Ok(U256::from(total_num_updates).saturating_mul(self.single_update_fee_in_wei.get())
294-
+ self.transaction_fee_in_wei.get())
293+
Ok(
294+
U256::from(total_num_updates).saturating_mul(self.single_update_fee_in_wei.get())
295+
+ self.transaction_fee_in_wei.get(),
296+
)
295297
}
296298

297299
pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
@@ -457,13 +459,20 @@ impl PythReceiver {
457459
}
458460
}
459461

462+
let expo = I32::try_from(price_feed_message.exponent)
463+
.map_err(|_| PythReceiverError::InvalidUpdateData)?;
464+
let price = I64::try_from(price_feed_message.price)
465+
.map_err(|_| PythReceiverError::InvalidUpdateData)?;
466+
let ema_price = I64::try_from(price_feed_message.ema_price)
467+
.map_err(|_| PythReceiverError::InvalidUpdateData)?;
468+
460469
let price_info_return = (
461470
price_id_fb,
462471
U64::from(publish_time),
463-
I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
464-
I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
472+
expo,
473+
price,
465474
U64::from(price_feed_message.conf),
466-
I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
475+
ema_price,
467476
U64::from(price_feed_message.ema_conf),
468477
);
469478

0 commit comments

Comments
 (0)