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

Commit 0dbb29c

Browse files
committed
Set API inventory map to use string
1 parent 869b887 commit 0dbb29c

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

core/inventory.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ var (
1919

2020
// InventoryListing is the listing representation stored on IPFS
2121
type InventoryListing struct {
22-
Inventory *big.Int `json:"inventory"`
23-
LastUpdated string `json:"lastUpdated"`
22+
Inventory string `json:"inventory"`
23+
LastUpdated string `json:"lastUpdated"`
2424
}
2525

2626
// Inventory is the complete inventory representation stored on IPFS
@@ -34,16 +34,18 @@ func (n *OpenBazaarNode) GetLocalInventory() (Inventory, error) {
3434
return nil, err
3535
}
3636

37-
inventory := make(Inventory, len(listings))
38-
totalCount := big.NewInt(0)
37+
var (
38+
totalCount *big.Int
39+
inventory = make(Inventory, len(listings))
40+
)
3941
for slug, variants := range listings {
4042
totalCount = big.NewInt(0)
4143
for _, variantCount := range variants {
4244
totalCount = new(big.Int).Add(totalCount, variantCount)
4345
}
4446

4547
inventory[slug] = &InventoryListing{
46-
Inventory: totalCount,
48+
Inventory: totalCount.String(),
4749
LastUpdated: time.Now().UTC().Format(time.RFC3339),
4850
}
4951
}
@@ -65,7 +67,7 @@ func (n *OpenBazaarNode) GetLocalInventoryForSlug(slug string) (*InventoryListin
6567
}
6668

6769
inventory = &InventoryListing{
68-
Inventory: totalCount,
70+
Inventory: totalCount.String(),
6971
LastUpdated: time.Now().UTC().Format(time.RFC3339),
7072
}
7173

qa/testdata/listing_crypto.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"price": "0",
1818
"priceCurrency": {
1919
"code": "TETH",
20-
"divisibility": 8,
21-
"name": "A",
22-
"currencyType": "A"
20+
"divisibility": 8
2321
},
2422
"images": [{
2523
"tiny": "QmUAuYuiafnJRZxDDX7MuruMNsicYNuyub5vUeAcupUBNs",

repo/listing.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,9 +1651,10 @@ func (l *Listing) GetInventory() (map[int]*big.Int, error) {
16511651
inventory := make(map[int]*big.Int)
16521652
for i, s := range listing.Item.Skus {
16531653
var amtStr string
1654-
if s.BigQuantity != "" {
1654+
switch l.ListingVersion {
1655+
case 5:
16551656
amtStr = s.BigQuantity
1656-
} else {
1657+
default:
16571658
amtStr = strconv.Itoa(int(s.Quantity))
16581659
}
16591660
amt, ok := new(big.Int).SetString(amtStr, 10)
@@ -2119,7 +2120,6 @@ func (l *Listing) validateCryptocurrencyListing() error {
21192120
return ErrListingCryptoCurrencyCodeInvalid
21202121
}
21212122

2122-
21232123
cryptoDivisibility := l.GetCryptoDivisibility()
21242124
if cryptoDivisibility == 0 {
21252125
return ErrListingCryptoDivisibilityInvalid

0 commit comments

Comments
 (0)