diff --git a/core/src/main/java/bisq/core/support/dispute/DisputeManager.java b/core/src/main/java/bisq/core/support/dispute/DisputeManager.java index fe623168d5..7517b5aeeb 100644 --- a/core/src/main/java/bisq/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/bisq/core/support/dispute/DisputeManager.java @@ -79,7 +79,6 @@ import java.util.stream.Collectors; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import monero.common.MoneroError; -import monero.wallet.MoneroWallet; import monero.wallet.model.MoneroTxConfig; import monero.wallet.model.MoneroTxWallet; @@ -496,6 +495,7 @@ public abstract class DisputeManager> extends Sup // update multisig hex if (message.getUpdatedMultisigHex() != null) sender.setUpdatedMultisigHex(message.getUpdatedMultisigHex()); + trade.importMultisigHex(); // update peer node address // TODO: tests can reuse the same addresses so nullify equal peer @@ -820,23 +820,15 @@ public abstract class DisputeManager> extends Sup public MoneroTxWallet createDisputePayoutTx(Trade trade, Contract contract, DisputeResult disputeResult, boolean skipMultisigImport) { + // import multisig hex + trade.importMultisigHex(); + // sync and save wallet trade.syncWallet(); trade.saveWallet(); // create unsigned dispute payout tx if not already published if (!trade.isPayoutPublished()) { - MoneroWallet multisigWallet = trade.getWallet(); - - // import multisig hex - if (!skipMultisigImport) { - List updatedMultisigHexes = new ArrayList(); - if (trade.getBuyer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getBuyer().getUpdatedMultisigHex()); - if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex()); - if (!updatedMultisigHexes.isEmpty()) { - multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually - } - } // create unsigned dispute payout tx log.info("Arbitrator creating unsigned dispute payout tx for trade {}", trade.getId()); diff --git a/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java index 90b92055a9..60d1c6f6f7 100644 --- a/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/bisq/core/support/dispute/arbitration/ArbitrationManager.java @@ -55,7 +55,6 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import java.math.BigInteger; -import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -252,6 +251,10 @@ public final class ArbitrationManager extends DisputeManager updatedMultisigHexes = new ArrayList(); - if (trade.getTradePeer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getTradePeer().getUpdatedMultisigHex()); - if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex()); - if (!updatedMultisigHexes.isEmpty()) trade.getWallet().importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually - // wait to sign and publish payout tx if defer flag set if (disputeClosedMessage.isDeferPublishPayout()) { log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 289675636b..9bc2522e9a 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -777,6 +777,14 @@ public abstract class Trade implements Tradable, Model { }, syncNormalDuration); } + public void importMultisigHex() { + List multisigHexes = new ArrayList(); + if (getBuyer().getUpdatedMultisigHex() != null) multisigHexes.add(getBuyer().getUpdatedMultisigHex()); + if (getSeller().getUpdatedMultisigHex() != null) multisigHexes.add(getSeller().getUpdatedMultisigHex()); + if (getArbitrator().getUpdatedMultisigHex() != null) multisigHexes.add(getArbitrator().getUpdatedMultisigHex()); + if (!multisigHexes.isEmpty()) getWallet().importMultisigHex(multisigHexes.toArray(new String[0])); + } + public void changeWalletPassword(String oldPassword, String newPassword) { synchronized (walletLock) { getWallet().changePassword(oldPassword, newPassword); @@ -882,9 +890,15 @@ public abstract class Trade implements Tradable, Model { */ public MoneroTxWallet createPayoutTx() { + // check connection to monero daemon + checkWalletConnection(); + + // import multisig hex + importMultisigHex(); + if (getWallet().isMultisigImportNeeded()) throw new RuntimeException("Cannot create payout tx because multisig import is needed"); + // gather info MoneroWallet multisigWallet = getWallet(); - if (multisigWallet.isMultisigImportNeeded()) throw new RuntimeException("Cannot create payout tx because multisig import is needed"); String sellerPayoutAddress = this.getSeller().getPayoutAddressString(); String buyerPayoutAddress = this.getBuyer().getPayoutAddressString(); Preconditions.checkNotNull(sellerPayoutAddress, "Seller payout address must not be null"); @@ -895,9 +909,6 @@ public abstract class Trade implements Tradable, Model { BigInteger buyerPayoutAmount = buyerDepositAmount.add(tradeAmount); BigInteger sellerPayoutAmount = sellerDepositAmount.subtract(tradeAmount); - // check connection to monero daemon - checkWalletConnection(); - // create transaction to get fee estimate MoneroTxWallet feeEstimateTx = multisigWallet.createTx(new MoneroTxConfig() .setAccountIndex(0) diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java index 237068a3c7..19e7739287 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java @@ -65,18 +65,6 @@ public class BuyerPreparePaymentSentMessage extends TradeTask { Preconditions.checkNotNull(trade.getTakerDepositTx(), "trade.getTakerDepositTx() must not be null"); checkNotNull(trade.getOffer(), "offer must not be null"); - // get multisig wallet - MoneroWallet multisigWallet = trade.getWallet(); - - // import multisig hex - List updatedMultisigHexes = new ArrayList(); - if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex()); - if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex()); - if (!updatedMultisigHexes.isEmpty()) { - multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually - trade.saveWallet(); - } - // create payout tx if we have seller's updated multisig hex if (trade.getSeller().getUpdatedMultisigHex() != null) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java index 86ef0b67e7..107866706b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java @@ -53,8 +53,9 @@ public class ProcessDepositsConfirmedMessage extends TradeTask { if (sender.getNodeAddress().equals(trade.getSeller().getNodeAddress()) && sender != trade.getSeller()) trade.getSeller().setNodeAddress(null); if (sender.getNodeAddress().equals(trade.getArbitrator().getNodeAddress()) && sender != trade.getArbitrator()) trade.getArbitrator().setNodeAddress(null); - // store updated multisig hex for processing on payment sent + // update multisig hex sender.setUpdatedMultisigHex(request.getUpdatedMultisigHex()); + trade.importMultisigHex(); // decrypt seller payment account payload if key given if (request.getSellerPaymentAccountKey() != null && trade.getTradePeer().getPaymentAccountPayload() == null) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java index 9a0f6e0b0b..9f965cb34f 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java @@ -33,9 +33,6 @@ import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.ArrayList; -import java.util.List; - import org.apache.commons.lang3.StringUtils; @Slf4j @@ -108,16 +105,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask { private void processPayoutTx(PaymentReceivedMessage message) { - // sync and save wallet + // update wallet + trade.importMultisigHex(); trade.syncWallet(); trade.saveWallet(); - // import multisig hex - List updatedMultisigHexes = new ArrayList(); - if (trade.getSeller().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getSeller().getUpdatedMultisigHex()); - if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex()); - if (!updatedMultisigHexes.isEmpty()) trade.getWallet().importMultisigHex(updatedMultisigHexes.toArray(new String[0])); // TODO (monero-project): fails if multisig hex imported individually - // handle if payout tx not published if (!trade.isPayoutPublished()) { diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentSentMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentSentMessage.java index 08e6c9b063..db95360cc4 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentSentMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/ProcessPaymentSentMessage.java @@ -50,6 +50,9 @@ public class ProcessPaymentSentMessage extends TradeTask { trade.getBuyer().setUpdatedMultisigHex(message.getUpdatedMultisigHex()); trade.getSeller().setAccountAgeWitness(message.getSellerAccountAgeWitness()); + // import multisig hex + trade.importMultisigHex(); + // if seller, decrypt buyer's payment account payload if (trade.isSeller()) trade.decryptPeerPaymentAccountPayload(message.getPaymentAccountKey()); diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java b/core/src/main/java/bisq/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java index a253a9ef99..a81a64ba4a 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/SellerPreparePaymentReceivedMessage.java @@ -19,13 +19,9 @@ package bisq.core.trade.protocol.tasks; import bisq.core.trade.Trade; -import java.util.ArrayList; -import java.util.List; - import bisq.common.taskrunner.TaskRunner; import lombok.extern.slf4j.Slf4j; -import monero.wallet.MoneroWallet; import monero.wallet.model.MoneroTxWallet; @Slf4j @@ -48,14 +44,7 @@ public class SellerPreparePaymentReceivedMessage extends TradeTask { if (processModel.getPaymentReceivedMessage() == null) { // import multisig hex - MoneroWallet multisigWallet = trade.getWallet(); - List updatedMultisigHexes = new ArrayList(); - if (trade.getBuyer().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getBuyer().getUpdatedMultisigHex()); - if (trade.getArbitrator().getUpdatedMultisigHex() != null) updatedMultisigHexes.add(trade.getArbitrator().getUpdatedMultisigHex()); - if (!updatedMultisigHexes.isEmpty()) { - multisigWallet.importMultisigHex(updatedMultisigHexes.toArray(new String[0])); - trade.saveWallet(); - } + trade.importMultisigHex(); // verify, sign, and publish payout tx if given. otherwise create payout tx if (trade.getPayoutTxHex() != null) {