|
22 | 22 | import com.google.inject.Singleton; |
23 | 23 | import com.google.inject.name.Named; |
24 | 24 |
|
25 | | -import haveno.common.ThreadUtils; |
26 | 25 | import haveno.common.crypto.KeyRing; |
27 | 26 | import haveno.common.crypto.PubKeyRing; |
28 | 27 | import haveno.common.handlers.FaultHandler; |
@@ -101,57 +100,51 @@ public Dispute getDispute(String tradeId) { |
101 | 100 | public void openDispute(String tradeId, ResultHandler resultHandler, FaultHandler faultHandler) { |
102 | 101 | Trade trade = tradeManager.getOpenTrade(tradeId).orElseThrow(() -> |
103 | 102 | new IllegalArgumentException(format("trade with id '%s' not found", tradeId))); |
104 | | - |
105 | | - // open dispute on trade thread |
106 | | - ThreadUtils.execute(() -> { |
107 | | - Offer offer = trade.getOffer(); |
108 | | - if (offer == null) throw new IllegalStateException(format("offer with tradeId '%s' is null", tradeId)); |
109 | | - |
110 | | - // Dispute agents are registered as mediators and refund agents, but current UI appears to be hardcoded |
111 | | - // to reference the arbitrator. Reference code is in desktop PendingTradesDataModel.java and could be refactored. |
112 | | - var disputeManager = arbitrationManager; |
113 | | - var isSupportTicket = false; |
114 | | - var isMaker = tradeManager.isMyOffer(offer); |
115 | | - var dispute = createDisputeForTrade(trade, offer, keyRing.getPubKeyRing(), isMaker, isSupportTicket); |
116 | | - |
117 | | - // Sends the openNewDisputeMessage to arbitrator, who will then create 2 disputes |
118 | | - // one for the opener, the other for the peer, see sendPeerOpenedDisputeMessage. |
119 | | - disputeManager.sendDisputeOpenedMessage(dispute, resultHandler, faultHandler); |
120 | | - tradeManager.requestPersistence(); |
121 | | - }, trade.getId()); |
| 103 | + Offer offer = trade.getOffer(); |
| 104 | + if (offer == null) throw new IllegalStateException(format("offer with tradeId '%s' is null", tradeId)); |
| 105 | + |
| 106 | + // Dispute agents are registered as mediators and refund agents, but current UI appears to be hardcoded |
| 107 | + // to reference the arbitrator. Reference code is in desktop PendingTradesDataModel.java and could be refactored. |
| 108 | + var disputeManager = arbitrationManager; |
| 109 | + var isSupportTicket = false; |
| 110 | + var isMaker = tradeManager.isMyOffer(offer); |
| 111 | + var dispute = createDisputeForTrade(trade, offer, keyRing.getPubKeyRing(), isMaker, isSupportTicket); |
| 112 | + |
| 113 | + // Sends the openNewDisputeMessage to arbitrator, who will then create 2 disputes |
| 114 | + // one for the opener, the other for the peer, see sendPeerOpenedDisputeMessage. |
| 115 | + disputeManager.sendDisputeOpenedMessage(dispute, resultHandler, faultHandler); |
| 116 | + tradeManager.requestPersistence(); |
122 | 117 | } |
123 | 118 |
|
124 | 119 | public Dispute createDisputeForTrade(Trade trade, Offer offer, PubKeyRing pubKey, boolean isMaker, boolean isSupportTicket) { |
125 | | - synchronized (trade.getLock()) { |
126 | | - byte[] payoutTxSerialized = null; |
127 | | - String payoutTxHashAsString = null; |
128 | | - |
129 | | - PubKeyRing arbitratorPubKeyRing = trade.getArbitrator().getPubKeyRing(); |
130 | | - checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null"); |
131 | | - Dispute dispute = new Dispute(new Date().getTime(), |
132 | | - trade.getId(), |
133 | | - pubKey.hashCode(), // trader id, |
134 | | - true, |
135 | | - (offer.getDirection() == OfferDirection.BUY) == isMaker, |
136 | | - isMaker, |
137 | | - pubKey, |
138 | | - trade.getDate().getTime(), |
139 | | - trade.getMaxTradePeriodDate().getTime(), |
140 | | - trade.getContract(), |
141 | | - trade.getContractHash(), |
142 | | - payoutTxSerialized, |
143 | | - payoutTxHashAsString, |
144 | | - trade.getContractAsJson(), |
145 | | - trade.getMaker().getContractSignature(), |
146 | | - trade.getTaker().getContractSignature(), |
147 | | - trade.getMaker().getPaymentAccountPayload(), |
148 | | - trade.getTaker().getPaymentAccountPayload(), |
149 | | - arbitratorPubKeyRing, |
150 | | - isSupportTicket, |
151 | | - SupportType.ARBITRATION); |
152 | | - |
153 | | - return dispute; |
154 | | - } |
| 120 | + byte[] payoutTxSerialized = null; |
| 121 | + String payoutTxHashAsString = null; |
| 122 | + |
| 123 | + PubKeyRing arbitratorPubKeyRing = trade.getArbitrator().getPubKeyRing(); |
| 124 | + checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must not be null"); |
| 125 | + Dispute dispute = new Dispute(new Date().getTime(), |
| 126 | + trade.getId(), |
| 127 | + pubKey.hashCode(), // trader id, |
| 128 | + true, |
| 129 | + (offer.getDirection() == OfferDirection.BUY) == isMaker, |
| 130 | + isMaker, |
| 131 | + pubKey, |
| 132 | + trade.getDate().getTime(), |
| 133 | + trade.getMaxTradePeriodDate().getTime(), |
| 134 | + trade.getContract(), |
| 135 | + trade.getContractHash(), |
| 136 | + payoutTxSerialized, |
| 137 | + payoutTxHashAsString, |
| 138 | + trade.getContractAsJson(), |
| 139 | + trade.getMaker().getContractSignature(), |
| 140 | + trade.getTaker().getContractSignature(), |
| 141 | + trade.getMaker().getPaymentAccountPayload(), |
| 142 | + trade.getTaker().getPaymentAccountPayload(), |
| 143 | + arbitratorPubKeyRing, |
| 144 | + isSupportTicket, |
| 145 | + SupportType.ARBITRATION); |
| 146 | + |
| 147 | + return dispute; |
155 | 148 | } |
156 | 149 |
|
157 | 150 | // TODO: does not wait for success or error response |
@@ -313,6 +306,7 @@ public void sendDisputeChatMessage(String disputeId, String message, ArrayList<A |
313 | 306 | Dispute dispute; |
314 | 307 | if (disputeOptional.isPresent()) dispute = disputeOptional.get(); |
315 | 308 | else throw new IllegalStateException(format("dispute with id '%s' not found", disputeId)); |
| 309 | + if (!arbitrationManager.canSendChatMessages(dispute)) throw new IllegalStateException(format("dispute with id '%s' cannot send chat messages (must be open or stored to mailbox)", disputeId)); |
316 | 310 | ChatMessage chatMessage = new ChatMessage( |
317 | 311 | arbitrationManager.getSupportType(), |
318 | 312 | dispute.getTradeId(), |
|
0 commit comments