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

Commit c3f91da

Browse files
committed
Merge branch 'ethereum-master' of https://github.com/OpenBazaar/openbazaar-go into abstractions
2 parents 07dcb83 + ae14d9b commit c3f91da

30 files changed

+643
-512
lines changed

api/jsonapi_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,12 @@ func TestListingsQuantity(t *testing.T) {
377377
"POST", "/ob/listing", jsonFor(t, listing), 200, `{"slug": "crypto"}`,
378378
})
379379

380-
listing.Item.Skus[0].Quantity = 0
380+
listing.Item.Skus[0].BigQuantity = "0"
381381
runAPITest(t, apiTest{
382382
"POST", "/ob/listing", jsonFor(t, listing), 200, anyResponseJSON,
383383
})
384384

385-
listing.Item.Skus[0].Quantity = -1
385+
listing.Item.Skus[0].BigQuantity = "-1"
386386
runAPITest(t, apiTest{
387387
"POST", "/ob/listing", jsonFor(t, listing), 200, anyResponseJSON,
388388
})
@@ -394,12 +394,12 @@ func TestCryptoListingsQuantity(t *testing.T) {
394394
"POST", "/ob/listing", jsonFor(t, listing), 200, `{"slug": "crypto"}`,
395395
})
396396

397-
listing.Item.Skus[0].Quantity = 0
397+
listing.Item.Skus[0].BigQuantity = "0"
398398
runAPITest(t, apiTest{
399399
"POST", "/ob/listing", jsonFor(t, listing), 500, errorResponseJSON(repo.ErrCryptocurrencySkuQuantityInvalid),
400400
})
401401

402-
listing.Item.Skus[0].Quantity = -1
402+
listing.Item.Skus[0].BigQuantity = "-1"
403403
runAPITest(t, apiTest{
404404
"POST", "/ob/listing", jsonFor(t, listing), 500, errorResponseJSON(repo.ErrCryptocurrencySkuQuantityInvalid),
405405
})
@@ -479,7 +479,7 @@ func TestMarketRatePrice(t *testing.T) {
479479
listing.Item.PriceCurrency = &pb.CurrencyDefinition{Code: "BTC", Divisibility: 8}
480480

481481
runAPITests(t, apiTests{
482-
{"POST", "/ob/listing", jsonFor(t, listing), 500, errorResponseJSON(repo.ErrMarketPriceListingIllegalField("item.price"))},
482+
{"POST", "/ob/listing", jsonFor(t, listing), 500, errorResponseJSON(repo.ErrMarketPriceListingIllegalField("item.bigPrice"))},
483483
})
484484
}
485485

