diff --git a/Lib9c/TableData/Swap/SwapRateSheet.cs b/Lib9c/TableData/Swap/SwapRateSheet.cs index d4ebe2ba9f..cc01904de2 100644 --- a/Lib9c/TableData/Swap/SwapRateSheet.cs +++ b/Lib9c/TableData/Swap/SwapRateSheet.cs @@ -23,8 +23,7 @@ public override void Set(IReadOnlyList fields) var currencyFrom = ParseCurrency(fields[0]); var currencyTo = ParseCurrency(fields[1]); Pair = new CurrencyPair(currencyFrom, currencyTo); - RateNumerator = ParseBigInteger(fields[2]); - RateDenominator = ParseBigInteger(fields[3]); + (RateNumerator, RateDenominator) = ParseFraction(fields[2]); } } diff --git a/Lib9c/TableData/TableExtensions.cs b/Lib9c/TableData/TableExtensions.cs index 2379babacc..4cad0d956f 100644 --- a/Lib9c/TableData/TableExtensions.cs +++ b/Lib9c/TableData/TableExtensions.cs @@ -73,6 +73,40 @@ public static BigInteger ParseBigInteger(string value) throw new ArgumentException(value); } + public static (BigInteger Numerator, BigInteger Denominator) ParseFraction(string value) + { + if (TryParseFraction(value, out var result)) + { + return result; + } + + throw new ArgumentException(value); + } + + public static bool TryParseFraction(string value, out (BigInteger Numerator, BigInteger Denominator) result) + { + result = (BigInteger.One, BigInteger.One); + + List fractionStrings = value.Split("/").ToList(); + if (fractionStrings.Count != 2) + { + return false; + } + + if (!BigInteger.TryParse(fractionStrings[0].Trim(), out var numerator)) + { + return false; + } + + if (!BigInteger.TryParse(fractionStrings[1].Trim(), out var denominator)) + { + return false; + } + + result = (numerator, denominator); + return true; + } + public static Currency ParseCurrency(string value) { if (TryParseCurrency(value, out var result))