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

Commit f87525c

Browse files
committed
Use v4 contract in dispute where needed
1 parent d4f9eb0 commit f87525c

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

api/jsonapi.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,13 @@ func (i *jsonAPIHandler) POSTOpenDispute(w http.ResponseWriter, r *http.Request)
21222122
}
21232123

21242124
// TODO: Remove once broken contracts are migrated
2125-
lookupCoin := contract.BuyerOrder.Payment.AmountCurrency.Code
2125+
v5order, err := repo.ToV5Order(contract.BuyerOrder, nil)
2126+
if err != nil {
2127+
ErrorResponse(w, http.StatusBadRequest, err.Error())
2128+
return
2129+
}
2130+
2131+
lookupCoin := v5order.Payment.AmountCurrency.Code
21262132
_, err = i.node.LookupCurrency(lookupCoin)
21272133
if err != nil {
21282134
log.Warningf("invalid BuyerOrder.Payment.Coin (%s) on order (%s)", lookupCoin, d.OrderID)
@@ -2268,8 +2274,14 @@ func (i *jsonAPIHandler) POSTReleaseFunds(w http.ResponseWriter, r *http.Request
22682274
}
22692275
}
22702276

2277+
v5order, err := repo.ToV5Order(contract.BuyerOrder, nil)
2278+
if err != nil {
2279+
ErrorResponse(w, http.StatusBadRequest, err.Error())
2280+
return
2281+
}
2282+
22712283
// TODO: Remove once broken contracts are migrated
2272-
lookupCoin := contract.BuyerOrder.Payment.AmountCurrency.Code
2284+
lookupCoin := v5order.Payment.AmountCurrency.Code
22732285
_, err = i.node.LookupCurrency(lookupCoin)
22742286
if err != nil {
22752287
log.Warningf("invalid BuyerOrder.Payment.Coin (%s) on order (%s)", lookupCoin, rel.OrderID)

core/disputes.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,25 +738,39 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
738738
if out, ok := outMap["buyer"]; ok {
739739
payout.BuyerOutput = &pb.DisputeResolution_Payout_Output{
740740
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: buyerAddr.String()},
741-
BigAmount: out.Value.String(),
741+
}
742+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
743+
payout.BuyerOutput.BigAmount = out.Value.String()
744+
} else {
745+
payout.BuyerOutput.Amount = out.Value.Uint64()
742746
}
743747
}
744748
if out, ok := outMap["vendor"]; ok {
745749
payout.VendorOutput = &pb.DisputeResolution_Payout_Output{
746750
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: vendorAddr.String()},
747-
BigAmount: out.Value.String(),
751+
}
752+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
753+
payout.VendorOutput.BigAmount = out.Value.String()
754+
} else {
755+
payout.VendorOutput.Amount = out.Value.Uint64()
748756
}
749757
}
750758
if out, ok := outMap["moderator"]; ok {
751759
payout.ModeratorOutput = &pb.DisputeResolution_Payout_Output{
752760
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: modAddr.String()},
753-
BigAmount: out.Value.String(),
761+
}
762+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
763+
payout.ModeratorOutput.BigAmount = out.Value.String()
764+
} else {
765+
payout.ModeratorOutput.Amount = out.Value.Uint64()
754766
}
755767
}
756768

757-
payout.PayoutCurrency = &pb.CurrencyDefinition{
758-
Code: preferredOrder.Payment.AmountCurrency.Code,
759-
Divisibility: preferredOrder.Payment.AmountCurrency.Divisibility,
769+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
770+
payout.PayoutCurrency = &pb.CurrencyDefinition{
771+
Code: preferredOrder.Payment.AmountCurrency.Code,
772+
Divisibility: preferredOrder.Payment.AmountCurrency.Divisibility,
773+
}
760774
}
761775

762776
d.Payout = payout

qa/complete_disputed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_test(self):
6565
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6666
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
6767
listing_json["metadata"]["acceptedCurrencies"] = ["t" + self.cointype]
68-
if self.vendor_version == 4:
68+
if self.vendor_version == "v4":
6969
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
7070
else:
7171
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

@@ -187,7 +187,7 @@ def run_test(self):
187187
resp = json.loads(r.text)
188188
raise TestFailure("CompleteDisputedTest - FAIL: Fulfillment POST failed. Reason: %s", resp["reason"])
189189
time.sleep(4)
190-
190+
191191
# Bob open dispute
192192
dispute = {
193193
"orderId": orderId,
@@ -297,7 +297,7 @@ def run_test(self):
297297
confirmed = int(resp["confirmed"])
298298
#unconfirmed = int(resp["unconfirmed"])
299299
amt = 0
300-
if self.buyer_version == 4:
300+
if self.buyer_version == "v4":
301301
amt = payment_amount
302302
else:
303303
amt = int(payment_amount["amount"])

qa/complete_moderated_with_timeout.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def run_test(self):
6363
# post listing to alice
6464
with open('testdata/'+ self.vendor_version +'/listing.json') as listing_file:
6565
listing_json = json.load(listing_file, object_pairs_hook=OrderedDict)
66-
if self.vendor_version == 4:
66+
if self.vendor_version == "v4":
6767
listing_json["metadata"]["priceCurrency"] = "t" + self.cointype
6868
else:
6969
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

repo/dispute_case_record.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ func (r *DisputeCaseRecord) ResolutionPaymentFeePerByte(ratio PayoutRatio, defau
107107
n := new(big.Int)
108108
switch {
109109
case ratio.BuyerMajority(), ratio.EvenMajority():
110-
n, _ = n.SetString(r.BuyerContract.BuyerOrder.BigRefundFee, 10)
110+
v5order, _ := ToV5Order(r.BuyerContract.BuyerOrder, nil)
111+
n, _ = n.SetString(v5order.BigRefundFee, 10)
111112
return n
112113
case ratio.VendorMajority():
113114
if len(r.VendorContract.VendorOrderFulfillment) > 0 && r.VendorContract.VendorOrderFulfillment[0].Payout != nil {

0 commit comments

Comments
 (0)