Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 8700a76

Browse files
committed
Linter fixes
1 parent f98aac8 commit 8700a76

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

core/order.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
906906
var (
907907
total = big.NewInt(0)
908908
physicalGoods = make(map[string]*pb.Listing)
909-
toHundreths = func(f float32) *big.Float {
909+
toHundredths = func(f float32) *big.Float {
910910
return new(big.Float).Mul(big.NewFloat(float64(f)), big.NewFloat(0.01))
911911
}
912912
)
@@ -935,9 +935,9 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
935935
itemOriginAmt = repo.NewCurrencyValueFromBigInt(GetOrderQuantity(l, item), originDef)
936936

937937
if l.Metadata.PriceModifier != 0 {
938-
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundreths(l.Metadata.PriceModifier))
938+
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundredths(l.Metadata.PriceModifier))
939939
} else if l.Item.PriceModifier != 0 {
940-
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundreths(l.Item.PriceModifier))
940+
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundredths(l.Item.PriceModifier))
941941
}
942942
} else {
943943
oAmt, err := repo.NewCurrencyValueFromProtobuf(l.Item.BigPrice, l.Item.PriceCurrency)
@@ -980,7 +980,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
980980
itemOriginAmt = itemOriginAmt.SubBigInt(disc)
981981
} else if discountF := vendorCoupon.GetPercentDiscount(); discountF > 0 {
982982
// apply percentage discount
983-
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundreths(-discountF))
983+
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundredths(-discountF))
984984
}
985985
}
986986
}
@@ -990,7 +990,7 @@ func (n *OpenBazaarNode) CalculateOrderTotal(contract *pb.RicardianContract) (*b
990990
for _, tax := range l.Taxes {
991991
for _, taxRegion := range tax.TaxRegions {
992992
if contract.BuyerOrder.Shipping.Country == taxRegion {
993-
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundreths(tax.Percentage))
993+
itemOriginAmt = itemOriginAmt.AddBigFloatProduct(toHundredths(tax.Percentage))
994994
break
995995
}
996996
}
@@ -1711,7 +1711,9 @@ func (n *OpenBazaarNode) ReserveCurrencyConverter() (*repo.CurrencyConverter, er
17111711
}
17121712

17131713
// priming the exchange rate cache
1714-
wal.ExchangeRates().GetAllRates(false)
1714+
if _, err := wal.ExchangeRates().GetAllRates(false); err != nil {
1715+
log.Warningf("priming exchange rate cache: %s", err.Error())
1716+
}
17151717

17161718
cc, err := repo.NewCurrencyConverter(reserveCode, wal.ExchangeRates())
17171719
if err != nil {

core/utils.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ func (n *OpenBazaarNode) LookupCurrency(currencyCode string) (repo.CurrencyDefin
113113
return repo.AllCurrencies().Lookup(currencyCode)
114114
}
115115

116-
// exchangeRateCode strips the T off the currency code if we are on testnet or regtest.
117-
func (n *OpenBazaarNode) exchangeRateCode(currencyCode string) string {
118-
if n.TestnetEnable || n.RegressionTestEnable {
119-
return strings.TrimPrefix(currencyCode, "T")
120-
}
121-
return currencyCode
122-
}
123-
124116
func (n *OpenBazaarNode) ValidateMultiwalletHasPreferredCurrencies(data repo.SettingsData) error {
125117
if data.PreferredCurrencies == nil {
126118
return nil

repo/currency_converter.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ func NewEquivalentConverter() *CurrencyConverter {
2626
return &CurrencyConverter{reserveCode: "EQL", reserveRater: equivRater{}}
2727
}
2828

29+
// CurrencyConverter is suitable for converting a currency from one CurrencyDefinition
30+
// to another, accounting for their differing divisibility as well as their differing
31+
// exchange rate as provided by the rater. The rater can represent all rates for the
32+
// reserve currency code provided.
2933
type CurrencyConverter struct {
3034
reserveCode string
3135
reserveRater rater
3236
}
3337

34-
func NewCurrencyConverter(code string, rater rater) (*CurrencyConverter, error) {
35-
var cc = &CurrencyConverter{reserveCode: code, reserveRater: rater}
38+
// NewCurrencyConverter returns a valid CurrencyConverter. The rater is verified by
39+
// ensuring the rate of its reserveCode is 1.0 (ensuring it is equivalent to itself).
40+
func NewCurrencyConverter(reserveCode string, rater rater) (*CurrencyConverter, error) {
41+
var cc = &CurrencyConverter{reserveCode: reserveCode, reserveRater: rater}
3642
if rate, err := cc.getExchangeRate(cc.reserveCode); err != nil {
3743
return nil, fmt.Errorf("unable to get reserve rate (%s): %s", cc.reserveCode, err.Error())
3844
} else if rate != 1.0 {

0 commit comments

Comments
 (0)