Skip to content

Commit

Permalink
More changes the get the trade start working
Browse files Browse the repository at this point in the history
Also add trade tasks to publish the warning/redirect/claim txs.
  • Loading branch information
stejbac committed Jul 6, 2024
1 parent 14f0d88 commit 854bfd8
Show file tree
Hide file tree
Showing 21 changed files with 681 additions and 38 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/bisq/core/btc/model/AddressEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public enum Context {
MULTI_SIG,
TRADE_PAYOUT,
WARNING_TX_FEE_BUMP,
REDIRECT_TX_FEE_BUMP,
CLAIM_TX_FEE_BUMP
REDIRECT_TX_FEE_BUMP
}

// keyPair can be null in case the object is created from deserialization as it is transient.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
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.DepositTxAndSellerPaymentAccountMessage;
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.messages.PreparedTxBuyerSignaturesRequest;
Expand Down Expand Up @@ -274,6 +275,8 @@ public NetworkEnvelope fromProto(protobuf.NetworkEnvelope proto) throws Protobuf
return PreparedTxBuyerSignaturesRequest.fromProto(proto.getPreparedTxBuyerSignaturesRequest(), messageVersion);
case PREPARED_TX_BUYER_SIGNATURES_MESSAGE:
return PreparedTxBuyerSignaturesMessage.fromProto(proto.getPreparedTxBuyerSignaturesMessage(), messageVersion);
case DEPOSIT_TX_AND_SELLER_PAYMENT_ACCOUNT_MESSAGE:
return DepositTxAndSellerPaymentAccountMessage.fromProto(proto.getDepositTxAndSellerPaymentAccountMessage(), this, messageVersion);

