pub fn parse_price(price_str: &str, target_currency: &[u8], scale: u32) -> Option<u128> {
	let val = lite_json::parse_json(price_str);
	let price = match val.ok()? {
		JsonValue::Object(obj) => {
			let (_, v) = obj.into_iter().find(|(k, _)| k.iter().copied().eq(target_currency.iter().map(|b| *b as char)))?;
			match v {
				JsonValue::Number(number) => number,
				_ => return None,
			}
		},
		_ => return None,
	};

	let exp = price.fraction_length.saturating_sub(2);
	Some(price.integer as u128 * 10_u128.pow(scale) + (price.fraction as u128 * 10_u128.pow(scale-2) / 10_u128.pow(exp)) as u128)
}
/// Parse the price from the given JSON string using `lite-json`.
///
/// Returns `None` when parsing failed or `Some(price in cents)` when parsing is successful.
Parse the price from the given JSON string using `lite-json`.
Returns `None` when parsing failed or `Some(price in cents)` when parsing is successful.
Parse the price from the given JSON string using ` lite - json ` . Returns ` None ` when parsing failed or ` Some ( price in cents ) ` when parsing is successful .
pub fn parse_price(price_str: &str, target_currency: &[u8], scale: u32) -> Option<u128> {
	let val = lite_json::parse_json(price_str);
	let price = match val.ok()? {
		JsonValue::Object(obj) => {
			let (_, v) = obj.into_iter().find(|(k, _)| k.iter().copied().eq(target_currency.iter().map(|b| *b as char)))?;
			match v {
				JsonValue::Number(number) => number,
				_ => return None,
			}
		},
		_ => return None,
	};
	let exp = price.fraction_length.saturating_sub(2);
	Some(price.integer as u128 * 10_u128.pow(scale) + (price.fraction as u128 * 10_u128.pow(scale-2) / 10_u128.pow(exp)) as u128)
}
pub fn parse_price ( price_str : & str , target_currency : & [ u8 ] , scale : u32 ) -> Option < u128 > { let val = lite_json :: parse_json ( price_str ) ; let price = match val . ok ( ) ? { JsonValue :: Object ( obj ) => { let ( _ , v ) = obj . into_iter ( ) . find ( | ( k , _ ) | k . iter ( ) . copied ( ) . eq ( target_currency . iter ( ) . map ( | b | * b as char ) ) ) ? ; match v { JsonValue :: Number ( number ) => number , _ => return None , } } , _ => return None , } ; let exp = price . fraction_length . saturating_sub ( 2 ) ; Some ( price . integer as u128 * 10_u128 . pow ( scale ) + ( price . fraction as u128 * 10_u128 . pow ( scale - 2 ) / 10_u128 . pow ( exp ) ) as u128 ) }
Parse the price from the given JSON string using `lite-json`.
Parse the price from the given JSON string using ` lite - json ` .
price_str
&str
target_currency
&[u8]
scale
u32
price_str
&str
target_currency
&[u8]
scale
u32