Skip to content

Commit

Permalink
Temp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stejbac committed May 17, 2024
1 parent ebe53bf commit c8b4ebb
Show file tree
Hide file tree
Showing 27 changed files with 1,041 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +145,8 @@ public InputsForDepositTxRequest(String tradeId,
this.hashOfTakersPaymentAccountPayload = hashOfTakersPaymentAccountPayload;
this.takersPaymentMethodId = takersPaymentMethodId;
this.burningManSelectionHeight = burningManSelectionHeight;
this.takersWarningTxFeeBumpAddress = takersWarningTxFeeBumpAddress;
this.takersRedirectTxFeeBumpAddress = takersRedirectTxFeeBumpAddress;
}


Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ protected void run() {

trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());

tradingPeer.setWarningTxFeeBumpAddress(request.getTakersWarningTxFeeBumpAddress());
tradingPeer.setRedirectTxFeeBumpAddress(request.getTakersRedirectTxFeeBumpAddress());

processModel.getTradeManager().requestPersistence();

complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -135,6 +134,7 @@ protected void handle(CounterCurrencyTransferStartedMessage message, NodeAddress
.executeTasks();
}


///////////////////////////////////////////////////////////////////////////////////////////
// User interaction
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -168,15 +168,19 @@ 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 {}",
message.getClass().getSimpleName(), peer, message.getTradeId(), message.getUid());

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) {
Expand All @@ -185,5 +189,4 @@ protected void onTradeMessage(TradeMessage message, NodeAddress peer) {
}

abstract protected Class<? extends TradeTask> getVerifyPeersFeePaymentClass();

}
Loading

0 comments on commit c8b4ebb

Please sign in to comment.