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

Commit 0a885c5

Browse files
committed
Fix disputes payouts to v4 vendor
1 parent f87525c commit 0a885c5

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

core/disputes.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,6 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
502502
return ErrCloseFailureCaseExpired
503503
}
504504

505-
var outpoints = dispute.ResolutionPaymentOutpoints(payDivision)
506-
if outpoints == nil {
507-
log.Errorf("no outpoints to resolve in dispute for order %s", orderID)
508-
return ErrCloseFailureNoOutpoints
509-
}
510-
511505
if dispute.VendorContract == nil && vendorPercentage > 0 {
512506
return errors.New("vendor must provide his copy of the contract before you can release funds to the vendor")
513507
}
@@ -521,6 +515,24 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
521515
return err
522516
}
523517

518+
var outpoints = dispute.ResolutionPaymentOutpoints(payDivision)
519+
if outpoints == nil {
520+
log.Errorf("no outpoints to resolve in dispute for order %s", orderID)
521+
return ErrCloseFailureNoOutpoints
522+
}
523+
for i, o := range outpoints {
524+
if preferredContract.VendorListings[0].Metadata.Version < repo.ListingVersion {
525+
if o.BigValue != "" {
526+
n, ok := new(big.Int).SetString(o.BigValue, 10)
527+
if !ok {
528+
return errors.New("invalid amount")
529+
}
530+
outpoints[i].Value = n.Uint64()
531+
outpoints[i].BigValue = ""
532+
}
533+
}
534+
}
535+
524536
// TODO: Remove once broken contracts are migrated
525537
paymentCoin := preferredOrder.Payment.AmountCurrency.Code
526538
_, err = n.LookupCurrency(paymentCoin)
@@ -563,9 +575,15 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
563575
// Calculate total out value
564576
totalOut := big.NewInt(0)
565577
for _, o := range outpoints {
566-
n, ok := new(big.Int).SetString(o.BigValue, 10)
567-
if !ok {
568-
return errors.New("invalid total out amount")
578+
var n *big.Int
579+
if o.Value > 0 {
580+
n = big.NewInt(int64(o.Value))
581+
} else {
582+
ok := false
583+
n, ok = new(big.Int).SetString(o.BigValue, 10)
584+
if !ok {
585+
return errors.New("invalid amount")
586+
}
569587
}
570588
totalOut = new(big.Int).Add(totalOut, n)
571589
}
@@ -640,9 +658,15 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
640658
if err != nil {
641659
return err
642660
}
643-
n, ok := new(big.Int).SetString(o.BigValue, 10)
644-
if !ok {
645-
return errors.New("invalid amount")
661+
var n *big.Int
662+
if o.Value > 0 {
663+
n = big.NewInt(int64(o.Value))
664+
} else {
665+
ok := false
666+
n, ok = new(big.Int).SetString(o.BigValue, 10)
667+
if !ok {
668+
return errors.New("invalid amount")
669+
}
646670
}
647671
input := wallet.TransactionInput{
648672
OutpointHash: decodedHash,

qa/dispute_close_buyer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run_test(self):
6464
# post listing to alice
6565
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6666
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
67-
if self.vendor_version == 4:
67+
if self.vendor_version == "v4":
6868
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
6969
else:
7070
listing_json["item"]["priceCurrency"]["code"] = "t" + self.cointype
@@ -137,7 +137,7 @@ def run_test(self):
137137
"feeLevel": "NORMAL",
138138
"requireAssociateOrder": False
139139
}
140-
if self.buyer_version == 4:
140+
if self.buyer_version == "v4":
141141
spend["amount"] = payment_amount
142142
spend["wallet"] = "T" + self.cointype
143143

@@ -171,7 +171,7 @@ def run_test(self):
171171
raise TestFailure("DisputeCloseBuyerTest - FAIL: Alice failed to detect payment")
172172
if resp["funded"] == False:
173173
raise TestFailure("DisputeCloseBuyerTest - FAIL: Alice incorrectly saved as unfunded")
174-
174+
175175
# Bob open dispute
176176
dispute = {
177177
"orderId": orderId,
@@ -281,7 +281,7 @@ def run_test(self):
281281
confirmed = int(resp["confirmed"])
282282
#unconfirmed = int(resp["unconfirmed"])
283283
amt = 0
284-
if self.buyer_version == 4:
284+
if self.buyer_version == "v4":
285285
amt = payment_amount
286286
else:
287287
amt = int(payment_amount["amount"])

qa/dispute_close_split.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run_test(self):
6464
# post listing to alice
6565
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6666
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
67-
if self.vendor_version == 4:
67+
if self.vendor_version == "v4":
6868
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
6969
else:
7070
listing_json["item"]["priceCurrency"]["code"] = "t" + self.cointype
@@ -137,7 +137,7 @@ def run_test(self):
137137
"feeLevel": "NORMAL",
138138
"requireAssociateOrder": False
139139
}
140-
if self.buyer_version == 4:
140+
if self.buyer_version == "v4":
141141
spend["amount"] = payment_amount
142142
spend["wallet"] = "T" + self.cointype
143143

@@ -281,7 +281,7 @@ def run_test(self):
281281
confirmed = int(resp["confirmed"])
282282
unconfirmed = int(resp["unconfirmed"])
283283
amt = 0
284-
if self.buyer_version == 4:
284+
if self.buyer_version == "v4":
285285
amt = payment_amount
286286
else:
287287
amt = int(payment_amount["amount"])

qa/dispute_close_vendor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def run_test(self):
6464
# post listing to alice
6565
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6666
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
67-
if self.vendor_version == 4:
67+
if self.vendor_version == "v4":
6868
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
6969
else:
7070
listing_json["item"]["priceCurrency"]["code"] = "t" + self.cointype
@@ -139,7 +139,7 @@ def run_test(self):
139139
"feeLevel": "NORMAL",
140140
"requireAssociateOrder": False
141141
}
142-
if self.buyer_version == 4:
142+
if self.buyer_version == "v4":
143143
spend["amount"] = payment_amount
144144
spend["wallet"] = "T" + self.cointype
145145

@@ -205,7 +205,7 @@ def run_test(self):
205205
resp = json.loads(r.text)
206206
if resp["state"] != "FULFILLED":
207207
raise TestFailure("FulfillDirectOnlineTest - FAIL: Alice failed to order fulfillment")
208-
208+
209209
# Alice open dispute
210210
dispute = {
211211
"orderId": orderId,
@@ -304,7 +304,7 @@ def run_test(self):
304304
time.sleep(20)
305305

306306
self.send_bitcoin_cmd("generate", 1)
307-
time.sleep(2)
307+
time.sleep(20)
308308

309309
# Check alice received payout
310310
api_url = alice["gateway_url"] + "wallet/balance/T" + self.cointype

0 commit comments

Comments
 (0)