diff --git a/api/jsonapi.go b/api/jsonapi.go index a564086aa1..e66d7f21f4 100644 --- a/api/jsonapi.go +++ b/api/jsonapi.go @@ -1544,11 +1544,18 @@ func (i *jsonAPIHandler) POSTOrderConfirmation(w http.ResponseWriter, r *http.Re ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - contract, state, funded, records, _, _, err := i.node.Datastore.Sales().GetByOrderId(conf.OrderID) + contract, state, funded, records, _, paymentCoin, err := i.node.Datastore.Sales().GetByOrderId(conf.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, err.Error()) return } + + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", conf.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if state != pb.OrderState_PENDING { ErrorResponse(w, http.StatusBadRequest, "order has already been confirmed") return @@ -1584,12 +1591,18 @@ func (i *jsonAPIHandler) POSTOrderCancel(w http.ResponseWriter, r *http.Request) ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - contract, state, _, records, _, _, err := i.node.Datastore.Purchases().GetByOrderId(can.OrderID) + contract, state, _, records, _, paymentCoin, err := i.node.Datastore.Purchases().GetByOrderId(can.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "order not found") return } + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", can.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if !((state == pb.OrderState_PENDING || state == pb.OrderState_PROCESSING_ERROR) && len(records) > 0) || !(state == pb.OrderState_PENDING || state == pb.OrderState_PROCESSING_ERROR) || contract.BuyerOrder.Payment.Method == pb.Order_Payment_MODERATED { ErrorResponse(w, http.StatusBadRequest, "order must be PENDING or PROCESSING_ERROR and only a direct payment to cancel") return @@ -1721,7 +1734,7 @@ func (i *jsonAPIHandler) POSTRefund(w http.ResponseWriter, r *http.Request) { ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - contract, state, _, records, _, _, err := i.node.Datastore.Sales().GetByOrderId(can.OrderID) + contract, state, _, records, _, paymentCoin, err := i.node.Datastore.Sales().GetByOrderId(can.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "order not found") return @@ -1730,6 +1743,13 @@ func (i *jsonAPIHandler) POSTRefund(w http.ResponseWriter, r *http.Request) { ErrorResponse(w, http.StatusBadRequest, "order must be AWAITING_FULFILLMENT, or PARTIALLY_FULFILLED") return } + + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", can.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + err = i.node.RefundOrder(contract, records) if err != nil { ErrorResponse(w, http.StatusInternalServerError, err.Error()) @@ -1911,11 +1931,18 @@ func (i *jsonAPIHandler) POSTOrderFulfill(w http.ResponseWriter, r *http.Request ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - contract, state, _, records, _, _, err := i.node.Datastore.Sales().GetByOrderId(fulfill.OrderId) + contract, state, _, records, _, paymentCoin, err := i.node.Datastore.Sales().GetByOrderId(fulfill.OrderId) if err != nil { ErrorResponse(w, http.StatusNotFound, "order not found") return } + + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", fulfill.OrderId) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if state != pb.OrderState_AWAITING_FULFILLMENT && state != pb.OrderState_PARTIALLY_FULFILLED { ErrorResponse(w, http.StatusBadRequest, "order must be in state AWAITING_FULFILLMENT or PARTIALLY_FULFILLED to fulfill") return @@ -1943,12 +1970,18 @@ func (i *jsonAPIHandler) POSTOrderComplete(w http.ResponseWriter, r *http.Reques ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - contract, state, _, records, _, _, err := i.node.Datastore.Purchases().GetByOrderId(or.OrderID) + contract, state, _, records, _, paymentCoin, err := i.node.Datastore.Purchases().GetByOrderId(or.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "order not found") return } + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", or.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if state != pb.OrderState_FULFILLED && state != pb.OrderState_RESOLVED && state != pb.OrderState_PAYMENT_FINALIZED { @@ -2012,19 +2045,29 @@ func (i *jsonAPIHandler) POSTOpenDispute(w http.ResponseWriter, r *http.Request) ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - var isSale bool - var contract *pb.RicardianContract - var state pb.OrderState - var records []*wallet.TransactionRecord - contract, state, _, records, _, _, err = i.node.Datastore.Purchases().GetByOrderId(d.OrderID) + var ( + isSale bool + contract *pb.RicardianContract + state pb.OrderState + records []*wallet.TransactionRecord + paymentCoin *repo.CurrencyCode + ) + contract, state, _, records, _, paymentCoin, err = i.node.Datastore.Purchases().GetByOrderId(d.OrderID) if err != nil { - contract, state, _, records, _, _, err = i.node.Datastore.Sales().GetByOrderId(d.OrderID) + contract, state, _, records, _, paymentCoin, err = i.node.Datastore.Sales().GetByOrderId(d.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "Order not found") return } isSale = true } + + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", d.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if contract.BuyerOrder.Payment.Method != pb.Order_Payment_MODERATED { ErrorResponse(w, http.StatusBadRequest, "Only moderated orders can be disputed") return @@ -2053,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: @@ -2141,17 +2189,27 @@ func (i *jsonAPIHandler) POSTReleaseFunds(w http.ResponseWriter, r *http.Request ErrorResponse(w, http.StatusBadRequest, err.Error()) return } - var contract *pb.RicardianContract - var state pb.OrderState - var records []*wallet.TransactionRecord - contract, state, _, records, _, _, err = i.node.Datastore.Purchases().GetByOrderId(rel.OrderID) + var ( + contract *pb.RicardianContract + state pb.OrderState + records []*wallet.TransactionRecord + paymentCoin *repo.CurrencyCode + ) + contract, state, _, records, _, paymentCoin, err = i.node.Datastore.Purchases().GetByOrderId(rel.OrderID) if err != nil { - contract, state, _, records, _, _, err = i.node.Datastore.Sales().GetByOrderId(rel.OrderID) + contract, state, _, records, _, paymentCoin, err = i.node.Datastore.Sales().GetByOrderId(rel.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "Order not found") return } } + + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", rel.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if state == pb.OrderState_DECIDED { err = i.node.ReleaseFunds(contract, records) if err != nil { @@ -2170,9 +2228,10 @@ func (i *jsonAPIHandler) POSTReleaseEscrow(w http.ResponseWriter, r *http.Reques rel struct { OrderID string `json:"orderId"` } - contract *pb.RicardianContract - state pb.OrderState - records []*wallet.TransactionRecord + contract *pb.RicardianContract + state pb.OrderState + records []*wallet.TransactionRecord + paymentCoin *repo.CurrencyCode ) decoder := json.NewDecoder(r.Body) @@ -2182,12 +2241,18 @@ func (i *jsonAPIHandler) POSTReleaseEscrow(w http.ResponseWriter, r *http.Reques return } - contract, state, _, records, _, _, err = i.node.Datastore.Sales().GetByOrderId(rel.OrderID) + contract, state, _, records, _, paymentCoin, err = i.node.Datastore.Sales().GetByOrderId(rel.OrderID) if err != nil { ErrorResponse(w, http.StatusNotFound, "Order not found") return } + // TODO: Remove once broken contracts are migrated + if _, err := repo.NewCurrencyCode(contract.BuyerOrder.Payment.Coin); err != nil { + log.Warningf("missing contract BuyerOrder.Payment.Coin on order (%s)", rel.OrderID) + contract.BuyerOrder.Payment.Coin = paymentCoin.String() + } + if state != pb.OrderState_PENDING && state != pb.OrderState_FULFILLED && state != pb.OrderState_DISPUTED { ErrorResponse(w, http.StatusBadRequest, "Release escrow can only be called when sale is pending, fulfilled, or disputed") return diff --git a/api/jsonapi_test.go b/api/jsonapi_test.go index 04a61b2b76..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 @@ -652,12 +654,13 @@ func TestPurchasesGet(t *testing.T) { } func TestCasesGet(t *testing.T) { + paymentCoinCode := repo.CurrencyCode("BTC") disputeCaseRecord := factory.NewDisputeCaseRecord() disputeCaseRecord.BuyerContract.VendorListings[0].Metadata.AcceptedCurrencies = []string{"BTC"} disputeCaseRecord.BuyerContract.VendorListings[0].Metadata.CoinType = "ZEC" disputeCaseRecord.BuyerContract.VendorListings[0].Metadata.ContractType = pb.Listing_Metadata_CRYPTOCURRENCY disputeCaseRecord.CoinType = "ZEC" - disputeCaseRecord.PaymentCoin = "BTC" + disputeCaseRecord.PaymentCoin = &paymentCoinCode dbSetup := func(testRepo *test.Repository) error { return testRepo.DB.Cases().PutRecord(disputeCaseRecord) } 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 diff --git a/repo/db/cases.go b/repo/db/cases.go index a2493bef6d..fd5b41d04c 100644 --- a/repo/db/cases.go +++ b/repo/db/cases.go @@ -50,7 +50,7 @@ func (c *CasesDB) PutRecord(dispute *repo.DisputeCaseRecord) error { dispute.Claim, "", "", - dispute.PaymentCoin, + dispute.PaymentCoin.String(), dispute.CoinType, ) if err != nil { @@ -65,12 +65,16 @@ func (c *CasesDB) PutRecord(dispute *repo.DisputeCaseRecord) error { } func (c *CasesDB) Put(caseID string, state pb.OrderState, buyerOpened bool, claim string, paymentCoin string, coinType string) error { + paymentCoinCode, err := repo.NewCurrencyCode(paymentCoin) + if err != nil { + return fmt.Errorf("verifying paymentCoin: %s", err.Error()) + } record := &repo.DisputeCaseRecord{ CaseID: caseID, Claim: claim, IsBuyerInitiated: buyerOpened, OrderState: state, - PaymentCoin: paymentCoin, + PaymentCoin: paymentCoinCode, CoinType: coinType, Timestamp: time.Now(), } @@ -388,22 +392,30 @@ func (c *CasesDB) GetCaseMetadata(caseID string) (buyerContract, vendorContract func (c *CasesDB) GetByCaseID(caseID string) (*repo.DisputeCaseRecord, error) { c.lock.Lock() defer c.lock.Unlock() - var buyerCon []byte - var vendorCon []byte - var buyerOuts []byte - var vendorOuts []byte - var buyerAddr string - var vendorAddr string - var stateInt int - var isBuyerInitiated int - var buyerInitiated bool - var createdAt int64 + var ( + buyerAddr string + buyerCon []byte + buyerInitiated bool + buyerOuts []byte + createdAt int64 + isBuyerInitiated int + paymentCoin string + stateInt int + vendorAddr string + vendorCon []byte + vendorOuts []byte + ) - stmt, err := c.db.Prepare("select buyerContract, vendorContract, buyerPayoutAddress, vendorPayoutAddress, buyerOutpoints, vendorOutpoints, state, buyerOpened, timestamp from cases where caseID=?") + stmt, err := c.db.Prepare("select buyerContract, vendorContract, buyerPayoutAddress, vendorPayoutAddress, buyerOutpoints, vendorOutpoints, state, buyerOpened, timestamp, paymentCoin from cases where caseID=?") if err != nil { return nil, err } - err = stmt.QueryRow(caseID).Scan(&buyerCon, &vendorCon, &buyerAddr, &vendorAddr, &buyerOuts, &vendorOuts, &stateInt, &isBuyerInitiated, &createdAt) + err = stmt.QueryRow(caseID).Scan(&buyerCon, &vendorCon, &buyerAddr, &vendorAddr, &buyerOuts, &vendorOuts, &stateInt, &isBuyerInitiated, &createdAt, &paymentCoin) + if err != nil { + return nil, err + } + + paymentCoinCode, err := repo.NewCurrencyCode(paymentCoin) if err != nil { return nil, err } @@ -458,16 +470,17 @@ func (c *CasesDB) GetByCaseID(caseID string) (*repo.DisputeCaseRecord, error) { return ret } return &repo.DisputeCaseRecord{ - CaseID: caseID, - IsBuyerInitiated: buyerInitiated, BuyerContract: brc, - BuyerPayoutAddress: buyerAddr, BuyerOutpoints: toPointer(buyerOutpointsOut), - VendorContract: vrc, - VendorPayoutAddress: vendorAddr, - VendorOutpoints: toPointer(vendorOutpointsOut), + BuyerPayoutAddress: buyerAddr, + CaseID: caseID, + IsBuyerInitiated: buyerInitiated, OrderState: pb.OrderState(stateInt), + PaymentCoin: paymentCoinCode, Timestamp: time.Unix(createdAt, 0), + VendorContract: vrc, + VendorOutpoints: toPointer(vendorOutpointsOut), + VendorPayoutAddress: vendorAddr, }, nil } diff --git a/repo/db/cases_test.go b/repo/db/cases_test.go index 3625f79655..a8128c15de 100644 --- a/repo/db/cases_test.go +++ b/repo/db/cases_test.go @@ -46,7 +46,7 @@ func TestCasesDB_Count(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 5, true, "blah", "", "btc") + err = casesdb.Put("caseID", 5, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -71,7 +71,7 @@ func TestPutCase(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -111,7 +111,7 @@ func TestUpdateWithNil(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -125,7 +125,7 @@ func TestUpdateWithNil(t *testing.T) { } buyerContract, _, _, _, _, _, _, _, _, _, err := casesdb.GetCaseMetadata("caseID") if err != nil { - t.Error(err) + t.Fatal(err) } if buyerContract != nil { t.Error("Vendor contract was not nil") @@ -144,7 +144,7 @@ func TestDeleteCase(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -172,7 +172,7 @@ func TestMarkCaseAsRead(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -202,7 +202,7 @@ func TestMarkCaseAsUnread(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -238,7 +238,7 @@ func TestUpdateBuyerInfo(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -290,7 +290,7 @@ func TestUpdateVendorInfo(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 0, true, "blah", "", "btc") + err = casesdb.Put("caseID", 0, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -343,7 +343,7 @@ func TestCasesGetCaseMetaData(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", "", "btc") + err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -407,6 +407,7 @@ func TestCasesGetCaseMetaData(t *testing.T) { func TestGetByCaseID(t *testing.T) { var ( + expectedPaymentCoin = "BCH" casesdb, teardown, err = buildNewCaseStore() contract = factory.NewContract() expectedBuyerOutpoints = []*pb.Outpoint{{Hash: "hash1", Index: 0, Value: 5}} @@ -417,7 +418,7 @@ func TestGetByCaseID(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", "", "btc") + err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", expectedPaymentCoin, "btc") if err != nil { t.Error(err) } @@ -478,6 +479,9 @@ func TestGetByCaseID(t *testing.T) { if dispute.OrderState != pb.OrderState_DISPUTED { t.Errorf("Expected state %s got %s", pb.OrderState_DISPUTED, dispute.OrderState) } + if dispute.PaymentCoin.String() != expectedPaymentCoin { + t.Errorf("Expected paymentCoin %s got %s", expectedPaymentCoin, dispute.PaymentCoin.String()) + } } func TestMarkAsClosed(t *testing.T) { @@ -492,7 +496,7 @@ func TestMarkAsClosed(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", "", "btc") + err = casesdb.Put("caseID", pb.OrderState_DISPUTED, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -512,7 +516,7 @@ func TestMarkAsClosed(t *testing.T) { } _, _, _, _, state, _, _, _, _, resolution, err := casesdb.GetCaseMetadata("caseID") if err != nil { - t.Error(err) + t.Fatal(err) } if state != pb.OrderState_RESOLVED { t.Error("Mark as closed failed to set state to resolved") @@ -534,7 +538,7 @@ func TestCasesDB_GetAll(t *testing.T) { } defer teardown() - err = casesdb.Put("caseID", 10, true, "blah", "", "btc") + err = casesdb.Put("caseID", 10, true, "blah", "btc", "btc") if err != nil { t.Error(err) } @@ -547,7 +551,7 @@ func TestCasesDB_GetAll(t *testing.T) { t.Error(err) } time.Sleep(time.Second) - err = casesdb.Put("caseID2", 11, true, "asdf", "", "btc") + err = casesdb.Put("caseID2", 11, true, "asdf", "btc", "btc") if err != nil { t.Error(err) } @@ -969,7 +973,6 @@ func TestCasesDB_Put_PaymentCoin(t *testing.T) { {[]string{"TBTC", "TBCH"}, "TBTC", "TBTC"}, {[]string{"TBCH", "TBTC"}, "TBTC", "TBTC"}, {[]string{"TBTC", "TBCH"}, "TBCH", "TBCH"}, - {[]string{}, "", ""}, } contract = factory.NewContract() ) @@ -982,13 +985,17 @@ func TestCasesDB_Put_PaymentCoin(t *testing.T) { contract.VendorListings[0].Metadata.AcceptedCurrencies = test.acceptedCurrencies contract.BuyerOrder.Payment.Coin = test.paymentCoin + paymentCoin, err := repo.NewCurrencyCode(test.paymentCoin) + if err != nil { + t.Fatal(err) + } err = casesdb.PutRecord(&repo.DisputeCaseRecord{ CaseID: "paymentCoinTest", BuyerContract: contract, VendorContract: contract, IsBuyerInitiated: true, - PaymentCoin: test.paymentCoin, + PaymentCoin: paymentCoin, }) if err != nil { t.Error(err) @@ -1010,7 +1017,7 @@ func TestCasesDB_Put_PaymentCoin(t *testing.T) { func TestCasesDB_Put_CoinType(t *testing.T) { var ( - testsCoins = []string{"", "TBTC", "TETH"} + testsCoins = []string{"TBTC", "TETH"} contract = factory.NewContract() ) @@ -1020,6 +1027,10 @@ func TestCasesDB_Put_CoinType(t *testing.T) { t.Fatal(err) } + paymentCoinCode, err := repo.NewCurrencyCode(testCoin) + if err != nil { + t.Fatal(err) + } contract.VendorListings[0].Metadata.CoinType = testCoin err = casesdb.PutRecord(&repo.DisputeCaseRecord{ @@ -1028,6 +1039,7 @@ func TestCasesDB_Put_CoinType(t *testing.T) { VendorContract: contract, IsBuyerInitiated: true, CoinType: testCoin, + PaymentCoin: paymentCoinCode, }) if err != nil { t.Error(err) diff --git a/repo/dispute_case_record.go b/repo/dispute_case_record.go index 426046b681..593bb12db6 100644 --- a/repo/dispute_case_record.go +++ b/repo/dispute_case_record.go @@ -29,7 +29,7 @@ type DisputeCaseRecord struct { VendorPayoutAddress string IsBuyerInitiated bool CoinType string - PaymentCoin string + PaymentCoin *CurrencyCode } // BuildModeratorDisputeExpiryFirstNotification returns a Notification with ExpiresIn set for the First Interval