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

Commit 67699a1

Browse files
committed
Merge branch 'master' into compatibilitytest
2 parents 5da4d62 + aa0fd46 commit 67699a1

File tree

6 files changed

+104
-43
lines changed

6 files changed

+104
-43
lines changed

api/endpoints.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func post(i *jsonAPIHandler, path string, w http.ResponseWriter, r *http.Request
115115
i.POSTBulkUpdateCurrency(w, r)
116116
case strings.HasPrefix(path, "/ob/resendordermessage"):
117117
i.POSTResendOrderMessage(w, r)
118+
case strings.HasPrefix(path, "/ob/hashmessage"):
119+
i.POSTHashMessage(w, r)
118120
default:
119121
ErrorResponse(w, http.StatusNotFound, "Not Found")
120122
}

api/jsonapi.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,3 +4406,26 @@ func (i *jsonAPIHandler) GETScanOfflineMessages(w http.ResponseWriter, r *http.R
44064406
}
44074407
SanitizedResponse(w, `{}`)
44084408
}
4409+
4410+
func (i *jsonAPIHandler) POSTHashMessage(w http.ResponseWriter, r *http.Request) {
4411+
type hashRequest struct {
4412+
Content string `json:"content"`
4413+
}
4414+
var (
4415+
req hashRequest
4416+
err = json.NewDecoder(r.Body).Decode(&req)
4417+
)
4418+
if err != nil {
4419+
ErrorResponse(w, http.StatusBadRequest, err.Error())
4420+
return
4421+
}
4422+
4423+
messageHash, err := ipfs.EncodeMultihash([]byte(req.Content))
4424+
if err != nil {
4425+
ErrorResponse(w, http.StatusBadRequest, err.Error())
4426+
return
4427+
}
4428+
4429+
SanitizedResponse(w, fmt.Sprintf(`{"hash": "%s"}`,
4430+
messageHash.B58String()))
4431+
}

core/disputes.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,12 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
12101210

12111211
peerID := order.BuyerID.PeerID
12121212

