Skip to content

Commit df4ae98

Browse files
committed
support deposits and payout finalization and recovery
1 parent 8d9f6b4 commit df4ae98

38 files changed

+500
-179
lines changed

core/src/main/java/haveno/core/api/CoreDisputesService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void applyPayoutAmountsToDisputeResult(PayoutSuggestion payoutSuggestion,
242242
disputeResult.setBuyerPayoutAmountBeforeCost(tradeAmount.add(buyerSecurityDeposit).add(sellerSecurityDeposit)); // TODO (woodser): apply min payout to incentivize loser? (see post v1.1.7)
243243
disputeResult.setSellerPayoutAmountBeforeCost(BigInteger.ZERO);
244244
if (disputeResult.getBuyerPayoutAmountBeforeCost().compareTo(trade.getWallet().getBalance()) > 0) { // in case peer's deposit transaction is not confirmed
245-
log.warn("Payout amount for buyer is more than wallet's balance. Decreasing payout amount from {} to {}",
245+
log.warn("Payout amount for buyer is more than wallet's balance. This can happen if a deposit tx is dropped. Decreasing payout amount from {} to {}",
246246
HavenoUtils.formatXmr(disputeResult.getBuyerPayoutAmountBeforeCost()),
247247
HavenoUtils.formatXmr(trade.getWallet().getBalance()));
248248
disputeResult.setBuyerPayoutAmountBeforeCost(trade.getWallet().getBalance());
@@ -254,7 +254,7 @@ public void applyPayoutAmountsToDisputeResult(PayoutSuggestion payoutSuggestion,
254254
disputeResult.setBuyerPayoutAmountBeforeCost(BigInteger.ZERO);
255255
disputeResult.setSellerPayoutAmountBeforeCost(tradeAmount.add(sellerSecurityDeposit).add(buyerSecurityDeposit));
256256
if (disputeResult.getSellerPayoutAmountBeforeCost().compareTo(trade.getWallet().getBalance()) > 0) { // in case peer's deposit transaction is not confirmed
257-
log.warn("Payout amount for seller is more than wallet's balance. Decreasing payout amount from {} to {}",
257+
log.warn("Payout amount for seller is more than wallet's balance. This can happen if a deposit tx is dropped. Decreasing payout amount from {} to {}",
258258
HavenoUtils.formatXmr(disputeResult.getSellerPayoutAmountBeforeCost()),
259259
HavenoUtils.formatXmr(trade.getWallet().getBalance()));
260260
disputeResult.setSellerPayoutAmountBeforeCost(trade.getWallet().getBalance());

core/src/main/java/haveno/core/api/model/TradeInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ public class TradeInfo implements Payload {
9191
private final boolean isDepositsPublished;
9292
private final boolean isDepositsConfirmed;
9393
private final boolean isDepositsUnlocked;
94+
private final boolean isDepositsFinalized;
9495
private final boolean isPaymentSent;
9596
private final boolean isPaymentReceived;
9697
private final boolean isPayoutPublished;
9798
private final boolean isPayoutConfirmed;
9899
private final boolean isPayoutUnlocked;
100+
private final boolean isPayoutFinalized;
99101
private final boolean isCompleted;
100102
private final String contractAsJson;
101103
private final ContractInfo contract;
@@ -135,11 +137,13 @@ public TradeInfo(TradeInfoV1Builder builder) {
135137
this.isDepositsPublished = builder.isDepositsPublished();
136138
this.isDepositsConfirmed = builder.isDepositsConfirmed();
137139
this.isDepositsUnlocked = builder.isDepositsUnlocked();
140+
this.isDepositsFinalized = builder.isDepositsFinalized();
138141
this.isPaymentSent = builder.isPaymentSent();
139142
this.isPaymentReceived = builder.isPaymentReceived();
140143
this.isPayoutPublished = builder.isPayoutPublished();
141144
this.isPayoutConfirmed = builder.isPayoutConfirmed();
142145
this.isPayoutUnlocked = builder.isPayoutUnlocked();
146+
this.isPayoutFinalized = builder.isPayoutFinalized();
143147
this.isCompleted = builder.isCompleted();
144148
this.contractAsJson = builder.getContractAsJson();
145149
this.contract = builder.getContract();
@@ -199,11 +203,13 @@ public static TradeInfo toTradeInfo(Trade trade) {
199203
.withIsDepositsPublished(trade.isDepositsPublished())
200204
.withIsDepositsConfirmed(trade.isDepositsConfirmed())
201205
.withIsDepositsUnlocked(trade.isDepositsUnlocked())
206+
.withIsDepositsFinalized(trade.isDepositsFinalized())
202207
.withIsPaymentSent(trade.isPaymentSent())
203208
.withIsPaymentReceived(trade.isPaymentReceived())
204209
.withIsPayoutPublished(trade.isPayoutPublished())
205210
.withIsPayoutConfirmed(trade.isPayoutConfirmed())
206211
.withIsPayoutUnlocked(trade.isPayoutUnlocked())
212+
.withIsPayoutFinalized(trade.isPayoutFinalized())
207213
.withIsCompleted(trade.isCompleted())
208214
.withContractAsJson(trade.getContractAsJson())
209215
.withContract(contractInfo)
@@ -252,12 +258,14 @@ public haveno.proto.grpc.TradeInfo toProtoMessage() {
252258
.setIsDepositsPublished(isDepositsPublished)
253259
.setIsDepositsConfirmed(isDepositsConfirmed)
254260
.setIsDepositsUnlocked(isDepositsUnlocked)
261+
.setIsDepositsFinalized(isDepositsFinalized)
255262
.setIsPaymentSent(isPaymentSent)
256263
.setIsPaymentReceived(isPaymentReceived)
257264
.setIsCompleted(isCompleted)
258265
.setIsPayoutPublished(isPayoutPublished)
259266
.setIsPayoutConfirmed(isPayoutConfirmed)
260267
.setIsPayoutUnlocked(isPayoutUnlocked)
268+
.setIsPayoutFinalized(isPayoutFinalized)
261269
.setContractAsJson(contractAsJson == null ? "" : contractAsJson)
262270
.setContract(contract.toProtoMessage())
263271
.setStartTime(startTime)
@@ -299,12 +307,14 @@ public static TradeInfo fromProto(haveno.proto.grpc.TradeInfo proto) {
299307
.withIsDepositsPublished(proto.getIsDepositsPublished())
300308
.withIsDepositsConfirmed(proto.getIsDepositsConfirmed())
301309
.withIsDepositsUnlocked(proto.getIsDepositsUnlocked())
310+
.withIsDepositsFinalized(proto.getIsDepositsFinalized())
302311
.withIsPaymentSent(proto.getIsPaymentSent())
303312
.withIsPaymentReceived(proto.getIsPaymentReceived())
304313
.withIsCompleted(proto.getIsCompleted())
305314
.withIsPayoutPublished(proto.getIsPayoutPublished())
306315
.withIsPayoutConfirmed(proto.getIsPayoutConfirmed())
307316
.withIsPayoutUnlocked(proto.getIsPayoutUnlocked())
317+
.withIsPayoutFinalized(proto.getIsPayoutFinalized())
308318
.withContractAsJson(proto.getContractAsJson())
309319
.withContract((ContractInfo.fromProto(proto.getContract())))
310320
.withStartTime(proto.getStartTime())
@@ -345,11 +355,13 @@ public String toString() {
345355
", isDepositsPublished=" + isDepositsPublished + "\n" +
346356
", isDepositsConfirmed=" + isDepositsConfirmed + "\n" +
347357
", isDepositsUnlocked=" + isDepositsUnlocked + "\n" +
358+
", isDepositsFinalized=" + isDepositsFinalized + "\n" +
348359
", isPaymentSent=" + isPaymentSent + "\n" +
349360
", isPaymentReceived=" + isPaymentReceived + "\n" +
350361
", isPayoutPublished=" + isPayoutPublished + "\n" +
351362
", isPayoutConfirmed=" + isPayoutConfirmed + "\n" +
352363
", isPayoutUnlocked=" + isPayoutUnlocked + "\n" +
364+
", isPayoutFinalized=" + isPayoutFinalized + "\n" +
353365
", isCompleted=" + isCompleted + "\n" +
354366
", offer=" + offer + "\n" +
355367
", contractAsJson=" + contractAsJson + "\n" +

core/src/main/java/haveno/core/api/model/builder/TradeInfoV1Builder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public final class TradeInfoV1Builder {
6464
private boolean isDepositsPublished;
6565
private boolean isDepositsConfirmed;
6666
private boolean isDepositsUnlocked;
67+
private boolean isDepositsFinalized;
6768
private boolean isPaymentSent;
6869
private boolean isPaymentReceived;
6970
private boolean isPayoutPublished;
7071
private boolean isPayoutConfirmed;
7172
private boolean isPayoutUnlocked;
73+
private boolean isPayoutFinalized;
7274
private boolean isCompleted;
7375
private String contractAsJson;
7476
private ContractInfo contract;
@@ -242,6 +244,11 @@ public TradeInfoV1Builder withIsDepositsUnlocked(boolean isDepositsUnlocked) {
242244
return this;
243245
}
244246

247+
public TradeInfoV1Builder withIsDepositsFinalized(boolean isDepositsFinalized) {
248+
this.isDepositsFinalized = isDepositsFinalized;
249+
return this;
250+
}
251+
245252
public TradeInfoV1Builder withIsPaymentSent(boolean isPaymentSent) {
246253
this.isPaymentSent = isPaymentSent;
247254
return this;
@@ -267,6 +274,11 @@ public TradeInfoV1Builder withIsPayoutUnlocked(boolean isPayoutUnlocked) {
267274
return this;
268275
}
269276

277+
public TradeInfoV1Builder withIsPayoutFinalized(boolean isPayoutFinalized) {
278+
this.isPayoutFinalized = isPayoutFinalized;
279+
return this;
280+
}
281+
270282
public TradeInfoV1Builder withIsCompleted(boolean isCompleted) {
271283
this.isCompleted = isCompleted;
272284
return this;

core/src/main/java/haveno/core/notifications/alerts/TradeEvents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private void setTradePhaseListener(Trade trade) {
7070
case DEPOSITS_PUBLISHED:
7171
break;
7272
case DEPOSITS_UNLOCKED:
73+
case DEPOSITS_FINALIZED: // TODO: use a separate message for deposits finalized?
7374
if (trade.getContract() != null && pubKeyRingProvider.get().equals(trade.getContract().getBuyerPubKeyRing()))
7475
msg = Res.get("account.notifications.trade.message.msg.conf", shortId);
7576
break;

core/src/main/java/haveno/core/support/SupportManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected void handle(ChatMessage chatMessage) {
160160
log.info("Received {} from peer {}. tradeId={}, uid={}", chatMessage.getClass().getSimpleName(), chatMessage.getSenderNodeAddress(), tradeId, uid);
161161
boolean channelOpen = channelOpen(chatMessage);
162162
if (!channelOpen) {
163-
log.debug("We got a chatMessage but we don't have a matching chat. TradeId = " + tradeId);
163+
log.warn("We got a chatMessage but we don't have a matching chat. TradeId = " + tradeId);
164164
if (!delayMsgMap.containsKey(uid)) {
165165
Timer timer = UserThread.runAfter(() -> handle(chatMessage), 1);
166166
delayMsgMap.put(uid, timer);

core/src/main/java/haveno/core/support/dispute/DisputeManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@ protected void handle(DisputeOpenedMessage message) {
598598
TradePeer opener = sender == trade.getArbitrator() ? trade.getTradePeer() : sender;
599599
if (message.getOpenerUpdatedMultisigHex() != null) opener.setUpdatedMultisigHex(message.getOpenerUpdatedMultisigHex());
600600

601+
// arbitrator syncs and polls wallet
602+
if (trade.isArbitrator()) {
603+
trade.syncAndPollWallet();
604+
trade.recoverIfMissingWalletData();
605+
}
606+
601607
// add chat message with price info
602608
if (trade instanceof ArbitratorTrade) addPriceInfoMessage(dispute, 0);
603609

0 commit comments

Comments
 (0)