From 19afa09c4d31d9ac45f8ee6ec3bfa6650d691635 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 14 Mar 2024 07:17:58 -0400 Subject: [PATCH] refactor: split computeByRate to newRat --- renter/price_tracker.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/renter/price_tracker.go b/renter/price_tracker.go index cad3d05..cb1b4c2 100644 --- a/renter/price_tracker.go +++ b/renter/price_tracker.go @@ -299,15 +299,24 @@ func siacoinsFromRat(r *big.Rat) (types.Currency, error) { } func computeByRate(num string, rate decimal.Decimal, name string) (*big.Rat, error) { + parsedNum, err := newRat(num, name) + if err != nil { + return nil, err + } + + parsedRate := new(big.Rat).Quo(parsedNum, rate.Rat()) + + return parsedRate, nil +} + +func newRat(num string, name string) (*big.Rat, error) { parsedNum, ok := new(big.Rat).SetString(num) if !ok { return nil, errors.New("failed to parse " + name) } - parsedRate := new(big.Rat).Quo(parsedNum, rate.Rat()) - - return parsedRate, nil + return parsedNum, nil } func ratDivide(a *big.Rat, b uint64) *big.Rat {