From 4c7075b0bd5a78f398ffa71f48d45b1909947279 Mon Sep 17 00:00:00 2001 From: woodser Date: Wed, 23 Nov 2022 14:25:45 +0000 Subject: [PATCH] set payout tx hash on payment received unless unlocked --- core/src/main/java/bisq/core/trade/Trade.java | 4 +- .../tasks/ProcessPaymentReceivedMessage.java | 87 +++++++++++-------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index 22034f01..edb492e5 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -816,7 +816,7 @@ public abstract class Trade implements Tradable, Model { // submit payout tx if (publish) { multisigWallet.submitMultisigTxHex(payoutTxHex); - setPayoutState(Trade.PayoutState.PAYOUT_PUBLISHED); + pollWallet(); } } @@ -1447,7 +1447,7 @@ public abstract class Trade implements Tradable, Model { } } - // check for outgoing txs (appears on payout confirmed) + // check for outgoing txs (appears after wallet submits payout tx or on payout confirmed) List outgoingTxs = getWallet().getTxs(new MoneroTxQuery().setIsOutgoing(true)); if (!outgoingTxs.isEmpty()) { MoneroTxWallet payoutTx = outgoingTxs.get(0); 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 1c980fcd..efbc3057 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 @@ -59,44 +59,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask { trade.getSeller().setNodeAddress(processModel.getTempTradingPeerNodeAddress()); if (trade.getSeller().getNodeAddress().equals(trade.getBuyer().getNodeAddress())) trade.getBuyer().setNodeAddress(null); // tests can reuse addresses - // 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 - - // sync and save wallet - trade.syncWallet(); - trade.saveWallet(); - - // handle if payout tx not published - if (!trade.isPayoutPublished()) { - - // wait to sign and publish payout tx if defer flag set (seller recently saw payout tx arrive at buyer) - boolean isSigned = message.getSignedPayoutTxHex() != null; - if (trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout()) { - log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); - GenUtils.waitFor(Trade.DEFER_PUBLISH_MS); - trade.syncWallet(); - } - - // verify and publish payout tx - if (!trade.isPayoutPublished()) { - if (isSigned) { - log.info("{} publishing signed payout tx from seller", trade.getClass().getSimpleName()); - trade.verifyPayoutTx(message.getSignedPayoutTxHex(), false, true); - } else { - log.info("{} verifying, signing, and publishing seller's payout tx", trade.getClass().getSimpleName()); - try { - trade.verifyPayoutTx(message.getUnsignedPayoutTxHex(), true, true); - } catch (Exception e) { - if (trade.isPayoutPublished()) log.info("Payout tx already published for {} {}", trade.getClass().getName(), trade.getId()); - else throw e; - } - } - } - } else { - log.info("Payout tx already published for {} {}", trade.getClass().getSimpleName(), trade.getId()); + // process payout tx unless already unlocked + if (!trade.isPayoutUnlocked()) { + processPayoutTx(message); + complete(); + return; } SignedWitness signedWitness = message.getSignedWitness(); @@ -115,4 +82,48 @@ public class ProcessPaymentReceivedMessage extends TradeTask { failed(t); } } + + private void processPayoutTx(PaymentReceivedMessage message) { + + // 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 + + // sync and save wallet + trade.syncWallet(); + trade.saveWallet(); + + // handle if payout tx not published + if (!trade.isPayoutPublished()) { + + // wait to sign and publish payout tx if defer flag set (seller recently saw payout tx arrive at buyer) + boolean isSigned = message.getSignedPayoutTxHex() != null; + if (trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout()) { + log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); + GenUtils.waitFor(Trade.DEFER_PUBLISH_MS); + trade.syncWallet(); + } + + // verify and publish payout tx + if (!trade.isPayoutPublished()) { + if (isSigned) { + log.info("{} publishing signed payout tx from seller", trade.getClass().getSimpleName()); + trade.verifyPayoutTx(message.getSignedPayoutTxHex(), false, true); + } else { + log.info("{} verifying, signing, and publishing seller's payout tx", trade.getClass().getSimpleName()); + try { + trade.verifyPayoutTx(message.getUnsignedPayoutTxHex(), true, true); + } catch (Exception e) { + if (trade.isPayoutPublished()) log.info("Payout tx already published for {} {}", trade.getClass().getName(), trade.getId()); + else throw e; + } + } + } + } else { + log.info("Payout tx already published for {} {}", trade.getClass().getSimpleName(), trade.getId()); + if (message.getSignedPayoutTxHex() != null && !trade.isPayoutConfirmed()) trade.verifyPayoutTx(message.getSignedPayoutTxHex(), false, true); + } + } }