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

Commit efe7a09

Browse files
committed
Update price checking for negative prices
1 parent 6e15486 commit efe7a09

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/listings.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,10 @@ func (n *OpenBazaarNode) SetPriceOnListings(percentage float64) error {
666666
oldSL := repo.NewSignedListingFromProtobuf(signedProto)
667667
l := oldSL.GetListing()
668668

669-
l.SetPrices(percentage)
669+
err = l.SetPrices(percentage)
670+
if err != nil {
671+
return err
672+
}
670673

671674
lb, err := l.MarshalJSON()
672675
if err != nil {

repo/listing.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,13 @@ func (l *Listing) SetPrices(percentage float64) error {
516516
newPrice := new(big.Float).Mul(currentPrice, floatFactor)
517517
newPriceInt, _ := newPrice.Int(nil)
518518

519-
l.listingProto.Item.BigPrice = newPriceInt.String()
519+
// Check if new price is negative
520+
zeroInt, _ := new(big.Int).SetString("0", 10)
521+
if newPriceInt.Cmp(zeroInt) == -1 {
522+
l.listingProto.Item.BigPrice = "1"
523+
} else {
524+
l.listingProto.Item.BigPrice = newPriceInt.String()
525+
}
520526

521527
return nil
522528
}

0 commit comments

Comments
 (0)