Skip to content

Commit 4dffeb3

Browse files
authored
Refactor some Price util functions (#27)
1 parent f8970d6 commit 4dffeb3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pyth-sdk/src/price.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ impl Price {
9696
/// basket_price.price, basket_price.conf, basket_price.expo);
9797
/// ```
9898
pub fn price_basket(amounts: &[(Price, i64, i32)], result_expo: i32) -> Option<Price> {
99-
assert!(amounts.len() > 0);
99+
if amounts.is_empty() {
100+
return None;
101+
}
102+
100103
let mut res = Price {
101104
price: 0,
102105
conf: 0,
103106
expo: result_expo,
104107
};
105-
for i in 0..amounts.len() {
108+
for amount in amounts {
106109
res = res.add(
107-
&amounts[i]
110+
&amount
108111
.0
109-
.cmul(amounts[i].1, amounts[i].2)?
112+
.cmul(amount.1, amount.2)?
110113
.scale_to_exponent(result_expo)?,
111114
)?
112115
}

0 commit comments

Comments
 (0)