diff --git a/core/src/main/java/haveno/core/api/CoreDisputesService.java b/core/src/main/java/haveno/core/api/CoreDisputesService.java index f94dc983c5..c2eaf09e68 100644 --- a/core/src/main/java/haveno/core/api/CoreDisputesService.java +++ b/core/src/main/java/haveno/core/api/CoreDisputesService.java @@ -112,7 +112,7 @@ public class CoreDisputesService { // Sends the openNewDisputeMessage to arbitrator, who will then create 2 disputes // one for the opener, the other for the peer, see sendPeerOpenedDisputeMessage. - disputeManager.sendDisputeOpenedMessage(dispute, false, trade.getSelf().getUpdatedMultisigHex(), resultHandler, faultHandler); + disputeManager.sendDisputeOpenedMessage(dispute, false, resultHandler, faultHandler); tradeManager.requestPersistence(); }, trade.getId()); } diff --git a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java index 14cda44672..7aa1906c58 100644 --- a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java @@ -157,6 +157,11 @@ public abstract class DisputeManager> extends Sup disputeListService.requestPersistence(); } + protected void requestPersistence(Trade trade) { + trade.requestPersistence(); + disputeListService.requestPersistence(); + } + @Override public NodeAddress getPeerNodeAddress(ChatMessage message) { Optional disputeOptional = findDispute(message); @@ -322,7 +327,6 @@ public abstract class DisputeManager> extends Sup // trader sends message to arbitrator to open dispute public void sendDisputeOpenedMessage(Dispute dispute, boolean reOpen, - String updatedMultisigHex, ResultHandler resultHandler, FaultHandler faultHandler) { @@ -372,12 +376,13 @@ public abstract class DisputeManager> extends Sup } // create dispute opened message + trade.exportMultisigHex(); NodeAddress agentNodeAddress = getAgentNodeAddress(dispute); DisputeOpenedMessage disputeOpenedMessage = new DisputeOpenedMessage(dispute, p2PService.getAddress(), UUID.randomUUID().toString(), getSupportType(), - updatedMultisigHex, + trade.getSelf().getUpdatedMultisigHex(), trade.getArbitrator().getPaymentSentMessage()); log.info("Send {} to peer {}. tradeId={}, openNewDisputeMessage.uid={}, " + "chatMessage.uid={}", @@ -792,7 +797,7 @@ public abstract class DisputeManager> extends Sup disputeResult.getChatMessage().setArrived(true); trade.advanceDisputeState(Trade.DisputeState.ARBITRATOR_SAW_ARRIVED_DISPUTE_CLOSED_MSG); trade.pollWalletNormallyForMs(30000); - requestPersistence(); + requestPersistence(trade); resultHandler.handleResult(); } @@ -811,7 +816,7 @@ public abstract class DisputeManager> extends Sup disputeResult.getChatMessage().setStoredInMailbox(true); Trade trade = tradeManager.getTrade(dispute.getTradeId()); trade.advanceDisputeState(Trade.DisputeState.ARBITRATOR_STORED_IN_MAILBOX_DISPUTE_CLOSED_MSG); - requestPersistence(); + requestPersistence(trade); resultHandler.handleResult(); } @@ -828,13 +833,13 @@ public abstract class DisputeManager> extends Sup // the state, as that is displayed to the user and we only persist that msg disputeResult.getChatMessage().setSendMessageError(errorMessage); trade.advanceDisputeState(Trade.DisputeState.ARBITRATOR_SEND_FAILED_DISPUTE_CLOSED_MSG); - requestPersistence(); + requestPersistence(trade); faultHandler.handleFault(errorMessage, new RuntimeException(errorMessage)); } } ); trade.advanceDisputeState(Trade.DisputeState.ARBITRATOR_SENT_DISPUTE_CLOSED_MSG); - requestPersistence(); + requestPersistence(trade); } catch (Exception e) { faultHandler.handleFault(e.getMessage(), e); } @@ -900,11 +905,11 @@ public abstract class DisputeManager> extends Sup // update trade state if (updateState) { trade.getProcessModel().setUnsignedPayoutTx(payoutTx); - trade.getSelf().setUpdatedMultisigHex(trade.getWallet().exportMultisigHex()); trade.updatePayout(payoutTx); if (trade.getBuyer().getUpdatedMultisigHex() != null && trade.getBuyer().getUnsignedPayoutTxHex() == null) trade.getBuyer().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex()); if (trade.getSeller().getUpdatedMultisigHex() != null && trade.getSeller().getUnsignedPayoutTxHex() == null) trade.getSeller().setUnsignedPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex()); } + trade.requestPersistence(); return payoutTx; } catch (Exception e) { trade.syncAndPollWallet(); diff --git a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java index 1d8a32d377..c3ec00b540 100644 --- a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java @@ -252,7 +252,7 @@ public final class ArbitrationManager extends DisputeManager { - private F first; - private S second; + private F first; + private S second; - public Pair(F first, S second) { - super(); - this.first = first; - this.second = second; - } + public Pair(F first, S second) { + super(); + this.first = first; + this.second = second; + } - public F getFirst() { - return first; - } + public F getFirst() { + return first; + } - public void setFirst(F first) { - this.first = first; - } + public void setFirst(F first) { + this.first = first; + } - public S getSecond() { - return second; - } + public S getSecond() { + return second; + } - public void setSecond(S second) { - this.second = second; - } + public void setSecond(S second) { + this.second = second; + } } public static void printBalances(MoneroWallet wallet) { - // collect info about subaddresses - List>> pairs = new ArrayList>>(); - //if (wallet == null) wallet = TestUtils.getWalletJni(); - BigInteger balance = wallet.getBalance(); - BigInteger unlockedBalance = wallet.getUnlockedBalance(); - List accounts = wallet.getAccounts(true); - System.out.println("Wallet balance: " + balance); - System.out.println("Wallet unlocked balance: " + unlockedBalance); - for (MoneroAccount account : accounts) { - add(pairs, "ACCOUNT", account.getIndex()); - add(pairs, "SUBADDRESS", ""); - add(pairs, "LABEL", ""); - add(pairs, "ADDRESS", ""); - add(pairs, "BALANCE", account.getBalance()); - add(pairs, "UNLOCKED", account.getUnlockedBalance()); - for (MoneroSubaddress subaddress : account.getSubaddresses()) { - add(pairs, "ACCOUNT", account.getIndex()); - add(pairs, "SUBADDRESS", subaddress.getIndex()); - add(pairs, "LABEL", subaddress.getLabel()); - add(pairs, "ADDRESS", subaddress.getAddress()); - add(pairs, "BALANCE", subaddress.getBalance()); - add(pairs, "UNLOCKED", subaddress.getUnlockedBalance()); + // collect info about subaddresses + List>> pairs = new ArrayList>>(); + //if (wallet == null) wallet = TestUtils.getWalletJni(); + BigInteger balance = wallet.getBalance(); + BigInteger unlockedBalance = wallet.getUnlockedBalance(); + List accounts = wallet.getAccounts(true); + System.out.println("Wallet balance: " + balance); + System.out.println("Wallet unlocked balance: " + unlockedBalance); + for (MoneroAccount account : accounts) { + add(pairs, "ACCOUNT", account.getIndex()); + add(pairs, "SUBADDRESS", ""); + add(pairs, "LABEL", ""); + add(pairs, "ADDRESS", ""); + add(pairs, "BALANCE", account.getBalance()); + add(pairs, "UNLOCKED", account.getUnlockedBalance()); + for (MoneroSubaddress subaddress : account.getSubaddresses()) { + add(pairs, "ACCOUNT", account.getIndex()); + add(pairs, "SUBADDRESS", subaddress.getIndex()); + add(pairs, "LABEL", subaddress.getLabel()); + add(pairs, "ADDRESS", subaddress.getAddress()); + add(pairs, "BALANCE", subaddress.getBalance()); + add(pairs, "UNLOCKED", subaddress.getUnlockedBalance()); + } } - } - // convert info to csv - Integer length = null; - for (Pair> pair : pairs) { - if (length == null) length = pair.getSecond().size(); - } + // convert info to csv + Integer length = null; + for (Pair> pair : pairs) { + if (length == null) + length = pair.getSecond().size(); + } - System.out.println(pairsToCsv(pairs)); + System.out.println(pairsToCsv(pairs)); } private static void add(List>> pairs, String header, Object value) { - if (value == null) value = ""; - Pair> pair = null; - for (Pair> aPair : pairs) { - if (aPair.getFirst().equals(header)) { - pair = aPair; - break; + if (value == null) value = ""; + Pair> pair = null; + for (Pair> aPair : pairs) { + if (aPair.getFirst().equals(header)) { + pair = aPair; + break; + } } - } - if (pair == null) { - List vals = new ArrayList(); - pair = new Pair>(header, vals); - pairs.add(pair); - } - pair.getSecond().add(value); + if (pair == null) { + List vals = new ArrayList(); + pair = new Pair>(header, vals); + pairs.add(pair); + } + pair.getSecond().add(value); } private static String pairsToCsv(List>> pairs) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < pairs.size(); i++) { - sb.append(pairs.get(i).getFirst()); - if (i < pairs.size() - 1) sb.append(','); - else sb.append('\n'); - } - for (int i = 0; i < pairs.get(0).getSecond().size(); i++) { - for (int j = 0; j < pairs.size(); j++) { - sb.append(pairs.get(j).getSecond().get(i)); - if (j < pairs.size() - 1) sb.append(','); - else sb.append('\n'); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < pairs.size(); i++) { + sb.append(pairs.get(i).getFirst()); + if (i < pairs.size() - 1) sb.append(','); + else sb.append('\n'); } - } - return sb.toString(); + for (int i = 0; i < pairs.get(0).getSecond().size(); i++) { + for (int j = 0; j < pairs.size(); j++) { + sb.append(pairs.get(j).getSecond().get(i)); + if (j < pairs.size() - 1) sb.append(','); + else sb.append('\n'); + } + } + return sb.toString(); } } - - diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java index e47a8f2bc7..93d1ce520a 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java @@ -58,7 +58,6 @@ public class ProcessPaymentSentMessage extends TradeTask { // if seller, decrypt buyer's payment account payload if (trade.isSeller()) trade.decryptPeerPaymentAccountPayload(message.getPaymentAccountKey()); - trade.requestPersistence(); // update state trade.advanceState(Trade.State.BUYER_SENT_PAYMENT_SENT_MSG); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java index 38ecdd7fee..bf0a4df025 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java @@ -90,7 +90,7 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask { for (Dispute dispute : trade.getDisputes()) dispute.setIsClosed(); } - processModel.getTradeManager().requestPersistence(); + trade.requestPersistence(); complete(); } catch (Throwable t) { failed(t); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/SendDepositsConfirmedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/SendDepositsConfirmedMessage.java index 3c52db21e9..8be8f00da5 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/SendDepositsConfirmedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/SendDepositsConfirmedMessage.java @@ -76,8 +76,7 @@ public abstract class SendDepositsConfirmedMessage extends SendMailboxMessageTas // export multisig hex once if (trade.getSelf().getUpdatedMultisigHex() == null) { - trade.getSelf().setUpdatedMultisigHex(trade.getWallet().exportMultisigHex()); - processModel.getTradeManager().requestPersistence(); + trade.exportMultisigHex(); } // We do not use a real unique ID here as we want to be able to re-send the exact same message in case the diff --git a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java index aa67c2f465..1e0072b633 100644 --- a/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java +++ b/desktop/src/main/java/haveno/desktop/main/portfolio/pendingtrades/PendingTradesDataModel.java @@ -545,27 +545,28 @@ public class PendingTradesDataModel extends ActivatableDataModel { dispute.setExtraData("counterCurrencyExtraData", trade.getCounterCurrencyExtraData()); trade.setDisputeState(Trade.DisputeState.MEDIATION_REQUESTED); - sendDisputeOpenedMessage(dispute, false, disputeManager, trade.getSelf().getUpdatedMultisigHex()); + sendDisputeOpenedMessage(dispute, false, disputeManager); tradeManager.requestPersistence(); } else if (useArbitration) { // Only if we have completed mediation we allow arbitration disputeManager = arbitrationManager; Dispute dispute = disputesService.createDisputeForTrade(trade, offer, pubKeyRingProvider.get(), isMaker, isSupportTicket); - sendDisputeOpenedMessage(dispute, false, disputeManager, trade.getSelf().getUpdatedMultisigHex()); + trade.exportMultisigHex(); + sendDisputeOpenedMessage(dispute, false, disputeManager); tradeManager.requestPersistence(); } else { log.warn("Invalid dispute state {}", disputeState.name()); } } - private void sendDisputeOpenedMessage(Dispute dispute, boolean reOpen, DisputeManager> disputeManager, String senderMultisigHex) { - disputeManager.sendDisputeOpenedMessage(dispute, reOpen, senderMultisigHex, + private void sendDisputeOpenedMessage(Dispute dispute, boolean reOpen, DisputeManager> disputeManager) { + disputeManager.sendDisputeOpenedMessage(dispute, reOpen, () -> navigation.navigateTo(MainView.class, SupportView.class, ArbitrationClientView.class), (errorMessage, throwable) -> { if ((throwable instanceof DisputeAlreadyOpenException)) { errorMessage += "\n\n" + Res.get("portfolio.pending.openAgainDispute.msg"); new Popup().warning(errorMessage) .actionButtonText(Res.get("portfolio.pending.openAgainDispute.button")) - .onAction(() -> sendDisputeOpenedMessage(dispute, true, disputeManager, senderMultisigHex)) + .onAction(() -> sendDisputeOpenedMessage(dispute, true, disputeManager)) .closeButtonText(Res.get("shared.cancel")).show(); } else { new Popup().warning(errorMessage).show();