@@ -211,12 +211,21 @@ func (Migration027) Up(repoPath, databasePassword string, testnetEnabled bool) e
211
211
return err
212
212
}
213
213
214
- listingJSON := signedListingJSON ["listing" ]
214
+ listingJSON , listingExists := signedListingJSON ["listing" ]
215
+ if ! listingExists {
216
+ continue
217
+ }
215
218
listing := listingJSON .(map [string ]interface {})
216
219
217
- metadataJSON := listing ["metadata" ]
220
+ metadataJSON , metadataExists := listing ["metadata" ]
221
+ if ! metadataExists {
222
+ continue
223
+ }
218
224
metadata := metadataJSON .(map [string ]interface {})
219
- itemJSON := listing ["item" ]
225
+ itemJSON , itemExists := listing ["item" ]
226
+ if ! itemExists {
227
+ continue
228
+ }
220
229
item := itemJSON .(map [string ]interface {})
221
230
222
231
var (
@@ -238,24 +247,25 @@ func (Migration027) Up(repoPath, databasePassword string, testnetEnabled bool) e
238
247
coupons = couponsJSON .([]interface {})
239
248
}
240
249
241
- pricingCurrencyJSON := metadata ["pricingCurrency" ]
242
- pricingCurrency := pricingCurrencyJSON .(string )
250
+ pricingCurrencyJSON , pricingCurrencyExists := metadata ["pricingCurrency" ]
251
+ if pricingCurrencyExists {
252
+ pricingCurrency := pricingCurrencyJSON .(string )
253
+ divisibility , ok := divisibilityMap [strings .ToUpper (pricingCurrency )]
254
+ if ! ok {
255
+ divisibility = 2
256
+ }
243
257
244
- divisibility , ok := divisibilityMap [strings .ToUpper (pricingCurrency )]
245
- if ! ok {
246
- divisibility = 2
247
- }
258
+ item ["priceCurrency" ] = struct {
259
+ Code string `json:"code"`
260
+ Divisibility uint32 `json:"divisibility"`
261
+ }{
262
+ Code : pricingCurrency ,
263
+ Divisibility : uint32 (divisibility ),
264
+ }
248
265
249
- item ["priceCurrency" ] = struct {
250
- Code string `json:"code"`
251
- Divisibility uint32 `json:"divisibility"`
252
- }{
253
- Code : pricingCurrency ,
254
- Divisibility : uint32 (divisibility ),
266
+ delete (metadata , "pricingCurrency" )
255
267
}
256
268
257
- delete (metadata , "pricingCurrency" )
258
-
259
269
var modifier float64
260
270
modifierJSON := metadata ["priceModifier" ]
261
271
if modifierJSON != nil {
@@ -266,47 +276,29 @@ func (Migration027) Up(repoPath, databasePassword string, testnetEnabled bool) e
266
276
267
277
delete (metadata , "priceModifier" )
268
278
269
- priceJSON := item ["price" ]
270
- price := priceJSON .(float64 )
271
-
272
- item ["bigPrice" ] = strconv .Itoa (int (price ))
279
+ priceJSON , priceExists := item ["price" ]
280
+ if priceExists {
281
+ price := priceJSON .(float64 )
273
282
274
- delete ( item , "price" )
283
+ item [ "bigPrice" ] = strconv . Itoa ( int ( price ) )
275
284
276
- var coinType string
277
- coinTypeJSON := metadata ["coinType" ]
278
- if coinTypeJSON != nil {
279
- coinType = coinTypeJSON .(string )
285
+ delete (item , "price" )
280
286
}
281
287
282
- metadata ["cryptoCurrencyCode" ] = coinType
283
-
284
- delete (metadata , "coinType" )
285
-
286
- var coinDivisibility float64
287
- coinDivisibilityJSON := metadata ["coinDivisibility" ]
288
- if coinDivisibilityJSON != nil {
289
- coinDivisibility = coinDivisibilityJSON .(float64 )
290
- }
291
-
292
- metadata ["cryptoDivisibility" ] = uint32 (coinDivisibility )
293
-
294
- delete (metadata , "coinDivisibility" )
295
-
296
288
for _ , skuJSON := range skus {
297
289
sku := skuJSON .(map [string ]interface {})
298
290
299
- quantityJSON , ok := sku ["quantity" ]
300
- if ok {
291
+ quantityJSON , quantityExists := sku ["quantity" ]
292
+ if quantityExists {
301
293
quantity := quantityJSON .(float64 )
302
294
303
295
sku ["bigQuantity" ] = strconv .Itoa (int (quantity ))
304
296
305
297
delete (sku , "quantity" )
306
298
}
307
299
308
- surchargeJSON , ok := sku ["surcharge" ]
309
- if ok {
300
+ surchargeJSON , surchargeExists := sku ["surcharge" ]
301
+ if surchargeExists {
310
302
surcharge := surchargeJSON .(float64 )
311
303
312
304
sku ["bigSurcharge" ] = strconv .Itoa (int (surcharge ))
@@ -327,14 +319,16 @@ func (Migration027) Up(repoPath, databasePassword string, testnetEnabled bool) e
327
319
service := serviceJSON .(map [string ]interface {})
328
320
329
321
priceJSON := service ["price" ]
330
- price := priceJSON .(float64 )
322
+ price , priceExists := priceJSON .(float64 )
331
323
332
- service ["bigPrice" ] = strconv .Itoa (int (price ))
324
+ if priceExists {
325
+ service ["bigPrice" ] = strconv .Itoa (int (price ))
333
326
334
- delete (service , "price" )
327
+ delete (service , "price" )
328
+ }
335
329
336
- additionalItemPriceJSON , ok := service ["additionalItemPrice" ]
337
- if ok {
330
+ additionalItemPriceJSON , additionalPriceExists := service ["additionalItemPrice" ]
331
+ if additionalPriceExists {
338
332
additionalItemPrice := additionalItemPriceJSON .(float64 )
339
333
340
334
service ["bigAdditionalItemPrice" ] = strconv .Itoa (int (additionalItemPrice ))
@@ -477,12 +471,21 @@ func (Migration027) Down(repoPath, databasePassword string, testnetEnabled bool)
477
471
return err
478
472
}
479
473
480
- listingJSON := signedListingJSON ["listing" ]
474
+ listingJSON , listingExists := signedListingJSON ["listing" ]
475
+ if ! listingExists {
476
+ continue
477
+ }
481
478
listing := listingJSON .(map [string ]interface {})
482
479
483
- metadataJSON := listing ["metadata" ]
480
+ metadataJSON , metadataExists := listing ["metadata" ]
481
+ if ! metadataExists {
482
+ continue
483
+ }
484
484
metadata := metadataJSON .(map [string ]interface {})
485
- itemJSON := listing ["item" ]
485
+ itemJSON , itemExists := listing ["item" ]
486
+ if ! itemExists {
487
+ continue
488
+ }
486
489
item := itemJSON .(map [string ]interface {})
487
490
488
491
var (
@@ -504,15 +507,19 @@ func (Migration027) Down(repoPath, databasePassword string, testnetEnabled bool)
504
507
coupons = couponsJSON .([]interface {})
505
508
}
506
509
507
- pricingCurrencyJSON := item ["priceCurrency" ]
508
- pricingCurrency := pricingCurrencyJSON .(map [string ]interface {})
510
+ pricingCurrencyJSON , pricingCurrencyExists := item ["priceCurrency" ]
511
+ if pricingCurrencyExists {
512
+ pricingCurrency := pricingCurrencyJSON .(map [string ]interface {})
509
513
510
- priceCurrencyCodeJSON := pricingCurrency ["code" ]
511
- priceCurrencyCode := priceCurrencyCodeJSON .(string )
514
+ priceCurrencyCodeJSON , currencyCodeExists := pricingCurrency ["code" ]
515
+ if currencyCodeExists {
516
+ priceCurrencyCode := priceCurrencyCodeJSON .(string )
512
517
513
- metadata ["pricingCurrency" ] = priceCurrencyCode
518
+ metadata ["pricingCurrency" ] = priceCurrencyCode
514
519
515
- delete (item , "priceCurrency" )
520
+ delete (item , "priceCurrency" )
521
+ }
522
+ }
516
523
517
524
var modifier float64
518
525
modifierJSON := item ["priceModifier" ]
@@ -524,39 +531,21 @@ func (Migration027) Down(repoPath, databasePassword string, testnetEnabled bool)
524
531
525
532
delete (item , "priceModifier" )
526
533
527
- priceJSON := item ["bigPrice" ]
528
- price := priceJSON .(string )
529
-
530
- p , ok := new (big.Int ).SetString (price , 10 )
531
- if ok {
532
- item ["price" ] = p .Uint64 ()
533
- }
534
- delete (item , "bigPrice" )
535
-
536
- var coinType string
537
- coinTypeJSON := metadata ["cryptoCurrencyCode" ]
538
- if coinTypeJSON != nil {
539
- coinType = coinTypeJSON .(string )
540
- }
541
-
542
- metadata ["coinType" ] = coinType
543
-
544
- delete (metadata , "cryptoCurrencyCode" )
534
+ priceJSON , priceExists := item ["bigPrice" ]
535
+ if priceExists {
536
+ price := priceJSON .(string )
545
537
546
- var coinDivisibility float64
547
- coinDivisibilityJSON := metadata ["cryptoDivisibility" ]
548
- if coinDivisibilityJSON != nil {
549
- coinDivisibility = coinDivisibilityJSON .(float64 )
538
+ p , ok := new (big.Int ).SetString (price , 10 )
539
+ if ok {
540
+ item ["price" ] = p .Uint64 ()
541
+ }
542
+ delete (item , "bigPrice" )
550
543
}
551
544
552
- metadata ["coinDivisibility" ] = uint32 (coinDivisibility )
553
-
554
- delete (metadata , "cryptoDivisibility" )
555
-
556
545
for _ , skuJSON := range skus {
557
546
sku := skuJSON .(map [string ]interface {})
558
- quantityJSON , ok := sku ["bigQuantity" ]
559
- if ok {
547
+ quantityJSON , quantityExists := sku ["bigQuantity" ]
548
+ if quantityExists {
560
549
quantity := quantityJSON .(string )
561
550
562
551
p , ok := new (big.Int ).SetString (quantity , 10 )
@@ -591,18 +580,20 @@ func (Migration027) Down(repoPath, databasePassword string, testnetEnabled bool)
591
580
for x , serviceJSON := range services {
592
581
service := serviceJSON .(map [string ]interface {})
593
582
594
- priceJSON := service ["bigPrice" ]
595
- price := priceJSON .(string )
583
+ priceJSON , priceExists := service ["bigPrice" ]
584
+ if priceExists {
585
+ price := priceJSON .(string )
596
586
597
- p , ok := new (big.Int ).SetString (price , 10 )
598
- if ok {
599
- service ["price" ] = p .Uint64 ()
600
- }
587
+ p , ok := new (big.Int ).SetString (price , 10 )
588
+ if ok {
589
+ service ["price" ] = p .Uint64 ()
590
+ }
601
591
602
- delete (service , "bigPrice" )
592
+ delete (service , "bigPrice" )
593
+ }
603
594
604
- additionalItemPriceJSON , ok := service ["bigAdditionalItemPrice" ]
605
- if ok {
595
+ additionalItemPriceJSON , additionalPriceExists := service ["bigAdditionalItemPrice" ]
596
+ if additionalPriceExists {
606
597
additionalItemPrice := additionalItemPriceJSON .(string )
607
598
608
599
a , ok := new (big.Int ).SetString (additionalItemPrice , 10 )
@@ -622,8 +613,8 @@ func (Migration027) Down(repoPath, databasePassword string, testnetEnabled bool)
622
613
for _ , couponJSON := range coupons {
623
614
coupon := couponJSON .(map [string ]interface {})
624
615
625
- priceDiscountJSON , ok := coupon ["bigPriceDiscount" ]
626
- if ok {
616
+ priceDiscountJSON , priceDiscountExists := coupon ["bigPriceDiscount" ]
617
+ if priceDiscountExists {
627
618
priceDiscount := priceDiscountJSON .(string )
628
619
629
620
a , ok := new (big.Int ).SetString (priceDiscount , 10 )
0 commit comments