diff --git a/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java b/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java index acd6fea37d7..970db6ae856 100644 --- a/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java +++ b/core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java @@ -43,7 +43,6 @@ import static com.google.common.base.Preconditions.checkNotNull; public class RedirectionTransactionFactory { - private final NetworkParameters params; public RedirectionTransactionFactory(NetworkParameters params) { @@ -97,6 +96,8 @@ public byte[] signRedirectionTransaction(Transaction redirectionTx, public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOutput, Transaction redirectionTx, + byte[] buyerPubKey, + byte[] sellerPubKey, byte[] buyerSignature, byte[] sellerSignature, Coin inputValue) @@ -105,6 +106,8 @@ public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOut TransactionInput input = redirectionTx.getInput(0); input.setScriptSig(ScriptBuilder.createEmpty()); + // FIXME: This redeem script is all wrong. It needs to be build from pubKeys, not signatures, + // and we cannot use TransactionWitness.redeemP2WSH with it, as it isn't a simple multisig script. Script redeemScript = createRedeemScript(buyerSignature, sellerSignature); TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript); input.setWitness(witness); diff --git a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java index 04a4fc11b7d..6897f65ca8a 100644 --- a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java @@ -886,6 +886,8 @@ public byte[] signRedirectionTx(Transaction redirectionTx, public Transaction finalizeRedirectionTx(TransactionOutput warningTxOutput, Transaction redirectionTx, + byte[] buyerPubKey, + byte[] sellerPubKey, byte[] buyerSignature, byte[] sellerSignature, Coin inputValue) @@ -893,6 +895,8 @@ public Transaction finalizeRedirectionTx(TransactionOutput warningTxOutput, return redirectionTransactionFactory.finalizeRedirectionTransaction( warningTxOutput, redirectionTx, + buyerPubKey, + sellerPubKey, buyerSignature, sellerSignature, inputValue diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/ProcessModel.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/ProcessModel.java index f712b286b80..f78f674bc95 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/ProcessModel.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/ProcessModel.java @@ -78,7 +78,7 @@ // persist them. /** - * This is the base model for the trade protocol. It is persisted with the trade (non transient fields). + * This is the base model for the trade protocol. It is persisted with the trade (non-transient fields). * It uses the {@link Provider} for access to domain services. */ diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/TradingPeer.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/TradingPeer.java index 1acb45a5dbb..cb60ce91d7e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/TradingPeer.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/TradingPeer.java @@ -63,6 +63,8 @@ public final class TradingPeer implements TradePeer { transient private byte[] warningTxSellerSignature; @Setter transient private byte[] warningTxBuyerSignature; + @Setter + private Transaction finalizedWarningTx; @Setter transient private Transaction redirectTx; @@ -70,6 +72,8 @@ public final class TradingPeer implements TradePeer { transient private byte[] redirectTxSellerSignature; @Setter transient private byte[] redirectTxBuyerSignature; + @Setter + private Transaction finalizedRedirectTx; // Transient/Mutable diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsMakerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsMakerProtocol_v5.java index 6262520199e..72ef3a8758d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsMakerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsMakerProtocol_v5.java @@ -37,9 +37,15 @@ import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerVerifyTakerFeePayment; import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesRequest; import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries; -import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerCreatesWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs; import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx; import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx; import bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker.BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest; import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5; @@ -101,10 +107,14 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, BuyerAsMakerCreatesAndSignsDepositTx.class, BuyerSetupDepositTxListener.class, - // We create our warn tx and our signature for the MS script +// // We create our warn tx and our signature for the MS script CreateFeeBumpAddressEntries.class, - BuyerCreatesWarningTx.class, + CreateWarningTxs.class, + CreateRedirectTxs.class, BuyerSignsOwnWarningTx.class, + BuyerSignsPeersWarningTx.class, + BuyerSignsOwnRedirectTx.class, + BuyerSignsPeersRedirectTx.class, MakerSendsInputsForDepositTxResponse_v5.class) @@ -130,6 +140,8 @@ protected void handle(PreparedTxBuyerSignaturesRequest message, NodeAddress peer .from(peer)) .setup(tasks( BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.class, + FinalizeWarningTxs.class, + FinalizeRedirectTxs.class, MakerRemovesOpenOffer.class, BuyerSendsPreparedTxBuyerSignaturesMessage.class) .withTimeout(120)) diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsTakerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsTakerProtocol_v5.java index 9a56557b6dd..ad01840c55d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsTakerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsTakerProtocol_v5.java @@ -36,8 +36,16 @@ import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyAndSignContract; import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment; import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs; import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage; import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx; import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5; import bisq.network.p2p.NodeAddress; @@ -114,6 +122,16 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) { .from(peer)) .setup(tasks(TakerProcessInputsForDepositTxResponse_v5.class, ApplyFilter.class, + + CreateWarningTxs.class, + CreateRedirectTxs.class, + BuyerSignsOwnWarningTx.class, + BuyerSignsPeersWarningTx.class, + BuyerSignsOwnRedirectTx.class, + BuyerSignsPeersRedirectTx.class, + FinalizeWarningTxs.class, + FinalizeRedirectTxs.class, + TakerVerifyAndSignContract.class, TakerPublishFeeTx.class, BuyerAsTakerSignsDepositTx.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsMakerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsMakerProtocol_v5.java index 09fc62e93bf..4aff976b111 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsMakerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsMakerProtocol_v5.java @@ -41,8 +41,16 @@ import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerFinalizesDepositTx; import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs; import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5; import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx; import bisq.network.p2p.NodeAddress; @@ -93,7 +101,15 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, MakerSetsLockTime.class, MakerCreateAndSignContract.class, SellerAsMakerCreatesUnsignedDepositTx.class, + CreateFeeBumpAddressEntries.class, + CreateWarningTxs.class, + CreateRedirectTxs.class, + SellerSignsOwnWarningTx.class, + SellerSignsPeersWarningTx.class, + SellerSignsOwnRedirectTx.class, + SellerSignsPeersRedirectTx.class, + MakerSendsInputsForDepositTxResponse_v5.class) .using(new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(message), @@ -132,8 +148,9 @@ protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer .from(peer)) .setup(tasks( SellerProcessPreparedTxBuyerSignaturesMessage.class, + FinalizeWarningTxs.class, + FinalizeRedirectTxs.class, SellerAsMakerFinalizesDepositTx.class, -// SellerFinalizesDelayedPayoutTx.class, MakerRemovesOpenOffer.class, SellerSendsDepositTxAndDelayedPayoutTxMessage.class, SellerPublishesDepositTx.class, diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsTakerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsTakerProtocol_v5.java index 9477a83adfb..0c875d5dcbc 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsTakerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsTakerProtocol_v5.java @@ -37,13 +37,16 @@ import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment; import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5; import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; -import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTx; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerCreatesWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs; +import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs; import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx; import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx; import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx; import bisq.core.trade.protocol.bisq_v5.tasks.seller_as_taker.SellerAsTakerSendsPreparedTxBuyerSignaturesRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries; import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5; import bisq.network.p2p.NodeAddress; @@ -112,25 +115,33 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) { .from(peer)) .setup(tasks( TakerProcessInputsForDepositTxResponse_v5.class, - ApplyFilter.class, + + CreateWarningTxs.class, + CreateRedirectTxs.class, + SellerSignsOwnWarningTx.class, + SellerSignsPeersWarningTx.class, + SellerSignsOwnRedirectTx.class, + SellerSignsPeersRedirectTx.class, + FinalizeWarningTxs.class, + FinalizeRedirectTxs.class, + TakerVerifyAndSignContract.class, TakerPublishFeeTx.class, SellerAsTakerSignsDepositTx.class, - // We create our warn tx and our signature for the MS script. - SellerCreatesWarningTx.class, - SellerSignsOwnWarningTx.class, +// // We create our warn tx and our signature for the MS script. +// SellerCreatesWarningTx.class, +// SellerSignsOwnWarningTx.class, // We can now create the signed claim tx from out warn tx // CreateSignedClaimTx.class, - // We create our redirect tx using the buyers warn tx output and our signature for the MS script - CreateRedirectTx.class, - SellerSignsOwnRedirectTx.class, +// // We create our redirect tx using the buyers warn tx output and our signature for the MS script +// SellerSignsOwnRedirectTx.class, - // We sign the buyers warn tx - SellerSignsPeersWarningTx.class, +// // We sign the buyers warn tx +// SellerSignsPeersWarningTx.class, // // We send buyer sig for their warn tx and our warn and redirect tx including our signatures // SellerSendStagedPayoutTxRequest.class) diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTxs.java similarity index 61% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTx.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTxs.java index 641f1e256d6..32d7693e1a6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTxs.java @@ -17,8 +17,6 @@ package bisq.core.trade.protocol.bisq_v5.tasks; -import bisq.core.btc.model.AddressEntry; -import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.TradeWalletService; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.model.TradingPeer; @@ -35,9 +33,11 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; + @Slf4j -public class CreateRedirectTx extends TradeTask { - public CreateRedirectTx(TaskRunner taskHandler, Trade trade) { +public class CreateRedirectTxs extends TradeTask { + public CreateRedirectTxs(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -47,28 +47,44 @@ protected void run() { runInterceptHook(); TradeWalletService tradeWalletService = processModel.getTradeWalletService(); - BtcWalletService btcWalletService = processModel.getBtcWalletService(); - String tradeId = processModel.getOffer().getId(); TradingPeer tradingPeer = processModel.getTradePeer(); + // Get receiver amounts and addresses. + TransactionOutput warningTxOutput = processModel.getWarningTx().getOutput(0); TransactionOutput peersWarningTxOutput = tradingPeer.getWarningTx().getOutput(0); + long inputAmount = peersWarningTxOutput.getValue().value; + checkArgument(warningTxOutput.getValue().value == inputAmount, + "Different warningTx output amounts. Ours: {}; Peer's: {}", warningTxOutput.getValue().value, inputAmount); + long depositTxFee = trade.getTradeTxFeeAsLong(); // Used for fee rate calculation inside getDelayedPayoutTxReceiverService + long inputAmountMinusFeeForFeeBumpOutput = inputAmount - 32 * depositTxFee; int selectionHeight = processModel.getBurningManSelectionHeight(); List> burningMen = processModel.getDelayedPayoutTxReceiverService().getReceivers( selectionHeight, - inputAmount, + inputAmountMinusFeeForFeeBumpOutput, depositTxFee); - log.info("Create redirectionTx using selectionHeight {} and receivers {}", selectionHeight, burningMen); - AddressEntry feeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.REDIRECT_TX_FEE_BUMP); - Tuple2 feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddressEntry.getAddressString()); + log.info("Create redirectionTxs using selectionHeight {} and receivers {}", selectionHeight, burningMen); + + // Create our redirect tx. + String feeBumpAddress = processModel.getRedirectTxFeeBumpAddress(); + var feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddress); Transaction unsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(peersWarningTxOutput, burningMen, feeBumpOutputAmountAndAddress); processModel.setRedirectTx(unsignedRedirectionTx); + // Create peer's redirect tx. + String peersFeeBumpAddress = tradingPeer.getRedirectTxFeeBumpAddress(); + var peersFeeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, peersFeeBumpAddress); + + Transaction peersUnsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(warningTxOutput, + burningMen, + peersFeeBumpOutputAmountAndAddress); + tradingPeer.setRedirectTx(peersUnsignedRedirectionTx); + processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerCreatesWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateWarningTxs.java similarity index 60% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerCreatesWarningTx.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateWarningTxs.java index 0fbd69f6caf..987a38aa093 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerCreatesWarningTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateWarningTxs.java @@ -15,11 +15,11 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.bisq_v5.tasks.buyer; +package bisq.core.trade.protocol.bisq_v5.tasks; -import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.TradeWalletService; +import bisq.core.trade.model.bisq_v1.BuyerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v5.model.StagedPayoutTxParameters; @@ -33,8 +33,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class BuyerCreatesWarningTx extends TradeTask { - public BuyerCreatesWarningTx(TaskRunner taskHandler, Trade trade) { +public class CreateWarningTxs extends TradeTask { + public CreateWarningTxs(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -43,21 +43,23 @@ protected void run() { try { runInterceptHook(); + boolean amBuyer = trade instanceof BuyerTrade; TradeWalletService tradeWalletService = processModel.getTradeWalletService(); BtcWalletService btcWalletService = processModel.getBtcWalletService(); - String tradeId = processModel.getOffer().getId(); Transaction depositTx = btcWalletService.getTxFromSerializedTx(processModel.getPreparedDepositTx()); TransactionOutput depositTxOutput = depositTx.getOutput(0); long lockTime = trade.getLockTime(); - byte[] buyerPubKey = processModel.getMyMultiSigPubKey(); - byte[] sellerPubKey = processModel.getTradePeer().getMultiSigPubKey(); - long claimDelay = StagedPayoutTxParameters.CLAIM_DELAY; + byte[] buyerPubKey = amBuyer ? processModel.getMyMultiSigPubKey() : processModel.getTradePeer().getMultiSigPubKey(); + byte[] sellerPubKey = amBuyer ? processModel.getTradePeer().getMultiSigPubKey() : processModel.getMyMultiSigPubKey(); + long claimDelay = StagedPayoutTxParameters.CLAIM_DELAY; // FIXME: Make sure this is a low value off mainnet long miningFee = StagedPayoutTxParameters.getWarningTxMiningFee(trade.getDepositTxFeeRate()); - AddressEntry feeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.WARNING_TX_FEE_BUMP); - Tuple2 feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.WARNING_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddressEntry.getAddressString()); - Transaction unsignedWarningTx = tradeWalletService.createUnsignedWarningTx(true, + // Create our warning tx. + String feeBumpAddress = processModel.getWarningTxFeeBumpAddress(); + var feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.WARNING_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddress); + + Transaction unsignedWarningTx = tradeWalletService.createUnsignedWarningTx(amBuyer, depositTxOutput, lockTime, buyerPubKey, @@ -67,6 +69,20 @@ protected void run() { feeBumpOutputAmountAndAddress); processModel.setWarningTx(unsignedWarningTx); + // Create peer's warning tx. + String peersFeeBumpAddress = processModel.getWarningTxFeeBumpAddress(); + var peersFeeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.WARNING_TX_FEE_BUMP_OUTPUT_VALUE, peersFeeBumpAddress); + + Transaction peersUnsignedWarningTx = tradeWalletService.createUnsignedWarningTx(!amBuyer, + depositTxOutput, + lockTime, + buyerPubKey, + sellerPubKey, + claimDelay, + miningFee, + peersFeeBumpOutputAmountAndAddress); + processModel.getTradePeer().setWarningTx(peersUnsignedWarningTx); + processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnRedirectTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeRedirectTxs.java similarity index 51% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnRedirectTx.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeRedirectTxs.java index 4f9c1d6c4f6..d09907a0d16 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnRedirectTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeRedirectTxs.java @@ -15,9 +15,10 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.bisq_v5.tasks.seller; +package bisq.core.trade.protocol.bisq_v5.tasks; import bisq.core.btc.wallet.TradeWalletService; +import bisq.core.trade.model.bisq_v1.BuyerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.model.TradingPeer; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; @@ -30,9 +31,11 @@ import lombok.extern.slf4j.Slf4j; +import static com.google.common.base.Preconditions.checkArgument; + @Slf4j -public class SellerFinalizesOwnRedirectTx extends TradeTask { - public SellerFinalizesOwnRedirectTx(TaskRunner taskHandler, Trade trade) { +public class FinalizeRedirectTxs extends TradeTask { + public FinalizeRedirectTxs(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -44,17 +47,45 @@ protected void run() { TradeWalletService tradeWalletService = processModel.getTradeWalletService(); TradingPeer tradingPeer = processModel.getTradePeer(); + // Get pubKeys and input value. + TransactionOutput warningTxOutput = processModel.getWarningTx().getOutput(0); TransactionOutput peersWarningTxOutput = tradingPeer.getWarningTx().getOutput(0); - Transaction redirectionTx = processModel.getRedirectTx(); + + Coin inputValue = peersWarningTxOutput.getValue(); + checkArgument(warningTxOutput.getValue().equals(inputValue), + "Different warningTx output values. Ours: {}; Peer's: {}", warningTxOutput.getValue(), inputValue); + + boolean amBuyer = trade instanceof BuyerTrade; + byte[] buyerPubKey = amBuyer ? processModel.getMyMultiSigPubKey() : tradingPeer.getMultiSigPubKey(); + byte[] sellerPubKey = amBuyer ? tradingPeer.getMultiSigPubKey() : processModel.getMyMultiSigPubKey(); + + // Finalize our redirect tx. + Transaction redirectTx = processModel.getRedirectTx(); byte[] buyerSignature = processModel.getRedirectTxBuyerSignature(); byte[] sellerSignature = processModel.getRedirectTxSellerSignature(); - Coin inputValue = peersWarningTxOutput.getValue(); - Transaction finalizedRedirectionTx = tradeWalletService.finalizeRedirectionTx(peersWarningTxOutput, - redirectionTx, + + Transaction finalizedRedirectTx = tradeWalletService.finalizeRedirectionTx(peersWarningTxOutput, + redirectTx, + buyerPubKey, + sellerPubKey, buyerSignature, sellerSignature, inputValue); - processModel.setFinalizedRedirectTx(finalizedRedirectionTx); + processModel.setFinalizedRedirectTx(finalizedRedirectTx); + + // Finalize peer's redirect tx. + Transaction peersRedirectTx = tradingPeer.getRedirectTx(); + byte[] peerBuyerSignature = tradingPeer.getRedirectTxBuyerSignature(); + byte[] peerSellerSignature = tradingPeer.getRedirectTxSellerSignature(); + + Transaction peersFinalizedRedirectTx = tradeWalletService.finalizeRedirectionTx(warningTxOutput, + peersRedirectTx, + buyerPubKey, + sellerPubKey, + peerBuyerSignature, + peerSellerSignature, + inputValue); + tradingPeer.setFinalizedRedirectTx(peersFinalizedRedirectTx); processModel.getTradeManager().requestPersistence(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerFinalizesOwnWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeWarningTxs.java similarity index 60% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerFinalizesOwnWarningTx.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeWarningTxs.java index f5b6bd2164f..53c11aa3cae 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerFinalizesOwnWarningTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/FinalizeWarningTxs.java @@ -15,10 +15,12 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.bisq_v5.tasks.buyer; +package bisq.core.trade.protocol.bisq_v5.tasks; import bisq.core.btc.wallet.TradeWalletService; +import bisq.core.trade.model.bisq_v1.BuyerTrade; import bisq.core.trade.model.bisq_v1.Trade; +import bisq.core.trade.protocol.bisq_v1.model.TradingPeer; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.common.taskrunner.TaskRunner; @@ -29,8 +31,8 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class BuyerFinalizesOwnWarningTx extends TradeTask { - public BuyerFinalizesOwnWarningTx(TaskRunner taskHandler, Trade trade) { +public class FinalizeWarningTxs extends TradeTask { + public FinalizeWarningTxs(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -40,13 +42,20 @@ protected void run() { runInterceptHook(); TradeWalletService tradeWalletService = processModel.getTradeWalletService(); + TradingPeer tradingPeer = processModel.getTradePeer(); + + // Get pubKeys and input value. + Transaction depositTx = processModel.getBtcWalletService().getTxFromSerializedTx(processModel.getPreparedDepositTx()); + Coin inputValue = depositTx.getOutput(0).getValue(); + boolean amBuyer = trade instanceof BuyerTrade; + byte[] buyerPubKey = amBuyer ? processModel.getMyMultiSigPubKey() : tradingPeer.getMultiSigPubKey(); + byte[] sellerPubKey = amBuyer ? tradingPeer.getMultiSigPubKey() : processModel.getMyMultiSigPubKey(); + + // Finalize our warning tx. Transaction warningTx = processModel.getWarningTx(); - byte[] buyerPubKey = processModel.getMyMultiSigPubKey(); - byte[] sellerPubKey = processModel.getTradePeer().getMultiSigPubKey(); byte[] buyerSignature = processModel.getWarningTxBuyerSignature(); byte[] sellerSignature = processModel.getWarningTxSellerSignature(); - Transaction depositTx = processModel.getBtcWalletService().getTxFromSerializedTx(processModel.getPreparedDepositTx()); - Coin inputValue = depositTx.getOutput(0).getValue(); + Transaction finalizedWarningTx = tradeWalletService.finalizeWarningTx(warningTx, buyerPubKey, sellerPubKey, @@ -55,6 +64,19 @@ protected void run() { inputValue); processModel.setFinalizedWarningTx(finalizedWarningTx); + // Finalize peer's warning tx. + Transaction peersWarningTx = tradingPeer.getWarningTx(); + byte[] peerBuyerSignature = tradingPeer.getWarningTxBuyerSignature(); + byte[] peerSellerSignature = tradingPeer.getWarningTxSellerSignature(); + + Transaction peersFinalizedWarningTx = tradeWalletService.finalizeWarningTx(peersWarningTx, + buyerPubKey, + sellerPubKey, + peerBuyerSignature, + peerSellerSignature, + inputValue); + tradingPeer.setFinalizedWarningTx(peersFinalizedWarningTx); + processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java index 4451515f76e..78b8d2c2fa4 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java @@ -19,8 +19,10 @@ import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.trade.model.bisq_v1.BuyerAsMakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.model.ProcessModel; +import bisq.core.trade.protocol.bisq_v1.model.TradingPeer; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5; @@ -56,6 +58,7 @@ protected void run() { try { runInterceptHook(); + TradingPeer tradePeer = processModel.getTradePeer(); BtcWalletService walletService = processModel.getBtcWalletService(); String id = processModel.getOffer().getId(); @@ -79,13 +82,13 @@ protected void run() { byte[] hashOfMakersPaymentAccountPayload = ProcessModel.hashOfPaymentAccountPayload(processModel.getPaymentAccountPayload(trade)); String makersPaymentMethodId = checkNotNull(processModel.getPaymentAccountPayload(trade)).getPaymentMethodId(); -// byte[] buyersUnsignedWarningTx = processModel.getWarningTx().bitcoinSerialize(); String makersWarningTxFeeBumpAddress = processModel.getWarningTxFeeBumpAddress(); String makersRedirectTxFeeBumpAddress = processModel.getRedirectTxFeeBumpAddress(); - byte[] buyersWarningTxMakerSignature = processModel.getWarningTxBuyerSignature(); - byte[] sellersWarningTxMakerSignature = processModel.getTradePeer().getWarningTxBuyerSignature(); - byte[] buyersRedirectTxMakerSignature = processModel.getRedirectTxBuyerSignature(); - byte[] sellersRedirectTxMakerSignature = processModel.getTradePeer().getRedirectTxBuyerSignature(); + boolean isBuyerMaker = trade instanceof BuyerAsMakerTrade; + byte[] buyersWarningTxMakerSignature = isBuyerMaker ? processModel.getWarningTxBuyerSignature() : tradePeer.getWarningTxSellerSignature(); + byte[] sellersWarningTxMakerSignature = isBuyerMaker ? tradePeer.getWarningTxBuyerSignature() : processModel.getWarningTxSellerSignature(); + byte[] buyersRedirectTxMakerSignature = isBuyerMaker ? processModel.getRedirectTxBuyerSignature() : tradePeer.getRedirectTxSellerSignature(); + byte[] sellersRedirectTxMakerSignature = isBuyerMaker ? tradePeer.getRedirectTxBuyerSignature() : processModel.getRedirectTxSellerSignature(); InputsForDepositTxResponse_v5 message = new InputsForDepositTxResponse_v5( processModel.getOfferId(), @@ -117,7 +120,7 @@ protected void run() { message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); processModel.getP2PService().sendEncryptedDirectMessage( peersNodeAddress, - processModel.getTradePeer().getPubKeyRing(), + tradePeer.getPubKeyRing(), message, new SendDirectMessageListener() { @Override diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerCreatesWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerCreatesWarningTx.java deleted file mode 100644 index c70daa7fabe..00000000000 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerCreatesWarningTx.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.core.trade.protocol.bisq_v5.tasks.seller; - -import bisq.core.btc.model.AddressEntry; -import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.btc.wallet.TradeWalletService; -import bisq.core.trade.model.bisq_v1.Trade; -import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; -import bisq.core.trade.protocol.bisq_v5.model.StagedPayoutTxParameters; - -import bisq.common.taskrunner.TaskRunner; -import bisq.common.util.Tuple2; - -import org.bitcoinj.core.Transaction; -import org.bitcoinj.core.TransactionOutput; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class SellerCreatesWarningTx extends TradeTask { - public SellerCreatesWarningTx(TaskRunner taskHandler, Trade trade) { - super(taskHandler, trade); - } - - @Override - protected void run() { - try { - runInterceptHook(); - - TradeWalletService tradeWalletService = processModel.getTradeWalletService(); - BtcWalletService btcWalletService = processModel.getBtcWalletService(); - String tradeId = processModel.getOffer().getId(); - - Transaction depositTx = processModel.getDepositTx(); - TransactionOutput depositTxOutput = depositTx.getOutput(0); - long lockTime = trade.getLockTime(); - byte[] buyerPubKey = processModel.getTradePeer().getMultiSigPubKey(); - byte[] sellerPubKey = processModel.getMyMultiSigPubKey(); - long claimDelay = StagedPayoutTxParameters.CLAIM_DELAY; - long miningFee = StagedPayoutTxParameters.getWarningTxMiningFee(trade.getDepositTxFeeRate()); - AddressEntry feeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.WARNING_TX_FEE_BUMP); - Tuple2 feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.WARNING_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddressEntry.getAddressString()); - Transaction unsignedWarningTx = tradeWalletService.createUnsignedWarningTx(false, - depositTxOutput, - lockTime, - buyerPubKey, - sellerPubKey, - claimDelay, - miningFee, - feeBumpOutputAmountAndAddress); - processModel.setWarningTx(unsignedWarningTx); - - processModel.getTradeManager().requestPersistence(); - - complete(); - } catch (Throwable t) { - failed(t); - } - } -} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnWarningTx.java deleted file mode 100644 index 2dab31c15e0..00000000000 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerFinalizesOwnWarningTx.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.core.trade.protocol.bisq_v5.tasks.seller; - -import bisq.core.btc.wallet.TradeWalletService; -import bisq.core.trade.model.bisq_v1.Trade; -import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; - -import bisq.common.taskrunner.TaskRunner; - -import org.bitcoinj.core.Coin; -import org.bitcoinj.core.Transaction; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class SellerFinalizesOwnWarningTx extends TradeTask { - public SellerFinalizesOwnWarningTx(TaskRunner taskHandler, Trade trade) { - super(taskHandler, trade); - } - - @Override - protected void run() { - try { - runInterceptHook(); - - TradeWalletService tradeWalletService = processModel.getTradeWalletService(); - Transaction warningTx = processModel.getWarningTx(); - byte[] buyerPubKey = processModel.getTradePeer().getMultiSigPubKey(); - byte[] sellerPubKey = processModel.getMyMultiSigPubKey(); - byte[] buyerSignature = processModel.getWarningTxBuyerSignature(); - byte[] sellerSignature = processModel.getWarningTxSellerSignature(); - Coin inputValue = processModel.getDepositTx().getOutput(0).getValue(); - Transaction finalizedWarningTx = tradeWalletService.finalizeWarningTx(warningTx, - buyerPubKey, - sellerPubKey, - buyerSignature, - sellerSignature, - inputValue); - processModel.setFinalizedWarningTx(finalizedWarningTx); - - processModel.getTradeManager().requestPersistence(); - - complete(); - } catch (Throwable t) { - failed(t); - } - } -} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java index dc8c3332c85..a7304ec51c2 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java @@ -17,6 +17,7 @@ package bisq.core.trade.protocol.bisq_v5.tasks.seller; +import bisq.core.trade.model.bisq_v1.SellerAsMakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; @@ -43,11 +44,13 @@ protected void run() { checkNotNull(message); checkTradeId(processModel.getOfferId(), message); - // TODO: Maybe check other signatures match what the seller-as-taker would have already got. - processModel.getTradePeer().setWarningTxBuyerSignature(message.getBuyersWarningTxBuyerSignature()); - processModel.setWarningTxBuyerSignature(message.getSellersWarningTxBuyerSignature()); - processModel.getTradePeer().setRedirectTxBuyerSignature(message.getBuyersRedirectTxBuyerSignature()); - processModel.setRedirectTxBuyerSignature(message.getSellersRedirectTxBuyerSignature()); + // TODO: Maybe check signatures in the message match what the seller-as-taker would have already got. + if (trade instanceof SellerAsMakerTrade) { + processModel.getTradePeer().setWarningTxBuyerSignature(message.getBuyersWarningTxBuyerSignature()); + processModel.setWarningTxBuyerSignature(message.getSellersWarningTxBuyerSignature()); + processModel.getTradePeer().setRedirectTxBuyerSignature(message.getBuyersRedirectTxBuyerSignature()); + processModel.setRedirectTxBuyerSignature(message.getSellersRedirectTxBuyerSignature()); + } processModel.getTradeWalletService().sellerAddsBuyerWitnessesToDepositTx( processModel.getDepositTx(), diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsOwnWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsOwnWarningTx.java index 15419817f9c..6ef8a7b2be2 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsOwnWarningTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsOwnWarningTx.java @@ -46,7 +46,8 @@ protected void run() { String tradeId = processModel.getOffer().getId(); Transaction unsignedWarningTx = processModel.getWarningTx(); - TransactionOutput depositTxOutput = processModel.getDepositTx().getOutput(0); + Transaction depositTx = btcWalletService.getTxFromSerializedTx(processModel.getPreparedDepositTx()); + TransactionOutput depositTxOutput = depositTx.getOutput(0); byte[] sellerPubKey = processModel.getMyMultiSigPubKey(); DeterministicKey myMultiSigKeyPair = btcWalletService.getMultiSigKeyPair(tradeId, sellerPubKey); byte[] buyerPubKey = processModel.getTradePeer().getMultiSigPubKey(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsPeersWarningTx.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsPeersWarningTx.java index 5da52a23bae..f485458316d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsPeersWarningTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerSignsPeersWarningTx.java @@ -31,8 +31,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkNotNull; - @Slf4j public class SellerSignsPeersWarningTx extends TradeTask { public SellerSignsPeersWarningTx(TaskRunner taskHandler, Trade trade) { @@ -50,7 +48,8 @@ protected void run() { TradingPeer tradingPeer = processModel.getTradePeer(); Transaction peersWarningTx = tradingPeer.getWarningTx(); - TransactionOutput depositTxOutput = checkNotNull(processModel.getDepositTx()).getOutput(0); + Transaction depositTx = btcWalletService.getTxFromSerializedTx(processModel.getPreparedDepositTx()); + TransactionOutput depositTxOutput = depositTx.getOutput(0); byte[] sellerPubKey = processModel.getMyMultiSigPubKey(); DeterministicKey myMultiSigKeyPair = btcWalletService.getMultiSigKeyPair(tradeId, sellerPubKey); byte[] buyerPubKey = tradingPeer.getMultiSigPubKey(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java index 4162407738d..cbb736f6148 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java @@ -19,6 +19,7 @@ import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.Restrictions; +import bisq.core.trade.model.bisq_v1.SellerAsTakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.bisq_v1.model.TradingPeer; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; @@ -90,12 +91,19 @@ protected void run() { checkArgument(response.getMakerInputs().size() > 0); -// byte[] tx = checkNotNull(response.getBuyersUnsignedWarningTx()); -// Transaction buyersUnsignedWarningTx = btcWalletService.getTxFromSerializedTx(tx); -// tradingPeer.setWarningTx(buyersUnsignedWarningTx); -// tradingPeer.setWarningTxBuyerSignature(response.getBuyersWarningTxSignature()); tradingPeer.setWarningTxFeeBumpAddress(response.getMakersWarningTxFeeBumpAddress()); tradingPeer.setRedirectTxFeeBumpAddress(response.getMakersRedirectTxFeeBumpAddress()); + if (trade instanceof SellerAsTakerTrade) { + processModel.setWarningTxBuyerSignature(response.getSellersWarningTxMakerSignature()); + tradingPeer.setWarningTxBuyerSignature(response.getBuyersWarningTxMakerSignature()); + processModel.setRedirectTxBuyerSignature(response.getSellersRedirectTxMakerSignature()); + tradingPeer.setRedirectTxBuyerSignature(response.getBuyersRedirectTxMakerSignature()); + } else { + processModel.setWarningTxSellerSignature(response.getBuyersWarningTxMakerSignature()); + tradingPeer.setWarningTxSellerSignature(response.getSellersWarningTxMakerSignature()); + processModel.setRedirectTxSellerSignature(response.getBuyersRedirectTxMakerSignature()); + tradingPeer.setRedirectTxSellerSignature(response.getSellersRedirectTxMakerSignature()); + } // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());