1213+
// Build, sign, and broadcast transaction
1214+
txnID, err := wal.Multisign(inputs, outputs, mySigs, moderatorSigs, redeemScriptBytes, *big.NewInt(0), true)
1215+
if err != nil {
1216+
return err
1217+
}
1218+
12131219
// Update database
12141220
if n.IpfsNode.Identity.Pretty() == order.BuyerID.PeerID {
12151221
err = n.Datastore.Purchases().Put(orderID, *contract, pb.OrderState_DECIDED, true)
@@ -1221,12 +1227,6 @@ func (n *OpenBazaarNode) ReleaseFunds(contract *pb.RicardianContract, records []
12211227
log.Errorf("ReleaseFunds error updating database: %s", err.Error())
12221228
}
12231229

1224-
// Build, sign, and broadcast transaction
1225-
txnID, err := wal.Multisign(inputs, outputs, mySigs, moderatorSigs, redeemScriptBytes, *big.NewInt(0), true)
1226-
if err != nil {
1227-
return err
1228-
}
1229-
12301230
err = n.SendOrderPayment(&SpendResponse{
12311231
Txid: util.NormalizeAddress(hexutil.Encode(txnID)),
12321232
Currency: &currencyDef,

net/service/handlers.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,11 +1520,19 @@ func (service *OpenBazaarService) handleDisputeClose(p peer.ID, pmes *pb.Message
15201520
return nil, err
15211521
}
15221522

1523+
// If DisputeAcceptance is already set then move the state directly to RESOLVED
15231524
if isPurchase {
1524-
// Set message state to complete
1525-
err = service.datastore.Purchases().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_DECIDED, false)
1525+
if contract.DisputeAcceptance != nil {
1526+
err = service.datastore.Purchases().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_RESOLVED, false)
1527+
} else {
1528+
err = service.datastore.Purchases().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_DECIDED, false)
1529+
}
15261530
} else {
1527-
err = service.datastore.Sales().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_DECIDED, false)
1531+
if contract.DisputeAcceptance != nil {
1532+
err = service.datastore.Sales().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_RESOLVED, false)
1533+
} else {
1534+
err = service.datastore.Sales().Put(rc.DisputeResolution.OrderId, *contract, pb.OrderState_DECIDED, false)
1535+
}
15281536
}
15291537
if err != nil {
15301538
return nil, err

vendor/github.com/OpenBazaar/go-ethwallet/wallet/wallet.go

Lines changed: 44 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wallet/listeners/transaction_listener.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (l *TransactionListener) OnTransactionReceived(cb wallet.TransactionCallbac
129129
log.Errorf("update funding for sale (%s): %s", orderId, err)
130130
}
131131
// This is a dispute payout. We should set the order state.
132-
if state == pb.OrderState_DECIDED && len(records) > 0 && fundsReleased {
132+
if len(records) > 0 && fundsReleased {
133133
if contract.DisputeAcceptance == nil && contract != nil && contract.BuyerOrder != nil && contract.BuyerOrder.BuyerID != nil {
134134
accept := new(pb.DisputeAcceptance)
135135
ts, _ := ptypes.TimestampProto(time.Now())
@@ -154,16 +154,22 @@ func (l *TransactionListener) OnTransactionReceived(cb wallet.TransactionCallbac
154154
log.Errorf("persist dispute acceptance notification for order (%s): %s", orderId, err)
155155
}
156156
}
157-
if err := l.db.Sales().Put(orderId, *contract, pb.OrderState_RESOLVED, false); err != nil {
158-
log.Errorf("failed updating order (%s) to RESOLVED: %s", orderId, err.Error())
157+
if state == pb.OrderState_DECIDED {
158+
if err := l.db.Sales().Put(orderId, *contract, pb.OrderState_RESOLVED, false); err != nil {
159+
log.Errorf("failed updating order (%s) to RESOLVED: %s", orderId, err.Error())
160+
}
161+
} else {
162+
if err := l.db.Sales().Put(orderId, *contract, state, false); err != nil {
163+
log.Errorf("failed updating order (%s) with DisputeAcceptance: %s", orderId, err.Error())
164+
}
159165
}
160166
}
161167
} else {
162168
err = l.db.Purchases().UpdateFunding(orderId, funded, records)
163169
if err != nil {
164170
log.Errorf("update funding for purchase (%s): %s", orderId, err)
165171
}
166-
if state == pb.OrderState_DECIDED && len(records) > 0 && fundsReleased {
172+
if len(records) > 0 && fundsReleased {
167173
if contract.DisputeAcceptance == nil && contract != nil && len(contract.VendorListings) > 0 && contract.VendorListings[0].VendorID != nil {
168174
accept := new(pb.DisputeAcceptance)
169175
ts, _ := ptypes.TimestampProto(time.Now())
@@ -192,8 +198,14 @@ func (l *TransactionListener) OnTransactionReceived(cb wallet.TransactionCallbac
192198
log.Errorf("persist dispute acceptance notification for order (%s): %s", orderId, err)
193199
}
194200
}
195-
if err := l.db.Purchases().Put(orderId, *contract, pb.OrderState_RESOLVED, false); err != nil {
196-
log.Errorf("failed updating order (%s) to RESOLVED: %s", orderId, err.Error())
201+
if state == pb.OrderState_DECIDED {
202+
if err := l.db.Purchases().Put(orderId, *contract, pb.OrderState_RESOLVED, false); err != nil {
203+
log.Errorf("failed updating order (%s) to RESOLVED: %s", orderId, err.Error())
204+
}
205+
} else {
206+
if err := l.db.Purchases().Put(orderId, *contract, state, false); err != nil {
207+
log.Errorf("failed updating order (%s) with DisputeAcceptance: %s", orderId, err.Error())
208+
}
197209
}
198210
}
199211
}

0 commit comments

Comments
 (0)