diff --git a/api/jsonapi.go b/api/jsonapi.go index 9534d36d97..e66d7f21f4 100644 --- a/api/jsonapi.go +++ b/api/jsonapi.go @@ -2096,21 +2096,26 @@ func (i *jsonAPIHandler) POSTOpenDispute(w http.ResponseWriter, r *http.Request) } func (i *jsonAPIHandler) POSTCloseDispute(w http.ResponseWriter, r *http.Request) { - type dispute struct { + type disputeParams struct { OrderID string `json:"orderId"` Resolution string `json:"resolution"` BuyerPercentage float32 `json:"buyerPercentage"` VendorPercentage float32 `json:"vendorPercentage"` } decoder := json.NewDecoder(r.Body) - var d dispute + var d disputeParams err := decoder.Decode(&d) if err != nil { ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - err = i.node.CloseDispute(d.OrderID, d.BuyerPercentage, d.VendorPercentage, d.Resolution) + disputeCase, err := i.node.Datastore.Cases().GetByCaseID(d.OrderID) + if err != nil { + ErrorResponse(w, http.StatusNotFound, err.Error()) + } + + err = i.node.CloseDispute(disputeCase.CaseID, d.BuyerPercentage, d.VendorPercentage, d.Resolution, disputeCase.PaymentCoin) if err != nil { switch err { case core.ErrCaseNotFound: diff --git a/api/jsonapi_test.go b/api/jsonapi_test.go index 07b954ac67..a0dab76c90 100644 --- a/api/jsonapi_test.go +++ b/api/jsonapi_test.go @@ -513,8 +513,10 @@ func TestPosts(t *testing.T) { func TestCloseDisputeBlocksWhenExpired(t *testing.T) { dbSetup := func(testRepo *test.Repository) error { + paymentCoin := repo.CurrencyCode("BTC") expired := factory.NewExpiredDisputeCaseRecord() expired.CaseID = "expiredCase" + expired.PaymentCoin = &paymentCoin for _, r := range []*repo.DisputeCaseRecord{expired} { if err := testRepo.DB.Cases().PutRecord(r); err != nil { return err diff --git a/core/disputes.go b/core/disputes.go index b970952921..c6848351c5 100644 --- a/core/disputes.go +++ b/core/disputes.go @@ -433,7 +433,7 @@ func (n *OpenBazaarNode) ProcessDisputeOpen(rc *pb.RicardianContract, peerID str } // CloseDispute - close a dispute -func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPercentage float32, resolution string) error { +func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPercentage float32, resolution string, paymentCoinHint *repo.CurrencyCode) error { var payDivision = repo.PayoutRatio{Buyer: buyerPercentage, Vendor: vendorPercentage} if err := payDivision.Validate(); err != nil { return err @@ -468,6 +468,12 @@ func (n *OpenBazaarNode) CloseDispute(orderID string, buyerPercentage, vendorPer } preferredContract := dispute.ResolutionPaymentContract(payDivision) + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(preferredContract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", orderID) + preferredContract.BuyerOrder.Payment.Coin = paymentCoinHint.String() + } + var d = new(pb.DisputeResolution) // Add timestamp