From f21dcfbbc8498624ff13f00dbf6011867463a00c Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Fri, 17 May 2024 19:11:43 +0200 Subject: [PATCH] Temp changes --- .../network/CoreNetworkProtoResolver.java | 23 ++- .../messages/InputsForDepositTxRequest.java | 26 +++- .../protocol/bisq_v1/model/ProcessModel.java | 5 + .../protocol/bisq_v1/model/TradingPeer.java | 5 + ...kerProcessesInputsForDepositTxRequest.java | 3 + .../TakerSendInputsForDepositTxRequest.java | 4 +- .../bisq_v5/BaseBuyerProtocol_v5.java | 7 +- .../bisq_v5/BaseSellerProtocol_v5.java | 21 +-- .../bisq_v5/BuyerAsMakerProtocol_v5.java | 138 +++++++++--------- .../bisq_v5/BuyerAsTakerProtocol_v5.java | 51 +++---- .../bisq_v5/SellerAsMakerProtocol_v5.java | 60 ++++---- .../bisq_v5/SellerAsTakerProtocol_v5.java | 86 +++++------ .../BuyersRedirectSellerSignatureRequest.java | 52 ++++--- ...BuyersRedirectSellerSignatureResponse.java | 40 +++-- .../InputsForDepositTxResponse_v5.java | 69 ++++++--- .../PreparedTxBuyerSignaturesMessage.java | 108 ++++++++++++++ .../PreparedTxBuyerSignaturesRequest.java | 102 +++++++++++++ .../messages/StagedPayoutTxRequest.java | 54 ++++--- .../tasks/CreateFeeBumpAddressEntries.java | 53 +++++++ ...SendsPreparedTxBuyerSignaturesMessage.java | 89 +++++++++++ ...ocessPreparedTxBuyerSignaturesRequest.java | 58 ++++++++ ...erSendsInputsForDepositTxResponse_v5.java} | 30 ++-- ...ocessPreparedTxBuyerSignaturesMessage.java | 67 +++++++++ ...SendsPreparedTxBuyerSignaturesRequest.java | 87 +++++++++++ ...ProcessInputsForDepositTxResponse_v5.java} | 19 ++- proto/src/main/proto/pb.proto | 125 ++++++++++++---- 26 files changed, 1029 insertions(+), 353 deletions(-) create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesRequest.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateFeeBumpAddressEntries.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerSendsPreparedTxBuyerSignaturesMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.java rename core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/{buyer_as_maker/BuyerAsMakerSendsInputsForDepositTxResponse_v5.java => maker/MakerSendsInputsForDepositTxResponse_v5.java} (82%) create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java create mode 100644 core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerSendsPreparedTxBuyerSignaturesRequest.java rename core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/{seller_as_taker/SellerAsTakerProcessesInputsForDepositTxResponse_v5.java => taker/TakerProcessInputsForDepositTxResponse_v5.java} (86%) diff --git a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java index 23f18ce0a91..abdc2ce42b0 100644 --- a/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java +++ b/core/src/main/java/bisq/core/proto/network/CoreNetworkProtoResolver.java @@ -66,10 +66,9 @@ import bisq.core.trade.protocol.bisq_v1.messages.RefreshTradeStateRequest; import bisq.core.trade.protocol.bisq_v1.messages.ShareBuyerPaymentAccountMessage; import bisq.core.trade.protocol.bisq_v1.messages.TraderSignedWitnessMessage; -import bisq.core.trade.protocol.bisq_v5.messages.BuyersRedirectSellerSignatureRequest; -import bisq.core.trade.protocol.bisq_v5.messages.BuyersRedirectSellerSignatureResponse; import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5; -import bisq.core.trade.protocol.bisq_v5.messages.StagedPayoutTxRequest; +import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; +import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesRequest; import bisq.core.trade.protocol.bsq_swap.messages.BsqSwapFinalizeTxRequest; import bisq.core.trade.protocol.bsq_swap.messages.BsqSwapFinalizedTxMessage; import bisq.core.trade.protocol.bsq_swap.messages.BsqSwapTxInputsMessage; @@ -270,17 +269,15 @@ public NetworkEnvelope fromProto(protobuf.NetworkEnvelope proto) throws Protobuf // Trade protocol v5 messages case INPUTS_FOR_DEPOSIT_TX_RESPONSE_V_5: - return InputsForDepositTxResponse_v5.fromProto(proto.getInputsForDepositTxResponseV5(), this, messageVersion); - case STAGED_PAYOUT_TX_REQUEST: - return StagedPayoutTxRequest.fromProto(proto.getStagedPayoutTxRequest(), messageVersion); - case BUYERS_REDIRECT_SELLER_SIGNATURE_REQUEST: - return BuyersRedirectSellerSignatureRequest.fromProto(proto.getBuyersRedirectSellerSignatureRequest(), messageVersion); - case BUYERS_REDIRECT_SELLER_SIGNATURE_RESPONSE: - return BuyersRedirectSellerSignatureResponse.fromProto(proto.getBuyersRedirectSellerSignatureResponse(), messageVersion); + return InputsForDepositTxResponse_v5.fromProto(proto.getInputsForDepositTxResponseV5(), messageVersion); + case PREPARED_TX_BUYER_SIGNATURES_REQUEST: + return PreparedTxBuyerSignaturesRequest.fromProto(proto.getPreparedTxBuyerSignaturesRequest(), messageVersion); + case PREPARED_TX_BUYER_SIGNATURES_MESSAGE: + return PreparedTxBuyerSignaturesMessage.fromProto(proto.getPreparedTxBuyerSignaturesMessage(), messageVersion); default: throw new ProtobufferException("Unknown proto message case (PB.NetworkEnvelope). messageCase=" + - proto.getMessageCase() + "; proto raw data=" + proto.toString()); + proto.getMessageCase() + "; proto raw data=" + proto); } } else { log.error("PersistableEnvelope.fromProto: PB.NetworkEnvelope is null"); @@ -297,7 +294,7 @@ public NetworkPayload fromProto(protobuf.StorageEntryWrapper proto) { return ProtectedStorageEntry.fromProto(proto.getProtectedStorageEntry(), this); default: throw new ProtobufferRuntimeException("Unknown proto message case(PB.StorageEntryWrapper). " + - "messageCase=" + proto.getMessageCase() + "; proto raw data=" + proto.toString()); + "messageCase=" + proto.getMessageCase() + "; proto raw data=" + proto); } } else { log.error("PersistableEnvelope.fromProto: PB.StorageEntryWrapper is null"); @@ -328,7 +325,7 @@ public NetworkPayload fromProto(protobuf.StoragePayload proto) { return TempProposalPayload.fromProto(proto.getTempProposalPayload()); default: throw new ProtobufferRuntimeException("Unknown proto message case (PB.StoragePayload). messageCase=" - + proto.getMessageCase() + "; proto raw data=" + proto.toString()); + + proto.getMessageCase() + "; proto raw data=" + proto); } } else { log.error("PersistableEnvelope.fromProto: PB.StoragePayload is null"); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java index 7725a66b81c..70e8cc8dc5f 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/messages/InputsForDepositTxRequest.java @@ -83,6 +83,10 @@ public final class InputsForDepositTxRequest extends TradeMessage implements Dir // Added in v 1.9.7 private final int burningManSelectionHeight; + // Added for v5 protocol + private final String takersWarningTxFeeBumpAddress; + private final String takersRedirectTxFeeBumpAddress; + public InputsForDepositTxRequest(String tradeId, NodeAddress senderNodeAddress, long tradeAmount, @@ -111,7 +115,9 @@ public InputsForDepositTxRequest(String tradeId, long currentDate, @Nullable byte[] hashOfTakersPaymentAccountPayload, @Nullable String takersPaymentMethodId, - int burningManSelectionHeight) { + int burningManSelectionHeight, + String takersWarningTxFeeBumpAddress, + String takersRedirectTxFeeBumpAddress) { super(messageVersion, tradeId, uid); this.senderNodeAddress = senderNodeAddress; this.tradeAmount = tradeAmount; @@ -139,6 +145,8 @@ public InputsForDepositTxRequest(String tradeId, this.hashOfTakersPaymentAccountPayload = hashOfTakersPaymentAccountPayload; this.takersPaymentMethodId = takersPaymentMethodId; this.burningManSelectionHeight = burningManSelectionHeight; + this.takersWarningTxFeeBumpAddress = takersWarningTxFeeBumpAddress; + this.takersRedirectTxFeeBumpAddress = takersRedirectTxFeeBumpAddress; } @@ -178,10 +186,12 @@ public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { .setBurningManSelectionHeight(burningManSelectionHeight); Optional.ofNullable(changeOutputAddress).ifPresent(builder::setChangeOutputAddress); - Optional.ofNullable(arbitratorNodeAddress).ifPresent(e -> builder.setArbitratorNodeAddress(arbitratorNodeAddress.toProtoMessage())); - Optional.ofNullable(takerPaymentAccountPayload).ifPresent(e -> builder.setTakerPaymentAccountPayload((protobuf.PaymentAccountPayload) takerPaymentAccountPayload.toProtoMessage())); - Optional.ofNullable(hashOfTakersPaymentAccountPayload).ifPresent(e -> builder.setHashOfTakersPaymentAccountPayload(ByteString.copyFrom(hashOfTakersPaymentAccountPayload))); - Optional.ofNullable(takersPaymentMethodId).ifPresent(e -> builder.setTakersPayoutMethodId(takersPaymentMethodId)); + Optional.ofNullable(arbitratorNodeAddress).ifPresent(e -> builder.setArbitratorNodeAddress(e.toProtoMessage())); + Optional.ofNullable(takerPaymentAccountPayload).ifPresent(e -> builder.setTakerPaymentAccountPayload((protobuf.PaymentAccountPayload) e.toProtoMessage())); + Optional.ofNullable(hashOfTakersPaymentAccountPayload).ifPresent(e -> builder.setHashOfTakersPaymentAccountPayload(ByteString.copyFrom(e))); + Optional.ofNullable(takersPaymentMethodId).ifPresent(builder::setTakersPayoutMethodId); + Optional.ofNullable(takersWarningTxFeeBumpAddress).ifPresent(builder::setTakersWarningTxFeeBumpAddress); + Optional.ofNullable(takersRedirectTxFeeBumpAddress).ifPresent(builder::setTakersRedirectTxFeeBumpAddress); return getNetworkEnvelopeBuilder().setInputsForDepositTxRequest(builder).build(); } @@ -230,7 +240,9 @@ public static InputsForDepositTxRequest fromProto(protobuf.InputsForDepositTxReq proto.getCurrentDate(), hashOfTakersPaymentAccountPayload, ProtoUtil.stringOrNullFromProto(proto.getTakersPayoutMethodId()), - proto.getBurningManSelectionHeight()); + proto.getBurningManSelectionHeight(), + ProtoUtil.stringOrNullFromProto(proto.getTakersWarningTxFeeBumpAddress()), + ProtoUtil.stringOrNullFromProto(proto.getTakersRedirectTxFeeBumpAddress())); } @Override @@ -261,6 +273,8 @@ public String toString() { ",\n hashOfTakersPaymentAccountPayload=" + Utilities.bytesAsHexString(hashOfTakersPaymentAccountPayload) + ",\n takersPaymentMethodId=" + takersPaymentMethodId + ",\n burningManSelectionHeight=" + burningManSelectionHeight + + ",\n takersWarningTxFeeBumpAddress=" + takersWarningTxFeeBumpAddress + + ",\n takersRedirectTxFeeBumpAddress=" + takersRedirectTxFeeBumpAddress + "\n} " + super.toString(); } } 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 f033b38daaa..f712b286b80 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 @@ -105,6 +105,11 @@ public static byte[] hashOfPaymentAccountPayload(PaymentAccountPayload paymentAc // Added in v 1.9.13 for trade protocol 5 /////////////////////////////////////////////////////////////////////////////////////////// + @Setter + transient private String warningTxFeeBumpAddress; + @Setter + transient private String redirectTxFeeBumpAddress; + @Setter transient private Transaction warningTx; @Setter 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 6b15f1565d9..1acb45a5dbb 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 @@ -52,6 +52,11 @@ public final class TradingPeer implements TradePeer { // Added in v 1.9.13 for trade protocol 5 /////////////////////////////////////////////////////////////////////////////////////////// + @Setter + transient private String warningTxFeeBumpAddress; + @Setter + transient private String redirectTxFeeBumpAddress; + @Setter transient private Transaction warningTx; @Setter diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/maker/MakerProcessesInputsForDepositTxRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/maker/MakerProcessesInputsForDepositTxRequest.java index 395d400893e..a161f9b26f6 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/maker/MakerProcessesInputsForDepositTxRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/maker/MakerProcessesInputsForDepositTxRequest.java @@ -125,6 +125,9 @@ protected void run() { trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); + tradingPeer.setWarningTxFeeBumpAddress(request.getTakersWarningTxFeeBumpAddress()); + tradingPeer.setRedirectTxFeeBumpAddress(request.getTakersRedirectTxFeeBumpAddress()); + processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/taker/TakerSendInputsForDepositTxRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/taker/TakerSendInputsForDepositTxRequest.java index a5df2116a9b..7e23f93ab4b 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/taker/TakerSendInputsForDepositTxRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v1/tasks/taker/TakerSendInputsForDepositTxRequest.java @@ -137,7 +137,9 @@ protected void run() { new Date().getTime(), hashOfTakersPaymentAccountPayload, takersPaymentMethodId, - burningManSelectionHeight); + burningManSelectionHeight, + processModel.getWarningTxFeeBumpAddress(), + processModel.getRedirectTxFeeBumpAddress()); log.info("Send {} with offerId {} and uid {} to peer {}", request.getClass().getSimpleName(), request.getTradeId(), request.getUid(), trade.getTradingPeerNodeAddress()); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseBuyerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseBuyerProtocol_v5.java index 932aa8ff80a..ab6c558879a 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseBuyerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseBuyerProtocol_v5.java @@ -24,7 +24,6 @@ import bisq.core.trade.protocol.TradeMessage; import bisq.core.trade.protocol.TradeTaskRunner; import bisq.core.trade.protocol.bisq_v1.DisputeProtocol; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureRequest; import bisq.core.trade.protocol.bisq_v1.messages.DepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; @@ -100,7 +99,7 @@ public void onMailboxMessage(TradeMessage message, NodeAddress peer) { } } - protected abstract void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer); +// protected abstract void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer); // The DepositTxAndDelayedPayoutTxMessage is a mailbox message. Earlier we used only the deposit tx which can // be set also when received by the network once published by the peer so that message was not mandatory and could @@ -194,9 +193,7 @@ protected void onTradeMessage(TradeMessage message, NodeAddress peer) { log.info("Received {} from {} with tradeId {} and uid {}", message.getClass().getSimpleName(), peer, message.getTradeId(), message.getUid()); - if (message instanceof DelayedPayoutTxSignatureRequest) { - handle((DelayedPayoutTxSignatureRequest) message, peer); - } else if (message instanceof DepositTxAndDelayedPayoutTxMessage) { + if (message instanceof DepositTxAndDelayedPayoutTxMessage) { handle((DepositTxAndDelayedPayoutTxMessage) message, peer); } else if (message instanceof PayoutTxPublishedMessage) { handle((PayoutTxPublishedMessage) message, peer); diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseSellerProtocol_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseSellerProtocol_v5.java index 6e949f945f0..afb6b30629c 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseSellerProtocol_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/BaseSellerProtocol_v5.java @@ -25,21 +25,20 @@ import bisq.core.trade.protocol.TradeTaskRunner; import bisq.core.trade.protocol.bisq_v1.DisputeProtocol; import bisq.core.trade.protocol.bisq_v1.messages.CounterCurrencyTransferStartedMessage; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.messages.ShareBuyerPaymentAccountMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; import bisq.core.trade.protocol.bisq_v1.tasks.VerifyPeersAccountAgeWitness; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerBroadcastPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerFinalizesDelayedPayoutTx; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage; -import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerProcessDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerProcessShareBuyerPaymentAccountMessage; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerPublishesDepositTx; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerPublishesTradeStatistics; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSendPayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSendsDepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSignAndFinalizePayoutTx; +import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage; import bisq.network.p2p.NodeAddress; @@ -78,12 +77,12 @@ public void onMailboxMessage(TradeMessage message, NodeAddress peerNodeAddress) // Incoming messages /////////////////////////////////////////////////////////////////////////////////////////// - protected void handle(DelayedPayoutTxSignatureResponse message, NodeAddress peer) { + protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer) { expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) .with(message) .from(peer)) - .setup(tasks(SellerProcessDelayedPayoutTxSignatureResponse.class, - SellerFinalizesDelayedPayoutTx.class, + .setup(tasks(SellerProcessPreparedTxBuyerSignaturesMessage.class, +// SellerFinalizesDelayedPayoutTx.class, SellerSendsDepositTxAndDelayedPayoutTxMessage.class, SellerPublishesDepositTx.class, SellerPublishesTradeStatistics.class)) @@ -135,6 +134,7 @@ protected void handle(CounterCurrencyTransferStartedMessage message, NodeAddress .executeTasks(); } + /////////////////////////////////////////////////////////////////////////////////////////// // User interaction /////////////////////////////////////////////////////////////////////////////////////////// @@ -168,6 +168,10 @@ public void onPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler e } + /////////////////////////////////////////////////////////////////////////////////////////// + // Massage dispatcher + /////////////////////////////////////////////////////////////////////////////////////////// + @Override protected void onTradeMessage(TradeMessage message, NodeAddress peer) { log.info("Received {} from {} with tradeId {} and uid {}", @@ -175,8 +179,8 @@ protected void onTradeMessage(TradeMessage message, NodeAddress peer) { super.onTradeMessage(message, peer); - if (message instanceof DelayedPayoutTxSignatureResponse) { - handle((DelayedPayoutTxSignatureResponse) message, peer); + if (message instanceof PreparedTxBuyerSignaturesMessage) { + handle((PreparedTxBuyerSignaturesMessage) message, peer); } else if (message instanceof ShareBuyerPaymentAccountMessage) { handle((ShareBuyerPaymentAccountMessage) message, peer); } else if (message instanceof CounterCurrencyTransferStartedMessage) { @@ -185,5 +189,4 @@ protected void onTradeMessage(TradeMessage message, NodeAddress peer) { } abstract protected Class getVerifyPeersFeePaymentClass(); - } 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 9e5860f435b..6262520199e 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 @@ -22,38 +22,26 @@ import bisq.core.trade.protocol.MakerProtocol; import bisq.core.trade.protocol.TradeMessage; import bisq.core.trade.protocol.TradeTaskRunner; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureRequest; import bisq.core.trade.protocol.bisq_v1.messages.DepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest; import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSendsDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSetupDepositTxListener; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSignsDelayedPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerVerifiesPreparedDelayedPayoutTx; import bisq.core.trade.protocol.bisq_v1.tasks.buyer_as_maker.BuyerAsMakerCreatesAndSignsDepositTx; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerCreateAndSignContract; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerProcessesInputsForDepositTxRequest; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerRemovesOpenOffer; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerSetsLockTime; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerVerifyTakerFeePayment; -import bisq.core.trade.protocol.bisq_v5.messages.StagedPayoutTxRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTx; -import bisq.core.trade.protocol.bisq_v5.tasks.CreateSignedClaimTx; +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.buyer.BuyerFinalizesOwnWarningTx; -import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerProcessStagedPayoutTxRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsBuyersRedirectSellerSignatureRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage; 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.BuyerVerifiesWarningAndRedirectTxs; -import bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker.BuyerAsMakerSendsInputsForDepositTxResponse_v5; +import bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker.BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest; +import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5; import bisq.network.p2p.NodeAddress; @@ -114,10 +102,11 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, BuyerSetupDepositTxListener.class, // We create our warn tx and our signature for the MS script + CreateFeeBumpAddressEntries.class, BuyerCreatesWarningTx.class, BuyerSignsOwnWarningTx.class, - BuyerAsMakerSendsInputsForDepositTxResponse_v5.class) + MakerSendsInputsForDepositTxResponse_v5.class) .using(new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(message), @@ -134,64 +123,77 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, // Incoming messages Take offer process /////////////////////////////////////////////////////////////////////////////////////////// - protected void handle(StagedPayoutTxRequest message, NodeAddress peer) { + protected void handle(PreparedTxBuyerSignaturesRequest message, NodeAddress peer) { checkArgument(Version.isTradeProtocolVersion5Activated()); expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) .with(message) .from(peer)) .setup(tasks( - // We received the sellers sig for our warn tx and the sellers warn and redirect tx as well the sellers signatures - BuyerProcessStagedPayoutTxRequest.class, - BuyerVerifiesWarningAndRedirectTxs.class, - + BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.class, MakerRemovesOpenOffer.class, - - // We sign sellers warn and redirect tx - BuyerSignsPeersWarningTx.class, - BuyerSignsPeersRedirectTx.class, - - // We have now all for finalizing our warn tx - BuyerFinalizesOwnWarningTx.class, - - // We create and sign our redirect tx with the input from the sellers warn tx - CreateRedirectTx.class, - BuyerSignsOwnRedirectTx.class, - - // As we have our finalized warn tx, we can create the signed claim tx - CreateSignedClaimTx.class, - - // We have now: - // - our finalized warn tx - // - our signed claim tx - // - our redirect tx + our sig - // - // Missing: - // - sellers sig for our redirect tx - // - sellers sig for the deposit tx - - // We do not send yet the signed deposit tx as we require first to have all txs completed. - // We request from the seller the signature for the redirect tx - // We send seller the signatures for the sellers warn and redirect tx, - // as well as our redirect tx and its signature - BuyerSendsBuyersRedirectSellerSignatureRequest.class) + BuyerSendsPreparedTxBuyerSignaturesMessage.class) .withTimeout(120)) .executeTasks(); } - protected void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer) { - expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) - .with(message) - .from(peer)) - .setup(tasks( - MakerRemovesOpenOffer.class, - BuyerProcessDelayedPayoutTxSignatureRequest.class, - BuyerVerifiesPreparedDelayedPayoutTx.class, - BuyerSignsDelayedPayoutTx.class, - BuyerFinalizesDelayedPayoutTx.class, - BuyerSendsDelayedPayoutTxSignatureResponse.class) - .withTimeout(120)) - .executeTasks(); - } +// protected void handle(StagedPayoutTxRequest message, NodeAddress peer) { +// checkArgument(Version.isTradeProtocolVersion5Activated()); +// expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) +// .with(message) +// .from(peer)) +// .setup(tasks( +// // We received the sellers sig for our warn tx and the sellers warn and redirect tx as well the sellers signatures +// BuyerProcessStagedPayoutTxRequest.class, +// BuyerVerifiesWarningAndRedirectTxs.class, +// +// MakerRemovesOpenOffer.class, +// +// // We sign sellers warn and redirect tx +// BuyerSignsPeersWarningTx.class, +// BuyerSignsPeersRedirectTx.class, +// +// // We have now all for finalizing our warn tx +// BuyerFinalizesOwnWarningTx.class, +// +// // We create and sign our redirect tx with the input from the sellers warn tx +// CreateRedirectTx.class, +// BuyerSignsOwnRedirectTx.class, +// +// // As we have our finalized warn tx, we can create the signed claim tx +// CreateSignedClaimTx.class, +// +// // We have now: +// // - our finalized warn tx +// // - our signed claim tx +// // - our redirect tx + our sig +// // +// // Missing: +// // - sellers sig for our redirect tx +// // - sellers sig for the deposit tx +// +// // We do not send yet the signed deposit tx as we require first to have all txs completed. +// // We request from the seller the signature for the redirect tx +// // We send seller the signatures for the sellers warn and redirect tx, +// // as well as our redirect tx and its signature +// BuyerSendsBuyersRedirectSellerSignatureRequest.class) +// .withTimeout(120)) +// .executeTasks(); +// } +// +// protected void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer) { +// expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) +// .with(message) +// .from(peer)) +// .setup(tasks( +// MakerRemovesOpenOffer.class, +// BuyerProcessDelayedPayoutTxSignatureRequest.class, +// BuyerVerifiesPreparedDelayedPayoutTx.class, +// BuyerSignsDelayedPayoutTx.class, +// BuyerFinalizesDelayedPayoutTx.class, +// BuyerSendsDelayedPayoutTxSignatureResponse.class) +// .withTimeout(120)) +// .executeTasks(); +// } @Override protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress peer) { @@ -227,8 +229,8 @@ protected void handle(PayoutTxPublishedMessage message, NodeAddress peer) { protected void onTradeMessage(TradeMessage message, NodeAddress peer) { super.onTradeMessage(message, peer); - if (message instanceof StagedPayoutTxRequest) { - handle((StagedPayoutTxRequest) message, peer); + if (message instanceof PreparedTxBuyerSignaturesRequest) { + handle((PreparedTxBuyerSignaturesRequest) message, peer); } } 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 e7f9ef258c9..9a56557b6dd 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 @@ -17,34 +17,28 @@ package bisq.core.trade.protocol.bisq_v5; - import bisq.core.offer.Offer; import bisq.core.trade.model.bisq_v1.BuyerAsTakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.TakerProtocol; import bisq.core.trade.protocol.TradeMessage; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureRequest; import bisq.core.trade.protocol.bisq_v1.messages.DepositTxAndDelayedPayoutTxMessage; -import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxResponse; import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSendsDelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSetupDepositTxListener; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSignsDelayedPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerVerifiesPreparedDelayedPayoutTx; import bisq.core.trade.protocol.bisq_v1.tasks.buyer_as_taker.BuyerAsTakerCreatesDepositTxInputs; -import bisq.core.trade.protocol.bisq_v1.tasks.buyer_as_taker.BuyerAsTakerSendsDepositTxMessage; import bisq.core.trade.protocol.bisq_v1.tasks.buyer_as_taker.BuyerAsTakerSignsDepositTx; import bisq.core.trade.protocol.bisq_v1.tasks.taker.CreateTakerFeeTx; -import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerProcessesInputsForDepositTxResponse; import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerPublishFeeTx; import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerSendInputsForDepositTxRequest; 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.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage; +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; @@ -99,6 +93,7 @@ public void onTakeOffer() { getVerifyPeersFeePaymentClass(), CreateTakerFeeTx.class, BuyerAsTakerCreatesDepositTxInputs.class, + CreateFeeBumpAddressEntries.class, TakerSendInputsForDepositTxRequest.class) .withTimeout(120)) .run(() -> { @@ -113,34 +108,34 @@ public void onTakeOffer() { // Incoming messages Take offer process /////////////////////////////////////////////////////////////////////////////////////////// - private void handle(InputsForDepositTxResponse message, NodeAddress peer) { + private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) { expect(phase(Trade.Phase.INIT) .with(message) .from(peer)) - .setup(tasks(TakerProcessesInputsForDepositTxResponse.class, + .setup(tasks(TakerProcessInputsForDepositTxResponse_v5.class, ApplyFilter.class, TakerVerifyAndSignContract.class, TakerPublishFeeTx.class, BuyerAsTakerSignsDepositTx.class, BuyerSetupDepositTxListener.class, - BuyerAsTakerSendsDepositTxMessage.class) + BuyerSendsPreparedTxBuyerSignaturesMessage.class) .withTimeout(120)) .executeTasks(); } - protected void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer) { - expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) - .with(message) - .from(peer)) - .setup(tasks( - BuyerProcessDelayedPayoutTxSignatureRequest.class, - BuyerVerifiesPreparedDelayedPayoutTx.class, - BuyerSignsDelayedPayoutTx.class, - BuyerFinalizesDelayedPayoutTx.class, - BuyerSendsDelayedPayoutTxSignatureResponse.class) - .withTimeout(120)) - .executeTasks(); - } +// protected void handle(DelayedPayoutTxSignatureRequest message, NodeAddress peer) { +// expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) +// .with(message) +// .from(peer)) +// .setup(tasks( +// BuyerProcessDelayedPayoutTxSignatureRequest.class, +// BuyerVerifiesPreparedDelayedPayoutTx.class, +// BuyerSignsDelayedPayoutTx.class, +// BuyerFinalizesDelayedPayoutTx.class, +// BuyerSendsDelayedPayoutTxSignatureResponse.class) +// .withTimeout(120)) +// .executeTasks(); +// } @Override protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress peer) { @@ -176,8 +171,8 @@ protected void handle(PayoutTxPublishedMessage message, NodeAddress peer) { protected void onTradeMessage(TradeMessage message, NodeAddress peer) { super.onTradeMessage(message, peer); - if (message instanceof InputsForDepositTxResponse) { - handle((InputsForDepositTxResponse) message, peer); + if (message instanceof InputsForDepositTxResponse_v5) { + handle((InputsForDepositTxResponse_v5) message, peer); } } 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 04f62b74e7a..09fc62e93bf 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 @@ -17,15 +17,12 @@ package bisq.core.trade.protocol.bisq_v5; - import bisq.core.trade.model.bisq_v1.SellerAsMakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.MakerProtocol; import bisq.core.trade.protocol.TradeMessage; import bisq.core.trade.protocol.TradeTaskRunner; import bisq.core.trade.protocol.bisq_v1.messages.CounterCurrencyTransferStartedMessage; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureResponse; -import bisq.core.trade.protocol.bisq_v1.messages.DepositTxMessage; import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest; import bisq.core.trade.protocol.bisq_v1.messages.ShareBuyerPaymentAccountMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; @@ -37,13 +34,15 @@ import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerSetsLockTime; import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerVerifyTakerFeePayment; import bisq.core.trade.protocol.bisq_v1.tasks.seller.MaybeCreateSubAccount; -import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerCreatesDelayedPayoutTx; -import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSendDelayedPayoutTxSignatureRequest; -import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSignsDelayedPayoutTx; +import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerPublishesDepositTx; +import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerPublishesTradeStatistics; +import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerSendsDepositTxAndDelayedPayoutTxMessage; import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerCreatesUnsignedDepositTx; import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerFinalizesDepositTx; -import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerProcessDepositTxMessage; -import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerSendsInputsForDepositTxResponse; +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.maker.MakerSendsInputsForDepositTxResponse_v5; +import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage; import bisq.network.p2p.NodeAddress; @@ -94,7 +93,8 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, MakerSetsLockTime.class, MakerCreateAndSignContract.class, SellerAsMakerCreatesUnsignedDepositTx.class, - SellerAsMakerSendsInputsForDepositTxResponse.class) + CreateFeeBumpAddressEntries.class, + MakerSendsInputsForDepositTxResponse_v5.class) .using(new TradeTaskRunner(trade, () -> handleTaskRunnerSuccess(message), errorMessage -> { @@ -110,26 +110,37 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message, // Incoming messages Take offer process /////////////////////////////////////////////////////////////////////////////////////////// - protected void handle(DepositTxMessage message, NodeAddress peer) { +// protected void handle(DepositTxMessage message, NodeAddress peer) { +// expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) +// .with(message) +// .from(peer)) +// .setup(tasks( +// MakerRemovesOpenOffer.class, +// SellerAsMakerProcessDepositTxMessage.class, +// SellerAsMakerFinalizesDepositTx.class, +// SellerCreatesDelayedPayoutTx.class, +// SellerSignsDelayedPayoutTx.class, +// SellerSendDelayedPayoutTxSignatureRequest.class) +// .withTimeout(120)) +// .executeTasks(); +// } + + @Override + protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer) { expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) .with(message) .from(peer)) .setup(tasks( - MakerRemovesOpenOffer.class, - SellerAsMakerProcessDepositTxMessage.class, + SellerProcessPreparedTxBuyerSignaturesMessage.class, SellerAsMakerFinalizesDepositTx.class, - SellerCreatesDelayedPayoutTx.class, - SellerSignsDelayedPayoutTx.class, - SellerSendDelayedPayoutTxSignatureRequest.class) - .withTimeout(120)) +// SellerFinalizesDelayedPayoutTx.class, + MakerRemovesOpenOffer.class, + SellerSendsDepositTxAndDelayedPayoutTxMessage.class, + SellerPublishesDepositTx.class, + SellerPublishesTradeStatistics.class)) .executeTasks(); } - @Override - protected void handle(DelayedPayoutTxSignatureResponse message, NodeAddress peer) { - super.handle(message, peer); - } - @Override protected void handle(ShareBuyerPaymentAccountMessage message, NodeAddress peer) { super.handle(message, peer); @@ -163,13 +174,6 @@ public void onPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler e @Override protected void onTradeMessage(TradeMessage message, NodeAddress peer) { super.onTradeMessage(message, peer); - - log.info("Received {} from {} with tradeId {} and uid {}", - message.getClass().getSimpleName(), peer, message.getTradeId(), message.getUid()); - - if (message instanceof DepositTxMessage) { - handle((DepositTxMessage) message, peer); - } } @Override 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 70cff3960ee..9477a83adfb 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 @@ -17,14 +17,12 @@ package bisq.core.trade.protocol.bisq_v5; - import bisq.core.offer.Offer; import bisq.core.trade.model.bisq_v1.SellerAsTakerTrade; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.trade.protocol.TakerProtocol; import bisq.core.trade.protocol.TradeMessage; import bisq.core.trade.protocol.bisq_v1.messages.CounterCurrencyTransferStartedMessage; -import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureResponse; import bisq.core.trade.protocol.bisq_v1.messages.ShareBuyerPaymentAccountMessage; import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter; import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync; @@ -37,21 +35,16 @@ import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerSendInputsForDepositTxRequest; 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.BuyersRedirectSellerSignatureRequest; 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.CreateSignedClaimTx; import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerCreatesWarningTx; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerFinalizesOwnRedirectTx; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerFinalizesOwnWarningTx; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessBuyersRedirectSellerSignatureRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSendStagedPayoutTxRequest; -import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSendsBuyersRedirectSellerSignatureResponse; 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.SellerAsTakerProcessesInputsForDepositTxResponse_v5; +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; @@ -102,6 +95,7 @@ public void onTakeOffer() { getVerifyPeersFeePaymentClass(), CreateTakerFeeTx.class, SellerAsTakerCreatesDepositTxInputs.class, + CreateFeeBumpAddressEntries.class, TakerSendInputsForDepositTxRequest.class) .withTimeout(120)) .executeTasks(); @@ -117,7 +111,7 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) { .with(message) .from(peer)) .setup(tasks( - SellerAsTakerProcessesInputsForDepositTxResponse_v5.class, + TakerProcessInputsForDepositTxResponse_v5.class, ApplyFilter.class, TakerVerifyAndSignContract.class, @@ -135,47 +129,46 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) { CreateRedirectTx.class, SellerSignsOwnRedirectTx.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) +// // We send buyer sig for their warn tx and our warn and redirect tx including our signatures +// SellerSendStagedPayoutTxRequest.class) + SellerAsTakerSendsPreparedTxBuyerSignaturesRequest.class) .withTimeout(120)) .executeTasks(); } - protected void handle(BuyersRedirectSellerSignatureRequest message, NodeAddress peer) { - expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) - .with(message) - .from(peer)) - .setup(tasks( - // We received the buyer's signature for our warn and redirect tx as well - // as the buyer's redirect tx and signature - SellerProcessBuyersRedirectSellerSignatureRequest.class, - - // We have now the buyers sig for our warn tx and finalize it - SellerFinalizesOwnWarningTx.class, - - // We have now the buyers sig for our redirect tx and finalize it - SellerFinalizesOwnRedirectTx.class, - - // We can now create the signed claim tx from out warn tx - CreateSignedClaimTx.class, - - // We sign the buyers redirect tx - SellerSignsPeersRedirectTx.class, - - // We have all transactions but missing still the buyer's witness for the deposit tx. - - // We send the buyer the requested signature for their redirect tx - SellerSendsBuyersRedirectSellerSignatureResponse.class)) - .executeTasks(); - } - +// protected void handle(BuyersRedirectSellerSignatureRequest message, NodeAddress peer) { +// expect(phase(Trade.Phase.TAKER_FEE_PUBLISHED) +// .with(message) +// .from(peer)) +// .setup(tasks( +// // We received the buyer's signature for our warn and redirect tx as well +// // as the buyer's redirect tx and signature +// SellerProcessBuyersRedirectSellerSignatureRequest.class, +// +// // We have now the buyers sig for our warn tx and finalize it +// SellerFinalizesOwnWarningTx.class, +// +// // We have now the buyers sig for our redirect tx and finalize it +// SellerFinalizesOwnRedirectTx.class, +// +// // We can now create the signed claim tx from out warn tx +// CreateSignedClaimTx.class, +// +// // We sign the buyers redirect tx +// SellerSignsPeersRedirectTx.class, +// +// // We have all transactions but missing still the buyer's witness for the deposit tx. +// +// // We send the buyer the requested signature for their redirect tx +// SellerSendsBuyersRedirectSellerSignatureResponse.class)) +// .executeTasks(); +// } @Override - protected void handle(DelayedPayoutTxSignatureResponse message, NodeAddress peer) { + protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer) { super.handle(message, peer); } @@ -213,13 +206,8 @@ public void onPaymentReceived(ResultHandler resultHandler, ErrorMessageHandler e protected void onTradeMessage(TradeMessage message, NodeAddress peer) { super.onTradeMessage(message, peer); - log.info("Received {} from {} with tradeId {} and uid {}", - message.getClass().getSimpleName(), peer, message.getTradeId(), message.getUid()); - if (message instanceof InputsForDepositTxResponse_v5) { handle((InputsForDepositTxResponse_v5) message, peer); - } else if (message instanceof BuyersRedirectSellerSignatureRequest) { - handle((BuyersRedirectSellerSignatureRequest) message, peer); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureRequest.java index 0fdd83110f6..e3a3a7ddfa9 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureRequest.java @@ -25,8 +25,6 @@ import bisq.common.app.Version; import bisq.common.util.Utilities; -import com.google.protobuf.ByteString; - import lombok.EqualsAndHashCode; import lombok.Getter; @@ -76,32 +74,32 @@ private BuyersRedirectSellerSignatureRequest(int messageVersion, this.buyersRedirectTxBuyerSignature = buyersRedirectTxBuyerSignature; } - @Override - public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { - return getNetworkEnvelopeBuilder() - .setBuyersRedirectSellerSignatureRequest(protobuf.BuyersRedirectSellerSignatureRequest.newBuilder() - .setUid(uid) - .setTradeId(tradeId) - .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) - .setSellersWarningTxBuyerSignature(ByteString.copyFrom(sellersWarningTxBuyerSignature)) - .setSellersRedirectTxBuyerSignature(ByteString.copyFrom(sellersRedirectTxBuyerSignature)) - .setBuyersRedirectTx(ByteString.copyFrom(buyersRedirectTx)) - .setBuyersRedirectTxBuyerSignature(ByteString.copyFrom(buyersRedirectTxBuyerSignature)) - ) - .build(); - } +// @Override +// public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { +// return getNetworkEnvelopeBuilder() +// .setBuyersRedirectSellerSignatureRequest(protobuf.BuyersRedirectSellerSignatureRequest.newBuilder() +// .setUid(uid) +// .setTradeId(tradeId) +// .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) +// .setSellersWarningTxBuyerSignature(ByteString.copyFrom(sellersWarningTxBuyerSignature)) +// .setSellersRedirectTxBuyerSignature(ByteString.copyFrom(sellersRedirectTxBuyerSignature)) +// .setBuyersRedirectTx(ByteString.copyFrom(buyersRedirectTx)) +// .setBuyersRedirectTxBuyerSignature(ByteString.copyFrom(buyersRedirectTxBuyerSignature)) +// ) +// .build(); +// } - public static BuyersRedirectSellerSignatureRequest fromProto(protobuf.BuyersRedirectSellerSignatureRequest proto, - int messageVersion) { - return new BuyersRedirectSellerSignatureRequest(messageVersion, - proto.getUid(), - proto.getTradeId(), - NodeAddress.fromProto(proto.getSenderNodeAddress()), - proto.getSellersWarningTxBuyerSignature().toByteArray(), - proto.getSellersRedirectTxBuyerSignature().toByteArray(), - proto.getBuyersRedirectTx().toByteArray(), - proto.getBuyersRedirectTxBuyerSignature().toByteArray()); - } +// public static BuyersRedirectSellerSignatureRequest fromProto(protobuf.BuyersRedirectSellerSignatureRequest proto, +// int messageVersion) { +// return new BuyersRedirectSellerSignatureRequest(messageVersion, +// proto.getUid(), +// proto.getTradeId(), +// NodeAddress.fromProto(proto.getSenderNodeAddress()), +// proto.getSellersWarningTxBuyerSignature().toByteArray(), +// proto.getSellersRedirectTxBuyerSignature().toByteArray(), +// proto.getBuyersRedirectTx().toByteArray(), +// proto.getBuyersRedirectTxBuyerSignature().toByteArray()); +// } @Override public String toString() { diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureResponse.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureResponse.java index ba7075ab1ad..3ed0c59076e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureResponse.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/BuyersRedirectSellerSignatureResponse.java @@ -25,8 +25,6 @@ import bisq.common.app.Version; import bisq.common.util.Utilities; -import com.google.protobuf.ByteString; - import lombok.EqualsAndHashCode; import lombok.Getter; @@ -61,26 +59,26 @@ private BuyersRedirectSellerSignatureResponse(int messageVersion, this.buyersRedirectTxSellerSignature = buyersRedirectTxSellerSignature; } - @Override - public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { - return getNetworkEnvelopeBuilder() - .setBuyersRedirectSellerSignatureResponse(protobuf.BuyersRedirectSellerSignatureResponse.newBuilder() - .setUid(uid) - .setTradeId(tradeId) - .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) - .setBuyersRedirectTxSellerSignature(ByteString.copyFrom(buyersRedirectTxSellerSignature)) - ) - .build(); - } +// @Override +// public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { +// return getNetworkEnvelopeBuilder() +// .setBuyersRedirectSellerSignatureResponse(protobuf.BuyersRedirectSellerSignatureResponse.newBuilder() +// .setUid(uid) +// .setTradeId(tradeId) +// .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) +// .setBuyersRedirectTxSellerSignature(ByteString.copyFrom(buyersRedirectTxSellerSignature)) +// ) +// .build(); +// } - public static BuyersRedirectSellerSignatureResponse fromProto(protobuf.BuyersRedirectSellerSignatureResponse proto, - int messageVersion) { - return new BuyersRedirectSellerSignatureResponse(messageVersion, - proto.getUid(), - proto.getTradeId(), - NodeAddress.fromProto(proto.getSenderNodeAddress()), - proto.getBuyersRedirectTxSellerSignature().toByteArray()); - } +// public static BuyersRedirectSellerSignatureResponse fromProto(protobuf.BuyersRedirectSellerSignatureResponse proto, +// int messageVersion) { +// return new BuyersRedirectSellerSignatureResponse(messageVersion, +// proto.getUid(), +// proto.getTradeId(), +// NodeAddress.fromProto(proto.getSenderNodeAddress()), +// proto.getBuyersRedirectTxSellerSignature().toByteArray()); +// } @Override public String toString() { diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/InputsForDepositTxResponse_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/InputsForDepositTxResponse_v5.java index d6e5bf49a45..f557b3a3861 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/InputsForDepositTxResponse_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/InputsForDepositTxResponse_v5.java @@ -18,7 +18,6 @@ package bisq.core.trade.protocol.bisq_v5.messages; import bisq.core.btc.model.RawTransactionInput; -import bisq.core.proto.CoreProtoResolver; import bisq.core.trade.protocol.TradeMessage; import bisq.network.p2p.DirectMessage; @@ -57,8 +56,12 @@ public final class InputsForDepositTxResponse_v5 extends TradeMessage implements private final long lockTime; private final byte[] hashOfMakersPaymentAccountPayload; private final String makersPaymentMethodId; - private final byte[] buyersUnsignedWarningTx; - private final byte[] buyersWarningTxSignature; + private final String makersWarningTxFeeBumpAddress; + private final String makersRedirectTxFeeBumpAddress; + private final byte[] buyersWarningTxMakerSignature; + private final byte[] sellersWarningTxMakerSignature; + private final byte[] buyersRedirectTxMakerSignature; + private final byte[] sellersRedirectTxMakerSignature; public InputsForDepositTxResponse_v5(String tradeId, String makerAccountId, @@ -75,8 +78,12 @@ public InputsForDepositTxResponse_v5(String tradeId, long lockTime, byte[] hashOfMakersPaymentAccountPayload, String makersPaymentMethodId, - byte[] buyersUnsignedWarningTx, - byte[] buyersWarningTxSignature) { + String makersWarningTxFeeBumpAddress, + String makersRedirectTxFeeBumpAddress, + byte[] buyersWarningTxMakerSignature, + byte[] sellersWarningTxMakerSignature, + byte[] buyersRedirectTxMakerSignature, + byte[] sellersRedirectTxMakerSignature) { this(tradeId, makerAccountId, makerMultiSigPubKey, @@ -93,8 +100,12 @@ public InputsForDepositTxResponse_v5(String tradeId, lockTime, hashOfMakersPaymentAccountPayload, makersPaymentMethodId, - buyersUnsignedWarningTx, - buyersWarningTxSignature); + makersWarningTxFeeBumpAddress, + makersRedirectTxFeeBumpAddress, + buyersWarningTxMakerSignature, + sellersWarningTxMakerSignature, + buyersRedirectTxMakerSignature, + sellersRedirectTxMakerSignature); } @@ -118,8 +129,12 @@ private InputsForDepositTxResponse_v5(String tradeId, long lockTime, byte[] hashOfMakersPaymentAccountPayload, String makersPaymentMethodId, - byte[] buyersUnsignedWarningTx, - byte[] buyersWarningTxSignature) { + String makersWarningTxFeeBumpAddress, + String makersRedirectTxFeeBumpAddress, + byte[] buyersWarningTxMakerSignature, + byte[] sellersWarningTxMakerSignature, + byte[] buyersRedirectTxMakerSignature, + byte[] sellersRedirectTxMakerSignature) { super(messageVersion, tradeId, uid); this.makerAccountId = makerAccountId; this.makerMultiSigPubKey = makerMultiSigPubKey; @@ -134,8 +149,12 @@ private InputsForDepositTxResponse_v5(String tradeId, this.lockTime = lockTime; this.hashOfMakersPaymentAccountPayload = hashOfMakersPaymentAccountPayload; this.makersPaymentMethodId = makersPaymentMethodId; - this.buyersUnsignedWarningTx = buyersUnsignedWarningTx; - this.buyersWarningTxSignature = buyersWarningTxSignature; + this.makersWarningTxFeeBumpAddress = makersWarningTxFeeBumpAddress; + this.makersRedirectTxFeeBumpAddress = makersRedirectTxFeeBumpAddress; + this.buyersWarningTxMakerSignature = buyersWarningTxMakerSignature; + this.sellersWarningTxMakerSignature = sellersWarningTxMakerSignature; + this.buyersRedirectTxMakerSignature = buyersRedirectTxMakerSignature; + this.sellersRedirectTxMakerSignature = sellersRedirectTxMakerSignature; } @Override @@ -152,8 +171,12 @@ public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) .setUid(uid) .setLockTime(lockTime) - .setBuyersUnsignedWarningTx(ByteString.copyFrom(buyersUnsignedWarningTx)) - .setBuyersWarningTxSignature(ByteString.copyFrom(buyersWarningTxSignature)); + .setMakersWarningTxFeeBumpAddress(makersWarningTxFeeBumpAddress) + .setMakersRedirectTxFeeBumpAddress(makersRedirectTxFeeBumpAddress) + .setBuyersWarningTxMakerSignature(ByteString.copyFrom(buyersWarningTxMakerSignature)) + .setSellersWarningTxMakerSignature(ByteString.copyFrom(sellersWarningTxMakerSignature)) + .setBuyersRedirectTxMakerSignature(ByteString.copyFrom(buyersRedirectTxMakerSignature)) + .setSellersRedirectTxMakerSignature(ByteString.copyFrom(sellersRedirectTxMakerSignature)); Optional.ofNullable(accountAgeWitnessSignatureOfPreparedDepositTx).ifPresent(e -> builder.setAccountAgeWitnessSignatureOfPreparedDepositTx(ByteString.copyFrom(e))); builder.setCurrentDate(currentDate); @@ -165,7 +188,6 @@ public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { } public static InputsForDepositTxResponse_v5 fromProto(protobuf.InputsForDepositTxResponse_v5 proto, - CoreProtoResolver coreProtoResolver, int messageVersion) { List makerInputs = proto.getMakerInputsList().stream() .map(RawTransactionInput::fromProto) @@ -189,14 +211,18 @@ public static InputsForDepositTxResponse_v5 fromProto(protobuf.InputsForDepositT proto.getLockTime(), hashOfMakersPaymentAccountPayload, ProtoUtil.stringOrNullFromProto(proto.getMakersPayoutMethodId()), - ProtoUtil.byteArrayOrNullFromProto(proto.getBuyersUnsignedWarningTx()), - ProtoUtil.byteArrayOrNullFromProto(proto.getBuyersWarningTxSignature())); + proto.getMakersWarningTxFeeBumpAddress(), + proto.getMakersRedirectTxFeeBumpAddress(), + proto.getBuyersWarningTxMakerSignature().toByteArray(), + proto.getSellersWarningTxMakerSignature().toByteArray(), + proto.getBuyersRedirectTxMakerSignature().toByteArray(), + proto.getSellersRedirectTxMakerSignature().toByteArray()); } @Override public String toString() { return "InputsForDepositTxResponse_v5{" + - ",\n makerAccountId='" + makerAccountId + '\'' + + "\n makerAccountId='" + makerAccountId + '\'' + ",\n makerMultiSigPubKey=" + Utilities.bytesAsHexString(makerMultiSigPubKey) + ",\n makerContractAsJson='" + makerContractAsJson + '\'' + ",\n makerContractSignature='" + makerContractSignature + '\'' + @@ -204,14 +230,17 @@ public String toString() { ",\n preparedDepositTx=" + Utilities.bytesAsHexString(preparedDepositTx) + ",\n makerInputs=" + makerInputs + ",\n senderNodeAddress=" + senderNodeAddress + - ",\n uid='" + uid + '\'' + ",\n accountAgeWitnessSignatureOfPreparedDepositTx=" + Utilities.bytesAsHexString(accountAgeWitnessSignatureOfPreparedDepositTx) + ",\n currentDate=" + new Date(currentDate) + ",\n lockTime=" + lockTime + ",\n hashOfMakersPaymentAccountPayload=" + Utilities.bytesAsHexString(hashOfMakersPaymentAccountPayload) + ",\n makersPaymentMethodId=" + makersPaymentMethodId + - ",\n buyersUnsignedWarningTx=" + Utilities.bytesAsHexString(buyersUnsignedWarningTx) + - ",\n buyersWarningTxSignature=" + Utilities.bytesAsHexString(buyersWarningTxSignature) + + ",\n makersWarningTxFeeBumpAddress=" + makersWarningTxFeeBumpAddress + + ",\n makersRedirectTxFeeBumpAddress=" + makersRedirectTxFeeBumpAddress + + ",\n buyersWarningTxMakerSignature=" + Utilities.bytesAsHexString(buyersWarningTxMakerSignature) + + ",\n sellersWarningTxMakerSignature=" + Utilities.bytesAsHexString(sellersWarningTxMakerSignature) + + ",\n buyersRedirectTxMakerSignature=" + Utilities.bytesAsHexString(buyersRedirectTxMakerSignature) + + ",\n sellersRedirectTxMakerSignature=" + Utilities.bytesAsHexString(sellersRedirectTxMakerSignature) + "\n} " + super.toString(); } } diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesMessage.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesMessage.java new file mode 100644 index 00000000000..011a4744bcf --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesMessage.java @@ -0,0 +1,108 @@ +/* + * 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.messages; + +import bisq.core.trade.protocol.TradeMessage; + +import bisq.network.p2p.DirectMessage; +import bisq.network.p2p.NodeAddress; + +import bisq.common.util.Utilities; + +import protobuf.NetworkEnvelope; + +import com.google.protobuf.ByteString; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode(callSuper = true) +@Getter +public class PreparedTxBuyerSignaturesMessage extends TradeMessage implements DirectMessage { + private final NodeAddress senderNodeAddress; + private final byte[] depositTxWithBuyerWitnesses; // TODO: Rename to depositTxWithBuyerWitnesses + private final byte[] buyersWarningTxBuyerSignature; + private final byte[] sellersWarningTxBuyerSignature; + private final byte[] buyersRedirectTxBuyerSignature; + private final byte[] sellersRedirectTxBuyerSignature; + + public PreparedTxBuyerSignaturesMessage(int messageVersion, + String tradeId, + String uid, + NodeAddress senderNodeAddress, + byte[] depositTxWithBuyerWitnesses, + byte[] buyersWarningTxBuyerSignature, + byte[] sellersWarningTxBuyerSignature, + byte[] buyersRedirectTxBuyerSignature, + byte[] sellersRedirectTxBuyerSignature) { + super(messageVersion, tradeId, uid); + this.senderNodeAddress = senderNodeAddress; + this.depositTxWithBuyerWitnesses = depositTxWithBuyerWitnesses; + this.buyersWarningTxBuyerSignature = buyersWarningTxBuyerSignature; + this.sellersWarningTxBuyerSignature = sellersWarningTxBuyerSignature; + this.buyersRedirectTxBuyerSignature = buyersRedirectTxBuyerSignature; + this.sellersRedirectTxBuyerSignature = sellersRedirectTxBuyerSignature; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public NetworkEnvelope toProtoNetworkEnvelope() { + protobuf.PreparedTxBuyerSignaturesMessage.Builder builder = protobuf.PreparedTxBuyerSignaturesMessage.newBuilder() + .setTradeId(tradeId) + .setUid(uid) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setDepositTxWithBuyerWitnesses(ByteString.copyFrom(depositTxWithBuyerWitnesses)) + .setBuyersWarningTxBuyerSignature(ByteString.copyFrom(buyersWarningTxBuyerSignature)) + .setSellersWarningTxBuyerSignature(ByteString.copyFrom(sellersWarningTxBuyerSignature)) + .setBuyersRedirectTxBuyerSignature(ByteString.copyFrom(buyersRedirectTxBuyerSignature)) + .setSellersRedirectTxBuyerSignature(ByteString.copyFrom(sellersRedirectTxBuyerSignature)); + + return getNetworkEnvelopeBuilder() + .setPreparedTxBuyerSignaturesMessage(builder) + .build(); + } + + public static PreparedTxBuyerSignaturesMessage fromProto(protobuf.PreparedTxBuyerSignaturesMessage proto, + int messageVersion) { + return new PreparedTxBuyerSignaturesMessage(messageVersion, + proto.getTradeId(), + proto.getUid(), + NodeAddress.fromProto(proto.getSenderNodeAddress()), + proto.getDepositTxWithBuyerWitnesses().toByteArray(), + proto.getBuyersWarningTxBuyerSignature().toByteArray(), + proto.getSellersWarningTxBuyerSignature().toByteArray(), + proto.getBuyersRedirectTxBuyerSignature().toByteArray(), + proto.getSellersRedirectTxBuyerSignature().toByteArray()); + } + + @Override + public String toString() { + return "PreparedTxBuyerSignaturesMessage{" + + "\n senderNodeAddress=" + senderNodeAddress + + ",\n depositTxWithBuyerWitnesses=" + Utilities.bytesAsHexString(depositTxWithBuyerWitnesses) + + ",\n buyersWarningTxBuyerSignature=" + Utilities.bytesAsHexString(buyersWarningTxBuyerSignature) + + ",\n sellersWarningTxBuyerSignature=" + Utilities.bytesAsHexString(sellersWarningTxBuyerSignature) + + ",\n buyersRedirectTxBuyerSignature=" + Utilities.bytesAsHexString(buyersRedirectTxBuyerSignature) + + ",\n sellersRedirectTxBuyerSignature=" + Utilities.bytesAsHexString(sellersRedirectTxBuyerSignature) + + "\n}" + super.toString(); + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesRequest.java new file mode 100644 index 00000000000..525f382ea52 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/PreparedTxBuyerSignaturesRequest.java @@ -0,0 +1,102 @@ +/* + * 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.messages; + +import bisq.core.trade.protocol.TradeMessage; + +import bisq.network.p2p.DirectMessage; +import bisq.network.p2p.NodeAddress; + +import bisq.common.util.Utilities; + +import protobuf.NetworkEnvelope; + +import com.google.protobuf.ByteString; + +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@EqualsAndHashCode(callSuper = true) +@Getter +public class PreparedTxBuyerSignaturesRequest extends TradeMessage implements DirectMessage { + private final NodeAddress senderNodeAddress; + private final byte[] buyersWarningTxSellerSignature; + private final byte[] sellersWarningTxSellerSignature; + private final byte[] buyersRedirectTxSellerSignature; + private final byte[] sellersRedirectTxSellerSignature; + + public PreparedTxBuyerSignaturesRequest(int messageVersion, + String tradeId, + String uid, + NodeAddress senderNodeAddress, + byte[] buyersWarningTxSellerSignature, + byte[] sellersWarningTxSellerSignature, + byte[] buyersRedirectTxSellerSignature, + byte[] sellersRedirectTxSellerSignature) { + super(messageVersion, tradeId, uid); + this.senderNodeAddress = senderNodeAddress; + this.buyersWarningTxSellerSignature = buyersWarningTxSellerSignature; + this.sellersWarningTxSellerSignature = sellersWarningTxSellerSignature; + this.buyersRedirectTxSellerSignature = buyersRedirectTxSellerSignature; + this.sellersRedirectTxSellerSignature = sellersRedirectTxSellerSignature; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // PROTO BUFFER + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public NetworkEnvelope toProtoNetworkEnvelope() { + protobuf.PreparedTxBuyerSignaturesRequest.Builder builder = protobuf.PreparedTxBuyerSignaturesRequest.newBuilder() + .setTradeId(tradeId) + .setUid(uid) + .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) + .setBuyersWarningTxSellerSignature(ByteString.copyFrom(buyersWarningTxSellerSignature)) + .setSellersWarningTxSellerSignature(ByteString.copyFrom(sellersWarningTxSellerSignature)) + .setBuyersRedirectTxSellerSignature(ByteString.copyFrom(buyersRedirectTxSellerSignature)) + .setSellersRedirectTxSellerSignature(ByteString.copyFrom(sellersRedirectTxSellerSignature)); + + return getNetworkEnvelopeBuilder() + .setPreparedTxBuyerSignaturesRequest(builder) + .build(); + } + + public static PreparedTxBuyerSignaturesRequest fromProto(protobuf.PreparedTxBuyerSignaturesRequest proto, + int messageVersion) { + return new PreparedTxBuyerSignaturesRequest(messageVersion, + proto.getTradeId(), + proto.getUid(), + NodeAddress.fromProto(proto.getSenderNodeAddress()), + proto.getBuyersWarningTxSellerSignature().toByteArray(), + proto.getSellersWarningTxSellerSignature().toByteArray(), + proto.getBuyersRedirectTxSellerSignature().toByteArray(), + proto.getSellersRedirectTxSellerSignature().toByteArray()); + } + + @Override + public String toString() { + return "PreparedTxBuyerSignaturesRequest{" + + "\n senderNodeAddress=" + senderNodeAddress + + ",\n buyersWarningTxSellerSignature=" + Utilities.bytesAsHexString(buyersWarningTxSellerSignature) + + ",\n sellersWarningTxSellerSignature=" + Utilities.bytesAsHexString(sellersWarningTxSellerSignature) + + ",\n buyersRedirectTxSellerSignature=" + Utilities.bytesAsHexString(buyersRedirectTxSellerSignature) + + ",\n sellersRedirectTxSellerSignature=" + Utilities.bytesAsHexString(sellersRedirectTxSellerSignature) + + "\n}" + super.toString(); + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/StagedPayoutTxRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/StagedPayoutTxRequest.java index 5feb1fee79d..e7c578d9845 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/StagedPayoutTxRequest.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/messages/StagedPayoutTxRequest.java @@ -25,8 +25,6 @@ import bisq.common.app.Version; import bisq.common.util.Utilities; -import com.google.protobuf.ByteString; - import lombok.EqualsAndHashCode; import lombok.Getter; @@ -82,33 +80,33 @@ private StagedPayoutTxRequest(int messageVersion, } - @Override - public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { - return getNetworkEnvelopeBuilder() - .setStagedPayoutTxRequest(protobuf.StagedPayoutTxRequest.newBuilder() - .setUid(uid) - .setTradeId(tradeId) - .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) - .setSellersWarningTx(ByteString.copyFrom(sellersWarningTx)) - .setSellersWarningTxSellerSignature(ByteString.copyFrom(sellersWarningTxSellerSignature)) - .setSellersRedirectionTx(ByteString.copyFrom(sellersRedirectionTx)) - .setSellersRedirectionTxSellerSignature(ByteString.copyFrom(sellersRedirectionTxSellerSignature)) - .setBuyersWarningTxSellerSignature(ByteString.copyFrom(buyersWarningTxSellerSignature))) - .build(); - } +// @Override +// public protobuf.NetworkEnvelope toProtoNetworkEnvelope() { +// return getNetworkEnvelopeBuilder() +// .setStagedPayoutTxRequest(protobuf.StagedPayoutTxRequest.newBuilder() +// .setUid(uid) +// .setTradeId(tradeId) +// .setSenderNodeAddress(senderNodeAddress.toProtoMessage()) +// .setSellersWarningTx(ByteString.copyFrom(sellersWarningTx)) +// .setSellersWarningTxSellerSignature(ByteString.copyFrom(sellersWarningTxSellerSignature)) +// .setSellersRedirectionTx(ByteString.copyFrom(sellersRedirectionTx)) +// .setSellersRedirectionTxSellerSignature(ByteString.copyFrom(sellersRedirectionTxSellerSignature)) +// .setBuyersWarningTxSellerSignature(ByteString.copyFrom(buyersWarningTxSellerSignature))) +// .build(); +// } - public static StagedPayoutTxRequest fromProto(protobuf.StagedPayoutTxRequest proto, - int messageVersion) { - return new StagedPayoutTxRequest(messageVersion, - proto.getUid(), - proto.getTradeId(), - NodeAddress.fromProto(proto.getSenderNodeAddress()), - proto.getSellersWarningTx().toByteArray(), - proto.getSellersWarningTxSellerSignature().toByteArray(), - proto.getSellersRedirectionTx().toByteArray(), - proto.getSellersRedirectionTxSellerSignature().toByteArray(), - proto.getBuyersWarningTxSellerSignature().toByteArray()); - } +// public static StagedPayoutTxRequest fromProto(protobuf.StagedPayoutTxRequest proto, +// int messageVersion) { +// return new StagedPayoutTxRequest(messageVersion, +// proto.getUid(), +// proto.getTradeId(), +// NodeAddress.fromProto(proto.getSenderNodeAddress()), +// proto.getSellersWarningTx().toByteArray(), +// proto.getSellersWarningTxSellerSignature().toByteArray(), +// proto.getSellersRedirectionTx().toByteArray(), +// proto.getSellersRedirectionTxSellerSignature().toByteArray(), +// proto.getBuyersWarningTxSellerSignature().toByteArray()); +// } @Override public String toString() { diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateFeeBumpAddressEntries.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateFeeBumpAddressEntries.java new file mode 100644 index 00000000000..5b8011e9937 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateFeeBumpAddressEntries.java @@ -0,0 +1,53 @@ +/* + * 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; + +import bisq.core.btc.model.AddressEntry; +import bisq.core.btc.wallet.BtcWalletService; +import bisq.core.trade.model.bisq_v1.Trade; +import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class CreateFeeBumpAddressEntries extends TradeTask { + protected CreateFeeBumpAddressEntries(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + BtcWalletService btcWalletService = processModel.getBtcWalletService(); + String tradeId = processModel.getOffer().getId(); + + AddressEntry warningTxFeeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.WARNING_TX_FEE_BUMP); + AddressEntry redirectTxFeeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.REDIRECT_TX_FEE_BUMP); + processModel.setWarningTxFeeBumpAddress(warningTxFeeBumpAddressEntry.getAddressString()); + processModel.setRedirectTxFeeBumpAddress(redirectTxFeeBumpAddressEntry.getAddressString()); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerSendsPreparedTxBuyerSignaturesMessage.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerSendsPreparedTxBuyerSignaturesMessage.java new file mode 100644 index 00000000000..bef6d40bbf2 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer/BuyerSendsPreparedTxBuyerSignaturesMessage.java @@ -0,0 +1,89 @@ +/* + * 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.buyer; + +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; + +import bisq.network.p2p.NodeAddress; +import bisq.network.p2p.SendDirectMessageListener; + +import bisq.common.app.Version; +import bisq.common.taskrunner.TaskRunner; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class BuyerSendsPreparedTxBuyerSignaturesMessage extends TradeTask { + protected BuyerSendsPreparedTxBuyerSignaturesMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + byte[] depositTxWithBuyerWitnesses = processModel.getPreparedDepositTx(); // FIXME + byte[] buyersWarningTxBuyerSignature = processModel.getWarningTxBuyerSignature(); + byte[] sellersWarningTxBuyerSignature = processModel.getTradePeer().getWarningTxBuyerSignature(); + byte[] buyersRedirectTxBuyerSignature = processModel.getRedirectTxBuyerSignature(); + byte[] sellersRedirectTxBuyerSignature = processModel.getTradePeer().getRedirectTxBuyerSignature(); + + PreparedTxBuyerSignaturesMessage message = new PreparedTxBuyerSignaturesMessage(Version.getP2PMessageVersion(), // TODO: Add extra constructor + processModel.getOfferId(), + UUID.randomUUID().toString(), + processModel.getMyNodeAddress(), + depositTxWithBuyerWitnesses, + buyersWarningTxBuyerSignature, + sellersWarningTxBuyerSignature, + buyersRedirectTxBuyerSignature, + sellersRedirectTxBuyerSignature); + + NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); + log.info("Send {} to peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + processModel.getP2PService().sendEncryptedDirectMessage( + peersNodeAddress, + processModel.getTradePeer().getPubKeyRing(), + message, + new SendDirectMessageListener() { + @Override + public void onArrived() { + log.info("{} arrived at peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + complete(); + } + + @Override + public void onFault(String errorMessage) { + log.error("{} failed: Peer {}. tradeId={}, uid={}, errorMessage={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid(), errorMessage); + appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage); + failed(errorMessage); + } + } + ); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.java new file mode 100644 index 00000000000..6d7fac2c43f --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.java @@ -0,0 +1,58 @@ +/* + * 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.buyer_as_maker; + +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.PreparedTxBuyerSignaturesRequest; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +import static bisq.core.util.Validator.checkTradeId; +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest extends TradeTask { + protected BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + PreparedTxBuyerSignaturesRequest request = (PreparedTxBuyerSignaturesRequest) processModel.getTradeMessage(); + checkNotNull(request); + checkTradeId(processModel.getOfferId(), request); + + processModel.setWarningTxSellerSignature(request.getBuyersWarningTxSellerSignature()); + processModel.getTradePeer().setWarningTxSellerSignature(request.getSellersWarningTxSellerSignature()); + processModel.setRedirectTxSellerSignature(request.getBuyersRedirectTxSellerSignature()); + processModel.getTradePeer().setRedirectTxSellerSignature(request.getSellersRedirectTxSellerSignature()); + + processModel.getTradeManager().requestPersistence(); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerSendsInputsForDepositTxResponse_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java similarity index 82% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerSendsInputsForDepositTxResponse_v5.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java index 4aa08cc860f..4451515f76e 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/buyer_as_maker/BuyerAsMakerSendsInputsForDepositTxResponse_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/maker/MakerSendsInputsForDepositTxResponse_v5.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker; +package bisq.core.trade.protocol.bisq_v5.tasks.maker; import bisq.core.btc.model.AddressEntry; import bisq.core.btc.wallet.BtcWalletService; @@ -44,10 +44,10 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -// Copy of BuyerAsMakerSendsInputsForDepositTxResponse with added buyersUnsignedWarningTx and buyersWarningTxSignature +// Copy of BuyerAsMakerSendsInputsForDepositTxResponse with added buyersUnsignedWarningTx and buyersWarningTxSignature FIXME: stale comment @Slf4j -public class BuyerAsMakerSendsInputsForDepositTxResponse_v5 extends TradeTask { - public BuyerAsMakerSendsInputsForDepositTxResponse_v5(TaskRunner taskHandler, Trade trade) { +public class MakerSendsInputsForDepositTxResponse_v5 extends TradeTask { + public MakerSendsInputsForDepositTxResponse_v5(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -79,8 +79,13 @@ protected void run() { byte[] hashOfMakersPaymentAccountPayload = ProcessModel.hashOfPaymentAccountPayload(processModel.getPaymentAccountPayload(trade)); String makersPaymentMethodId = checkNotNull(processModel.getPaymentAccountPayload(trade)).getPaymentMethodId(); - byte[] buyersUnsignedWarningTx = processModel.getWarningTx().bitcoinSerialize(); - byte[] buyersWarningTxSignature = processModel.getWarningTxBuyerSignature(); +// 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(); InputsForDepositTxResponse_v5 message = new InputsForDepositTxResponse_v5( processModel.getOfferId(), @@ -98,8 +103,12 @@ protected void run() { trade.getLockTime(), hashOfMakersPaymentAccountPayload, makersPaymentMethodId, - buyersUnsignedWarningTx, - buyersWarningTxSignature); + makersWarningTxFeeBumpAddress, + makersRedirectTxFeeBumpAddress, + buyersWarningTxMakerSignature, + sellersWarningTxMakerSignature, + buyersRedirectTxMakerSignature, + sellersRedirectTxMakerSignature); trade.setState(Trade.State.MAKER_SENT_PUBLISH_DEPOSIT_TX_REQUEST); processModel.getTradeManager().requestPersistence(); @@ -136,11 +145,10 @@ public void onFault(String errorMessage) { } } - protected byte[] getPreparedDepositTx() { Transaction preparedDepositTx = processModel.getBtcWalletService().getTxFromSerializedTx(processModel.getPreparedDepositTx()); - // Remove witnesses from preparedDepositTx, so that the seller can still compute the final - // tx id, but cannot publish it before providing the buyer with a signed delayed payout tx. + // Remove witnesses from preparedDepositTx, so that the peer can still compute the final + // tx id, but cannot publish it before we have all the finalized staged txs. return preparedDepositTx.bitcoinSerialize(false); } } 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 new file mode 100644 index 00000000000..dc8c3332c85 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller/SellerProcessPreparedTxBuyerSignaturesMessage.java @@ -0,0 +1,67 @@ +/* + * 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.trade.model.bisq_v1.Trade; +import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask; +import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage; + +import bisq.common.taskrunner.TaskRunner; + +import lombok.extern.slf4j.Slf4j; + +import static bisq.core.util.Validator.checkTradeId; +import static com.google.common.base.Preconditions.checkNotNull; + +@Slf4j +public class SellerProcessPreparedTxBuyerSignaturesMessage extends TradeTask { + protected SellerProcessPreparedTxBuyerSignaturesMessage(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + PreparedTxBuyerSignaturesMessage message = (PreparedTxBuyerSignaturesMessage) processModel.getTradeMessage(); + 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()); + + processModel.getTradeWalletService().sellerAddsBuyerWitnessesToDepositTx( + processModel.getDepositTx(), + processModel.getBtcWalletService().getTxFromSerializedTx(message.getDepositTxWithBuyerWitnesses()) + ); + + // update to the latest peer address of our peer if the message is correct + trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); + + processModel.getTradeManager().requestPersistence(); + + complete(); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerSendsPreparedTxBuyerSignaturesRequest.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerSendsPreparedTxBuyerSignaturesRequest.java new file mode 100644 index 00000000000..a7a9165eec3 --- /dev/null +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerSendsPreparedTxBuyerSignaturesRequest.java @@ -0,0 +1,87 @@ +/* + * 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_as_taker; + +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.PreparedTxBuyerSignaturesRequest; + +import bisq.network.p2p.NodeAddress; +import bisq.network.p2p.SendDirectMessageListener; + +import bisq.common.app.Version; +import bisq.common.taskrunner.TaskRunner; + +import java.util.UUID; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class SellerAsTakerSendsPreparedTxBuyerSignaturesRequest extends TradeTask { + protected SellerAsTakerSendsPreparedTxBuyerSignaturesRequest(TaskRunner taskHandler, Trade trade) { + super(taskHandler, trade); + } + + @Override + protected void run() { + try { + runInterceptHook(); + + byte[] buyersWarningTxSellerSignature = processModel.getTradePeer().getWarningTxSellerSignature(); + byte[] sellersWarningTxSellerSignature = processModel.getWarningTxSellerSignature(); + byte[] buyersRedirectTxSellerSignature = processModel.getTradePeer().getRedirectTxSellerSignature(); + byte[] sellersRedirectTxSellerSignature = processModel.getRedirectTxSellerSignature(); + + PreparedTxBuyerSignaturesRequest message = new PreparedTxBuyerSignaturesRequest(Version.getP2PMessageVersion(), // TODO: Add extra constructor + processModel.getOfferId(), + UUID.randomUUID().toString(), + processModel.getMyNodeAddress(), + buyersWarningTxSellerSignature, + sellersWarningTxSellerSignature, + buyersRedirectTxSellerSignature, + sellersRedirectTxSellerSignature); + + NodeAddress peersNodeAddress = trade.getTradingPeerNodeAddress(); + log.info("Send {} to peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + processModel.getP2PService().sendEncryptedDirectMessage( + peersNodeAddress, + processModel.getTradePeer().getPubKeyRing(), + message, + new SendDirectMessageListener() { + @Override + public void onArrived() { + log.info("{} arrived at peer {}. tradeId={}, uid={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid()); + complete(); + } + + @Override + public void onFault(String errorMessage) { + log.error("{} failed: Peer {}. tradeId={}, uid={}, errorMessage={}", + message.getClass().getSimpleName(), peersNodeAddress, message.getTradeId(), message.getUid(), errorMessage); + appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage); + failed(errorMessage); + } + } + ); + } catch (Throwable t) { + failed(t); + } + } +} diff --git a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerProcessesInputsForDepositTxResponse_v5.java b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java similarity index 86% rename from core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerProcessesInputsForDepositTxResponse_v5.java rename to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java index 97c14b81c70..4162407738d 100644 --- a/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/seller_as_taker/SellerAsTakerProcessesInputsForDepositTxResponse_v5.java +++ b/core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/taker/TakerProcessInputsForDepositTxResponse_v5.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.trade.protocol.bisq_v5.tasks.seller_as_taker; +package bisq.core.trade.protocol.bisq_v5.tasks.taker; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.Restrictions; @@ -27,8 +27,6 @@ import bisq.common.config.Config; import bisq.common.taskrunner.TaskRunner; -import org.bitcoinj.core.Transaction; - import java.util.Optional; import lombok.extern.slf4j.Slf4j; @@ -39,8 +37,8 @@ import static com.google.common.base.Preconditions.checkNotNull; @Slf4j -public class SellerAsTakerProcessesInputsForDepositTxResponse_v5 extends TradeTask { - public SellerAsTakerProcessesInputsForDepositTxResponse_v5(TaskRunner taskHandler, Trade trade) { +public class TakerProcessInputsForDepositTxResponse_v5 extends TradeTask { + public TakerProcessInputsForDepositTxResponse_v5(TaskRunner taskHandler, Trade trade) { super(taskHandler, trade); } @@ -56,7 +54,6 @@ protected void run() { checkTradeId(processModel.getOfferId(), response); checkNotNull(response); - Optional.ofNullable(response.getHashOfMakersPaymentAccountPayload()) .ifPresent(e -> tradingPeer.setHashOfPaymentAccountPayload(response.getHashOfMakersPaymentAccountPayload())); Optional.ofNullable(response.getMakersPaymentMethodId()) @@ -93,10 +90,12 @@ 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()); +// 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()); // update to the latest peer address of our peer if the message is correct trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress()); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 45083ce0860..abd17afe122 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -103,10 +103,13 @@ message NetworkEnvelope { GetAccountingBlocksResponse get_accounting_blocks_response = 62; NewAccountingBlockBroadcastMessage new_accounting_block_broadcast_message = 63; + // InputsForDepositTxRequest_v5 inputs_for_deposit_tx_request_v_5 = 64; InputsForDepositTxResponse_v5 inputs_for_deposit_tx_response_v_5 = 64; - StagedPayoutTxRequest staged_payout_tx_request = 65; - BuyersRedirectSellerSignatureRequest buyers_redirect_seller_signature_request = 66; - BuyersRedirectSellerSignatureResponse buyers_redirect_seller_signature_response = 67; + // StagedPayoutTxRequest staged_payout_tx_request = 66; + // BuyersRedirectSellerSignatureRequest buyers_redirect_seller_signature_request = 67; + // BuyersRedirectSellerSignatureResponse buyers_redirect_seller_signature_response = 68; + PreparedTxBuyerSignaturesRequest prepared_tx_buyer_signatures_request = 65; + PreparedTxBuyerSignaturesMessage prepared_tx_buyer_signatures_message = 66; } } @@ -241,6 +244,7 @@ message PrefixedSealedAndSignedMessage { string uid = 4; } +// Used in protocol version 4 only message InputsForDepositTxRequest { string trade_id = 1; NodeAddress sender_node_address = 2; @@ -271,7 +275,43 @@ message InputsForDepositTxRequest { bytes hash_of_takers_payment_account_payload = 26; string takers_payout_method_id = 27; int32 burning_man_selection_height = 28; // Added in v 1.9.7 -} + string takers_warning_tx_fee_bump_address = 29; // Added for v5 protocol + string takers_redirect_tx_fee_bump_address = 30; // Added for v5 protocol +} + +//message InputsForDepositTxRequest_v5 { +// string trade_id = 1; +// NodeAddress sender_node_address = 2; +// int64 trade_amount = 3; +// int64 trade_price = 4; +// int64 tx_fee = 5; +// int64 taker_fee = 6; +// bool is_currency_for_taker_fee_btc = 7; +// repeated RawTransactionInput raw_transaction_inputs = 8; +// int64 change_output_value = 9; +// string change_output_address = 10; +// bytes taker_multi_sig_pub_key = 11; +// string taker_payout_address_string = 12; +// PubKeyRing taker_pub_key_ring = 13; +// // Not used anymore from 1.7.0 but kept for backward compatibility. +// PaymentAccountPayload taker_payment_account_payload = 14; +// string taker_account_id = 15; +// string taker_fee_tx_id = 16; +// repeated NodeAddress accepted_arbitrator_node_addresses = 17; +// repeated NodeAddress accepted_mediator_node_addresses = 18; +// NodeAddress arbitrator_node_address = 19; +// NodeAddress mediator_node_address = 20; +// string uid = 21; +// bytes account_age_witness_signature_of_offer_id = 22; +// int64 current_date = 23; +// repeated NodeAddress accepted_refund_agent_node_addresses = 24; +// NodeAddress refund_agent_node_address = 25; +// bytes hash_of_takers_payment_account_payload = 26; +// string takers_payout_method_id = 27; +// int32 burning_man_selection_height = 28; // Added in v 1.9.7 +// string takers_warning_tx_fee_bump_address = 29; +// string takers_redirect_tx_fee_bump_address = 30; +//} // Used in protocol version 4 only message InputsForDepositTxResponse { @@ -310,54 +350,81 @@ message InputsForDepositTxResponse_v5 { int64 lock_time = 14; bytes hash_of_makers_payment_account_payload = 15; string makers_payout_method_id = 16; - bytes buyers_unsigned_warning_tx = 17; - bytes buyers_warning_tx_signature = 18; -} - -message DelayedPayoutTxSignatureRequest { - string uid = 1; - string trade_id = 2; - NodeAddress sender_node_address = 3; - bytes delayed_payout_tx = 4; - bytes delayed_payout_tx_seller_signature = 5; + // bytes buyers_unsigned_warning_tx = 17; + // bytes buyers_warning_tx_signature = 18; + string makers_warning_tx_fee_bump_address = 17; + string makers_redirect_tx_fee_bump_address = 18; + bytes buyers_warning_tx_maker_signature = 19; + bytes sellers_warning_tx_maker_signature = 20; + bytes buyers_redirect_tx_maker_signature = 21; + bytes sellers_redirect_tx_maker_signature = 22; } -message StagedPayoutTxRequest { +message PreparedTxBuyerSignaturesRequest { string uid = 1; string trade_id = 2; NodeAddress sender_node_address = 3; - bytes sellers_warning_tx = 4; + bytes buyers_warning_tx_seller_signature = 4; bytes sellers_warning_tx_seller_signature = 5; - bytes sellers_redirection_tx = 6; - bytes sellers_redirection_tx_seller_signature = 7; - bytes buyers_warning_tx_seller_signature = 8; + bytes buyers_redirect_tx_seller_signature = 6; + bytes sellers_redirect_tx_seller_signature = 7; } -message DelayedPayoutTxSignatureResponse { +message PreparedTxBuyerSignaturesMessage { string uid = 1; string trade_id = 2; NodeAddress sender_node_address = 3; - bytes delayed_payout_tx_buyer_signature = 4; - bytes deposit_tx = 5; + bytes deposit_tx_with_buyer_witnesses = 4; + bytes buyers_warning_tx_buyer_signature = 5; + bytes sellers_warning_tx_buyer_signature = 6; + bytes buyers_redirect_tx_buyer_signature = 7; + bytes sellers_redirect_tx_buyer_signature = 8; } -message BuyersRedirectSellerSignatureRequest { +message DelayedPayoutTxSignatureRequest { string uid = 1; string trade_id = 2; NodeAddress sender_node_address = 3; - bytes sellers_warning_tx_buyer_signature = 4; - bytes sellers_redirect_tx_buyer_signature = 5; - bytes buyers_redirect_tx = 6; - bytes buyers_redirect_tx_buyer_signature = 7; + bytes delayed_payout_tx = 4; + bytes delayed_payout_tx_seller_signature = 5; } -message BuyersRedirectSellerSignatureResponse { +//message StagedPayoutTxRequest { +// string uid = 1; +// string trade_id = 2; +// NodeAddress sender_node_address = 3; +// bytes sellers_warning_tx = 4; +// bytes sellers_warning_tx_seller_signature = 5; +// bytes sellers_redirection_tx = 6; +// bytes sellers_redirection_tx_seller_signature = 7; +// bytes buyers_warning_tx_seller_signature = 8; +//} + +message DelayedPayoutTxSignatureResponse { string uid = 1; string trade_id = 2; NodeAddress sender_node_address = 3; - bytes buyers_redirect_tx_seller_signature = 7; + bytes delayed_payout_tx_buyer_signature = 4; + bytes deposit_tx = 5; } +//message BuyersRedirectSellerSignatureRequest { +// string uid = 1; +// string trade_id = 2; +// NodeAddress sender_node_address = 3; +// bytes sellers_warning_tx_buyer_signature = 4; +// bytes sellers_redirect_tx_buyer_signature = 5; +// bytes buyers_redirect_tx = 6; +// bytes buyers_redirect_tx_buyer_signature = 7; +//} + +//message BuyersRedirectSellerSignatureResponse { +// string uid = 1; +// string trade_id = 2; +// NodeAddress sender_node_address = 3; +// bytes buyers_redirect_tx_seller_signature = 7; +//} + message DepositTxAndDelayedPayoutTxMessage { string uid = 1;