default:
throw new ProtobufferException("Unknown proto message case (PB.NetworkEnvelope). messageCase=" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@
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.DepositTxAndDelayedPayoutTxMessage;
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.TradeTask;
import bisq.core.trade.protocol.bisq_v1.tasks.VerifyPeersAccountAgeWitness;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDepositTxAndDelayedPayoutTxMessage;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessPayoutTxPublishedMessage;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSendCounterCurrencyTransferStartedMessage;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSendsShareBuyerPaymentAccountMessage;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSetupDepositTxListener;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSetupPayoutTxListener;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerSignPayoutTx;
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerVerifiesFinalDelayedPayoutTx;
import bisq.core.trade.protocol.bisq_v5.messages.DepositTxAndSellerPaymentAccountMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerProcessDepositTxAndSellerPaymentAccountMessage;

import bisq.network.p2p.NodeAddress;

Expand Down Expand Up @@ -92,8 +91,8 @@ protected void onInitialized() {
public void onMailboxMessage(TradeMessage message, NodeAddress peer) {
super.onMailboxMessage(message, peer);

if (message instanceof DepositTxAndDelayedPayoutTxMessage) {
handle((DepositTxAndDelayedPayoutTxMessage) message, peer);
if (message instanceof DepositTxAndSellerPaymentAccountMessage) {
handle((DepositTxAndSellerPaymentAccountMessage) message, peer);
} else if (message instanceof PayoutTxPublishedMessage) {
handle((PayoutTxPublishedMessage) message, peer);
}
Expand All @@ -110,7 +109,7 @@ public void onMailboxMessage(TradeMessage message, NodeAddress peer) {
// For backward compatibility and extra resilience we still keep DepositTxAndDelayedPayoutTxMessage as a
// mailbox message but the stored in mailbox case is not expected and the seller would try to send the message again
// in the hope to reach the buyer directly in case of network issues.
protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress peer) {
protected void handle(DepositTxAndSellerPaymentAccountMessage message, NodeAddress peer) {
expect(anyPhase(Trade.Phase.TAKER_FEE_PUBLISHED, Trade.Phase.DEPOSIT_PUBLISHED)
.with(message)
.from(peer)
Expand All @@ -123,11 +122,10 @@ protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress pe
sendAckMessage(message, true, null);
removeMailboxMessageAfterProcessing(message);
}))
.setup(tasks(BuyerProcessDepositTxAndDelayedPayoutTxMessage.class,
.setup(tasks(BuyerProcessDepositTxAndSellerPaymentAccountMessage.class,
ApplyFilter.class,
VerifyPeersAccountAgeWitness.class,
BuyerSendsShareBuyerPaymentAccountMessage.class,
BuyerVerifiesFinalDelayedPayoutTx.class)
BuyerSendsShareBuyerPaymentAccountMessage.class)
.using(new TradeTaskRunner(trade,
() -> {
stopTimeout();
Expand Down Expand Up @@ -193,8 +191,8 @@ 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 DepositTxAndDelayedPayoutTxMessage) {
handle((DepositTxAndDelayedPayoutTxMessage) message, peer);
if (message instanceof DepositTxAndSellerPaymentAccountMessage) {
handle((DepositTxAndSellerPaymentAccountMessage) message, peer);
} else if (message instanceof PayoutTxPublishedMessage) {
handle((PayoutTxPublishedMessage) message, peer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer
.with(message)
.from(peer))
.setup(tasks(SellerProcessPreparedTxBuyerSignaturesMessage.class,
// SellerFinalizesDelayedPayoutTx.class,
SellerSendsDepositTxAndDelayedPayoutTxMessage.class,
SellerPublishesDepositTx.class,
SellerPublishesTradeStatistics.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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.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;
Expand All @@ -35,6 +34,7 @@
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.DepositTxAndSellerPaymentAccountMessage;
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.CreateRedirectTxs;
Expand Down Expand Up @@ -208,7 +208,7 @@ protected void handle(PreparedTxBuyerSignaturesRequest message, NodeAddress peer
// }

@Override
protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress peer) {
protected void handle(DepositTxAndSellerPaymentAccountMessage message, NodeAddress peer) {
super.handle(message, peer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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.DepositTxAndDelayedPayoutTxMessage;
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;
Expand All @@ -35,13 +34,14 @@
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.DepositTxAndSellerPaymentAccountMessage;
import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx;
Expand Down Expand Up @@ -156,7 +156,7 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) {
// }

@Override
protected void handle(DepositTxAndDelayedPayoutTxMessage message, NodeAddress peer) {
protected void handle(DepositTxAndSellerPaymentAccountMessage message, NodeAddress peer) {
super.handle(message, peer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
import bisq.core.trade.protocol.bisq_v1.tasks.seller.MaybeCreateSubAccount;
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_v5.messages.PreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
Expand All @@ -47,6 +45,7 @@
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSendsDepositTxAndSellerPaymentAccountMessage;
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;
Expand Down Expand Up @@ -150,9 +149,8 @@ protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer
SellerProcessPreparedTxBuyerSignaturesMessage.class,
FinalizeWarningTxs.class,
FinalizeRedirectTxs.class,
SellerAsMakerFinalizesDepositTx.class,
MakerRemovesOpenOffer.class,
SellerSendsDepositTxAndDelayedPayoutTxMessage.class,
SellerSendsDepositTxAndSellerPaymentAccountMessage.class,
SellerPublishesDepositTx.class,
SellerPublishesTradeStatistics.class))
.executeTasks();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

package bisq.core.trade.protocol.bisq_v5.messages;

import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.proto.CoreProtoResolver;
import bisq.core.trade.protocol.bisq_v1.messages.TradeMailboxMessage;

import bisq.network.p2p.NodeAddress;

import bisq.common.app.Version;
import bisq.common.util.Utilities;

import com.google.protobuf.ByteString;

import lombok.EqualsAndHashCode;
import lombok.Getter;

// It is the last message in the take offer phase. We use MailboxMessage instead of DirectMessage to add more tolerance
// in case of network issues and as the message does not trigger further protocol execution.
@EqualsAndHashCode(callSuper = true)
@Getter
public class DepositTxAndSellerPaymentAccountMessage extends TradeMailboxMessage {
private final NodeAddress senderNodeAddress;
private final byte[] depositTx;
private final PaymentAccountPayload sellerPaymentAccountPayload;

public DepositTxAndSellerPaymentAccountMessage(String uid,
String tradeId,
NodeAddress senderNodeAddress,
byte[] depositTx,
PaymentAccountPayload sellerPaymentAccountPayload) {
this(Version.getP2PMessageVersion(),
uid,
tradeId,
senderNodeAddress,
depositTx,
sellerPaymentAccountPayload);
}

///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

private DepositTxAndSellerPaymentAccountMessage(int messageVersion,
String uid,
String tradeId,
NodeAddress senderNodeAddress,
byte[] depositTx,
PaymentAccountPayload sellerPaymentAccountPayload) {
super(messageVersion, tradeId, uid);
this.senderNodeAddress = senderNodeAddress;
this.depositTx = depositTx;
this.sellerPaymentAccountPayload = sellerPaymentAccountPayload;
}

@Override
public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
protobuf.DepositTxAndSellerPaymentAccountMessage.Builder builder = protobuf.DepositTxAndSellerPaymentAccountMessage.newBuilder()
.setUid(uid)
.setTradeId(tradeId)
.setSenderNodeAddress(senderNodeAddress.toProtoMessage())
.setDepositTx(ByteString.copyFrom(depositTx))
.setSellerPaymentAccountPayload((protobuf.PaymentAccountPayload) sellerPaymentAccountPayload.toProtoMessage());

return getNetworkEnvelopeBuilder().setDepositTxAndSellerPaymentAccountMessage(builder).build();
}

public static DepositTxAndSellerPaymentAccountMessage fromProto(protobuf.DepositTxAndSellerPaymentAccountMessage proto,
CoreProtoResolver coreProtoResolver,
int messageVersion) {
return new DepositTxAndSellerPaymentAccountMessage(messageVersion,
proto.getUid(),
proto.getTradeId(),
NodeAddress.fromProto(proto.getSenderNodeAddress()),
proto.getDepositTx().toByteArray(),
coreProtoResolver.fromProto(proto.getSellerPaymentAccountPayload()));
}

@Override
public String toString() {
return "DepositTxAndDelayedPayoutTxMessage{" +
"\n senderNodeAddress=" + senderNodeAddress +
",\n depositTx=" + Utilities.bytesAsHexString(depositTx) +
"\n} " + super.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@Getter
public class PreparedTxBuyerSignaturesMessage extends TradeMessage implements DirectMessage {
private final NodeAddress senderNodeAddress;
private final byte[] depositTxWithBuyerWitnesses; // TODO: Rename to depositTxWithBuyerWitnesses
private final byte[] depositTxWithBuyerWitnesses;
private final byte[] buyersWarningTxBuyerSignature;
private final byte[] sellersWarningTxBuyerSignature;
private final byte[] buyersRedirectTxBuyerSignature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@Slf4j
public class CreateFeeBumpAddressEntries extends TradeTask {
protected CreateFeeBumpAddressEntries(TaskRunner<Trade> taskHandler, Trade trade) {
public CreateFeeBumpAddressEntries(TaskRunner<Trade> taskHandler, Trade trade) {
super(taskHandler, trade);
}

Expand Down
Loading

0 comments on commit 854bfd8

Please sign in to comment.