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

Commit 15bf638

Browse files
authored
Merge pull request #2042 from OpenBazaar/compatibilitytest
Compatibilitytest
2 parents aa0fd46 + 9181503 commit 15bf638

File tree

81 files changed

+1741
-925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1741
-925
lines changed

api/jsonapi.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,9 +1675,14 @@ func (i *jsonAPIHandler) POSTOrderCancel(w http.ResponseWriter, r *http.Request)
16751675
ErrorResponse(w, http.StatusNotFound, "order not found")
16761676
return
16771677
}
1678+
v5order, err := repo.ToV5Order(contract.BuyerOrder, nil)
1679+
if err != nil {
1680+
ErrorResponse(w, http.StatusNotFound, "order not found")
1681+
return
1682+
}
16781683

16791684
// TODO: Remove once broken contracts are migrated
1680-
lookupCoin := contract.BuyerOrder.Payment.AmountCurrency.Code
1685+
lookupCoin := v5order.Payment.AmountCurrency.Code
16811686
_, err = i.node.LookupCurrency(lookupCoin)
16821687
if err != nil {
16831688
log.Warningf("invalid BuyerOrder.Payment.Coin (%s) on order (%s)", lookupCoin, can.OrderID)
@@ -2022,8 +2027,14 @@ func (i *jsonAPIHandler) POSTOrderComplete(w http.ResponseWriter, r *http.Reques
20222027
return
20232028
}
20242029

2030+
v5order, err := repo.ToV5Order(contract.BuyerOrder, nil)
2031+
if err != nil {
2032+
ErrorResponse(w, http.StatusNotFound, "order not found")
2033+
return
2034+
}
2035+
20252036
// TODO: Remove once broken contracts are migrated
2026-
lookupCoin := contract.BuyerOrder.Payment.AmountCurrency.Code
2037+
lookupCoin := v5order.Payment.AmountCurrency.Code
20272038
_, err = i.node.LookupCurrency(lookupCoin)
20282039
if err != nil {
20292040
log.Warningf("invalid BuyerOrder.Payment.Coin (%s) on order (%s)", lookupCoin, or.OrderID)
@@ -2111,7 +2122,13 @@ func (i *jsonAPIHandler) POSTOpenDispute(w http.ResponseWriter, r *http.Request)
21112122
}
21122123

21132124
// TODO: Remove once broken contracts are migrated
2114-
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
21152132
_, err = i.node.LookupCurrency(lookupCoin)
21162133
if err != nil {
21172134
log.Warningf("invalid BuyerOrder.Payment.Coin (%s) on order (%s)", lookupCoin, d.OrderID)
@@ -2257,8 +2274,14 @@ func (i *jsonAPIHandler) POSTReleaseFunds(w http.ResponseWriter, r *http.Request
22572274
}
22582275
}
22592276

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

core/disputes.go

Lines changed: 56 additions & 18 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,
@@ -738,25 +762,39 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer
738762
if out, ok := outMap["buyer"]; ok {
739763
payout.BuyerOutput = &pb.DisputeResolution_Payout_Output{
740764
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: buyerAddr.String()},
741-
BigAmount: out.Value.String(),
765+
}
766+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
767+
payout.BuyerOutput.BigAmount = out.Value.String()
768+
} else {
769+
payout.BuyerOutput.Amount = out.Value.Uint64()
742770
}
743771
}
744772
if out, ok := outMap["vendor"]; ok {
745773
payout.VendorOutput = &pb.DisputeResolution_Payout_Output{
746774
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: vendorAddr.String()},
747-
BigAmount: out.Value.String(),
775+
}
776+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
777+
payout.VendorOutput.BigAmount = out.Value.String()
778+
} else {
779+
payout.VendorOutput.Amount = out.Value.Uint64()
748780
}
749781
}
750782
if out, ok := outMap["moderator"]; ok {
751783
payout.ModeratorOutput = &pb.DisputeResolution_Payout_Output{
752784
ScriptOrAddress: &pb.DisputeResolution_Payout_Output_Address{Address: modAddr.String()},
753-
BigAmount: out.Value.String(),
785+
}
786+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
787+
payout.ModeratorOutput.BigAmount = out.Value.String()
788+
} else {
789+
payout.ModeratorOutput.Amount = out.Value.Uint64()
754790
}
755791
}
756792

757-
payout.PayoutCurrency = &pb.CurrencyDefinition{
758-
Code: preferredOrder.Payment.AmountCurrency.Code,
759-
Divisibility: preferredOrder.Payment.AmountCurrency.Divisibility,
793+
if preferredContract.VendorListings[0].Metadata.Version >= repo.ListingVersion {
794+
payout.PayoutCurrency = &pb.CurrencyDefinition{
795+
Code: preferredOrder.Payment.AmountCurrency.Code,
796+
Divisibility: preferredOrder.Payment.AmountCurrency.Divisibility,
797+
}
760798
}
761799

762800
d.Payout = payout

0 commit comments

Comments
 (0)