mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Fix buggy string comparison in OCW pallet example (#8602)
This commit is contained in:
@@ -612,18 +612,17 @@ impl<T: Config> Pallet<T> {
|
||||
/// Returns `None` when parsing failed or `Some(price in cents)` when parsing is successful.
|
||||
fn parse_price(price_str: &str) -> Option<u32> {
|
||||
let val = lite_json::parse_json(price_str);
|
||||
let price = val.ok().and_then(|v| match v {
|
||||
let price = match val.ok()? {
|
||||
JsonValue::Object(obj) => {
|
||||
let mut chars = "USD".chars();
|
||||
obj.into_iter()
|
||||
.find(|(k, _)| k.iter().all(|k| Some(*k) == chars.next()))
|
||||
.and_then(|v| match v.1 {
|
||||
JsonValue::Number(number) => Some(number),
|
||||
_ => None,
|
||||
})
|
||||
let (_, v) = obj.into_iter()
|
||||
.find(|(k, _)| k.iter().copied().eq("USD".chars()))?;
|
||||
match v {
|
||||
JsonValue::Number(number) => number,
|
||||
_ => return None,
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
})?;
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let exp = price.fraction_length.checked_sub(2).unwrap_or(0);
|
||||
Some(price.integer as u32 * 100 + (price.fraction / 10_u64.pow(exp)) as u32)
|
||||
|
||||
Reference in New Issue
Block a user