@@ -564,7 +564,7 @@ func TestWalletCurrencyDictionary(t *testing.T) {
564564

565565
func TestWalletCurrencyDictionaryLookup(t *testing.T) {
566566
var randomLookup string
567-
for currency := range repo.AllCurrencies().AsMap() {
567+
for currency := range repo.TestnetCurrencies().AsMap() {
568568
// pick any currency string from the dictionary
569569
randomLookup = currency
570570
break

core/listings.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,12 @@ func (n *OpenBazaarNode) extractListingData(listing *pb.SignedListing) (repo.Lis
281281
shipsTo = append(shipsTo, region.String())
282282
}
283283
for _, service := range shippingOption.Services {
284+
if service.BigPrice == "" {
285+
return repo.ListingIndexData{}, errors.New("expected shipping service price")
286+
}
284287
servicePrice, ok := new(big.Int).SetString(service.BigPrice, 10)
285288
if !ok {
286-
return repo.ListingIndexData{}, errors.New("invalid price amount")
289+
return repo.ListingIndexData{}, errors.New("invalid shipping service price amount")
287290
}
288291
if servicePrice.Cmp(big.NewInt(0)) == 0 && !contains(freeShipping, region.String()) {
289292
freeShipping = append(freeShipping, region.String())
@@ -293,14 +296,14 @@ func (n *OpenBazaarNode) extractListingData(listing *pb.SignedListing) (repo.Lis
293296
}
294297

295298
var priceValue *repo.CurrencyValue
296-
if listing.Listing.Item.PriceCurrency != nil {
299+
if listing.Listing.Item.PriceCurrency != nil && listing.Listing.Item.BigPrice != "" {
297300
defn, err := n.LookupCurrency(listing.Listing.Item.PriceCurrency.Code)
298301
if err != nil {
299302
return repo.ListingIndexData{}, errors.New("invalid pricing currency")
300303
}
301304
amt, ok := new(big.Int).SetString(listing.Listing.Item.BigPrice, 10)
302305
if !ok {
303-
return repo.ListingIndexData{}, errors.New("invalid price amount")
306+
return repo.ListingIndexData{}, errors.New("invalid item price amount")
304307
}
305308
priceValue = &repo.CurrencyValue{Currency: defn, Amount: amt}
306309
}
@@ -675,7 +678,7 @@ func (n *OpenBazaarNode) GetListingFromSlug(slug string) (*pb.SignedListing, err
675678
for variant, count := range inventory {
676679
for i, s := range sl.Listing.Item.Skus {
677680
if variant == i {
678-
s.Quantity = count
681+
s.BigQuantity = fmt.Sprintf("%d", count)
679682
break
680683
}
681684
}

core/net.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func (n *OpenBazaarNode) SendOrderFulfillment(peerID string, k *libp2p.PubKey, f
458458
Payload: a,
459459
}
460460
orderID0 := fulfillmentMessage.VendorOrderFulfillment[0].OrderId
461-
if orderID0 != "" {
461+
if orderID0 == "" {
462462
log.Errorf("failed fetching orderID")
463463
} else {
464464
err = n.Datastore.Messages().Put(

core/order.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func (n *OpenBazaarNode) Purchase(data *repo.PurchaseData) (orderID string, paym
151151
payment.Method = pb.Order_Payment_ADDRESS_REQUEST
152152

153153
contract.BuyerOrder.Payment = payment
154+
payment.AmountCurrency = &pb.CurrencyDefinition{
155+
Code: defn.Code.String(),
156+
Divisibility: uint32(defn.Divisibility),
157+
}
154158

155159
// Calculate payment amount
156160
total, err := n.CalculateOrderTotal(contract)
@@ -159,7 +163,6 @@ func (n *OpenBazaarNode) Purchase(data *repo.PurchaseData) (orderID string, paym
159163
}
160164

161165
payment.BigAmount = total.String()
162-
contract.BuyerOrder.Payment = payment
163166

164167
contract, err = n.SignOrder(contract)
165168
if err != nil {
@@ -213,6 +216,10 @@ func prepareModeratedOrderContract(data *repo.PurchaseData, n *OpenBazaarNode, c
213216
return nil, errors.New("moderator does not accept our currency")
214217
}
215218
contract.BuyerOrder.Payment = payment
219+
payment.AmountCurrency = &pb.CurrencyDefinition{
220+
Code: defn.Code.String(),
221+
Divisibility: uint32(defn.Divisibility),
222+
}
216223
total, err := n.CalculateOrderTotal(contract)
217224
if err != nil {
218225
return nil, err
@@ -1128,16 +1135,19 @@ func (n *OpenBazaarNode) calculateShippingTotalForListings(contract *pb.Ricardia
11281135
return big.NewInt(0), err
11291136
}
11301137

1131-
var secondarySatoshi *big.Int
1132-
serviceAddlItemPrice, ok := new(big.Int).SetString(service.BigAdditionalItemPrice, 10)
1133-
if !ok {
1134-
return big.NewInt(0), errors.New("invalid service additional price")
1135-
}
1136-
if serviceAddlItemPrice.Cmp(big.NewInt(0)) > 0 {
1137-
secondarySatoshi, err = n.getPriceInSatoshi(contract.BuyerOrder.Payment.AmountCurrency.Code,
1138-
listing.Item.PriceCurrency.Code, serviceAddlItemPrice)
1139-
if err != nil {
1140-
return big.NewInt(0), err
1138+
secondarySatoshi := big.NewInt(0)
1139+
if service.BigAdditionalItemPrice != "" {
1140+
serviceAddlItemPrice, ok := new(big.Int).SetString(service.BigAdditionalItemPrice, 10)
1141+
if !ok {
1142+
return big.NewInt(0), errors.New("invalid service additional price")
1143+
}
1144+
1145+
if serviceAddlItemPrice.Cmp(big.NewInt(0)) > 0 {
1146+
secondarySatoshi, err = n.getPriceInSatoshi(contract.BuyerOrder.Payment.AmountCurrency.Code,
1147+
listing.Item.PriceCurrency.Code, serviceAddlItemPrice)
1148+
if err != nil {
1149+
return big.NewInt(0), err
1150+
}
11411151
}
11421152
}
11431153

core/profile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (n *OpenBazaarNode) UpdateProfile(profile *pb.Profile) error {
110110
}
111111
profile.ModeratorInfo.Fee.FixedFee = &pb.Moderator_Price{
112112
AmountCurrency: &pb.CurrencyDefinition{
113-
Code: normalizedFee.Currency.String(),
113+
Code: normalizedFee.Currency.CurrencyCode().String(),
114114
Divisibility: uint32(normalizedFee.Currency.Divisibility),
115115
},
116116
BigAmount: normalizedFee.Amount.String(),

core/signed_listings.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package core
22

33
import (
4+
"fmt"
45
"io/ioutil"
56

67
"github.com/OpenBazaar/jsonpb"
@@ -42,7 +43,7 @@ func AssignMatchingQuantities(inventory map[int]int64, sl *pb.SignedListing) err
4243
for variant, count := range inventory {
4344
for i, s := range sl.Listing.Item.Skus {
4445
if variant == i {
45-
s.Quantity = count
46+
s.BigQuantity = fmt.Sprintf("%d", count)
4647
break
4748
}
4849
}

core/signed_listings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestOpenBazaarSignedListings_AssignMatchingQuantities(t *testing.T) {
9090
t.Error(err)
9191
}
9292

93-
if listing.Listing.Item.Skus[0].Quantity != 1000 {
93+
if listing.Listing.Item.Skus[0].BigQuantity != "1000" {
9494
t.Error("Inventory was not set properly")
9595
}
9696
}

mobile/cmd/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ func main() {
5050

5151
time.Sleep(time.Second * 10)
5252
fmt.Println("restarting...", time.Now())
53+
54+
wg.Add(1)
55+
5356
go func() {
5457
err := n.Restart()
5558
if err != nil {
56-
fmt.Println(err.Error())
59+
panic(fmt.Sprintf("failed to restart: %s", err.Error()))
5760
}
5861
}()
5962

60-
wg.Add(1)
6163
wg.Wait()
64+
6265
}

mobile/node.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,17 @@ func (n *Node) Restart() error {
539539
n.startMtx.Lock()
540540
defer n.startMtx.Unlock()
541541

542+
var wg sync.WaitGroup
543+
542544
if n.started {
543-
return n.stop()
545+
wg.Add(1)
546+
go func() {
547+
defer wg.Done()
548+
if err := n.stop(); err != nil {
549+
log.Error(err)
550+
}
551+
}()
552+
wg.Wait()
544553
}
545554

546555
// This node has been stopped by the stop command so we need to create

0 commit comments

Comments
 (0)