Skip to content

Commit 9c1f04c

Browse files
committed
More temp changes
1 parent f21dcfb commit 9c1f04c

19 files changed

+241
-213
lines changed

core/src/main/java/bisq/core/btc/wallet/RedirectionTransactionFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import static com.google.common.base.Preconditions.checkNotNull;
4444

4545
public class RedirectionTransactionFactory {
46-
4746
private final NetworkParameters params;
4847

4948
public RedirectionTransactionFactory(NetworkParameters params) {
@@ -97,6 +96,8 @@ public byte[] signRedirectionTransaction(Transaction redirectionTx,
9796

9897
public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOutput,
9998
Transaction redirectionTx,
99+
byte[] buyerPubKey,
100+
byte[] sellerPubKey,
100101
byte[] buyerSignature,
101102
byte[] sellerSignature,
102103
Coin inputValue)
@@ -105,6 +106,8 @@ public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOut
105106
TransactionInput input = redirectionTx.getInput(0);
106107
input.setScriptSig(ScriptBuilder.createEmpty());
107108

109+
// FIXME: This redeem script is all wrong. It needs to be build from pubKeys, not signatures,
110+
// and we cannot use TransactionWitness.redeemP2WSH with it, as it isn't a simple multisig script.
108111
Script redeemScript = createRedeemScript(buyerSignature, sellerSignature);
109112
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript);
110113
input.setWitness(witness);

core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,17 @@ public byte[] signRedirectionTx(Transaction redirectionTx,
886886

887887
public Transaction finalizeRedirectionTx(TransactionOutput warningTxOutput,
888888
Transaction redirectionTx,
889+
byte[] buyerPubKey,
890+
byte[] sellerPubKey,
889891
byte[] buyerSignature,
890892
byte[] sellerSignature,
891893
Coin inputValue)
892894
throws AddressFormatException, TransactionVerificationException {
893895
return redirectionTransactionFactory.finalizeRedirectionTransaction(
894896
warningTxOutput,
895897
redirectionTx,
898+
buyerPubKey,
899+
sellerPubKey,
896900
buyerSignature,
897901
sellerSignature,
898902
inputValue

core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/ProcessModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// persist them.
7979

8080
/**
81-
* This is the base model for the trade protocol. It is persisted with the trade (non transient fields).
81+
* This is the base model for the trade protocol. It is persisted with the trade (non-transient fields).
8282
* It uses the {@link Provider} for access to domain services.
8383
*/
8484

core/src/main/java/bisq/core/trade/protocol/bisq_v1/model/TradingPeer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ public final class TradingPeer implements TradePeer {
6363
transient private byte[] warningTxSellerSignature;
6464
@Setter
6565
transient private byte[] warningTxBuyerSignature;
66+
@Setter
67+
private Transaction finalizedWarningTx;
6668

6769
@Setter
6870
transient private Transaction redirectTx;
6971
@Setter
7072
transient private byte[] redirectTxSellerSignature;
7173
@Setter
7274
transient private byte[] redirectTxBuyerSignature;
75+
@Setter
76+
private Transaction finalizedRedirectTx;
7377

7478

7579
// Transient/Mutable

core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsMakerProtocol_v5.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@
3737
import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerVerifyTakerFeePayment;
3838
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesRequest;
3939
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
40-
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerCreatesWarningTx;
40+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
41+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
42+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
43+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
4144
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage;
45+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx;
4246
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx;
47+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx;
48+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx;
4349
import bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker.BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest;
4450
import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5;
4551

@@ -101,10 +107,14 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message,
101107
BuyerAsMakerCreatesAndSignsDepositTx.class,
102108
BuyerSetupDepositTxListener.class,
103109

104-
// We create our warn tx and our signature for the MS script
110+
// // We create our warn tx and our signature for the MS script
105111
CreateFeeBumpAddressEntries.class,
106-
BuyerCreatesWarningTx.class,
112+
CreateWarningTxs.class,
113+
CreateRedirectTxs.class,
107114
BuyerSignsOwnWarningTx.class,
115+
BuyerSignsPeersWarningTx.class,
116+
BuyerSignsOwnRedirectTx.class,
117+
BuyerSignsPeersRedirectTx.class,
108118

109119
MakerSendsInputsForDepositTxResponse_v5.class)
110120

@@ -130,6 +140,8 @@ protected void handle(PreparedTxBuyerSignaturesRequest message, NodeAddress peer
130140
.from(peer))
131141
.setup(tasks(
132142
BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.class,
143+
FinalizeWarningTxs.class,
144+
FinalizeRedirectTxs.class,
133145
MakerRemovesOpenOffer.class,
134146
BuyerSendsPreparedTxBuyerSignaturesMessage.class)
135147
.withTimeout(120))

core/src/main/java/bisq/core/trade/protocol/bisq_v5/BuyerAsTakerProtocol_v5.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@
3636
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyAndSignContract;
3737
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment;
3838
import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5;
39+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
40+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
41+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
42+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
3943
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage;
4044
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
45+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx;
46+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx;
47+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx;
48+
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx;
4149
import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5;
4250

4351
import bisq.network.p2p.NodeAddress;
@@ -114,6 +122,16 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) {
114122
.from(peer))
115123
.setup(tasks(TakerProcessInputsForDepositTxResponse_v5.class,
116124
ApplyFilter.class,
125+
126+
CreateWarningTxs.class,
127+
CreateRedirectTxs.class,
128+
BuyerSignsOwnWarningTx.class,
129+
BuyerSignsPeersWarningTx.class,
130+
BuyerSignsOwnRedirectTx.class,
131+
BuyerSignsPeersRedirectTx.class,
132+
FinalizeWarningTxs.class,
133+
FinalizeRedirectTxs.class,
134+
117135
TakerVerifyAndSignContract.class,
118136
TakerPublishFeeTx.class,
119137
BuyerAsTakerSignsDepositTx.class,

core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsMakerProtocol_v5.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@
4141
import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerFinalizesDepositTx;
4242
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage;
4343
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
44+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
45+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
46+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
47+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
4448
import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5;
4549
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage;
50+
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx;
51+
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx;
52+
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx;
53+
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx;
4654

4755
import bisq.network.p2p.NodeAddress;
4856

@@ -93,7 +101,15 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message,
93101
MakerSetsLockTime.class,
94102
MakerCreateAndSignContract.class,
95103
SellerAsMakerCreatesUnsignedDepositTx.class,
104+
96105
CreateFeeBumpAddressEntries.class,
106+
CreateWarningTxs.class,
107+
CreateRedirectTxs.class,
108+
SellerSignsOwnWarningTx.class,
109+
SellerSignsPeersWarningTx.class,
110+
SellerSignsOwnRedirectTx.class,
111+
SellerSignsPeersRedirectTx.class,
112+
97113
MakerSendsInputsForDepositTxResponse_v5.class)
98114
.using(new TradeTaskRunner(trade,
99115
() -> handleTaskRunnerSuccess(message),
@@ -132,8 +148,9 @@ protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer
132148
.from(peer))
133149
.setup(tasks(
134150
SellerProcessPreparedTxBuyerSignaturesMessage.class,
151+
FinalizeWarningTxs.class,
152+
FinalizeRedirectTxs.class,
135153
SellerAsMakerFinalizesDepositTx.class,
136-
// SellerFinalizesDelayedPayoutTx.class,
137154
MakerRemovesOpenOffer.class,
138155
SellerSendsDepositTxAndDelayedPayoutTxMessage.class,
139156
SellerPublishesDepositTx.class,

core/src/main/java/bisq/core/trade/protocol/bisq_v5/SellerAsTakerProtocol_v5.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment;
3838
import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5;
3939
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage;
40-
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTx;
41-
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerCreatesWarningTx;
40+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
41+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
42+
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
43+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
44+
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
4245
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx;
4346
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx;
47+
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx;
4448
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx;
4549
import bisq.core.trade.protocol.bisq_v5.tasks.seller_as_taker.SellerAsTakerSendsPreparedTxBuyerSignaturesRequest;
46-
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
4750
import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5;
4851

4952
import bisq.network.p2p.NodeAddress;
@@ -112,25 +115,33 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) {
112115
.from(peer))
113116
.setup(tasks(
114117
TakerProcessInputsForDepositTxResponse_v5.class,
115-
116118
ApplyFilter.class,
119+
120+
CreateWarningTxs.class,
121+
CreateRedirectTxs.class,
122+
SellerSignsOwnWarningTx.class,
123+
SellerSignsPeersWarningTx.class,
124+
SellerSignsOwnRedirectTx.class,
125+
SellerSignsPeersRedirectTx.class,
126+
FinalizeWarningTxs.class,
127+
FinalizeRedirectTxs.class,
128+
117129
TakerVerifyAndSignContract.class,
118130
TakerPublishFeeTx.class,
119131
SellerAsTakerSignsDepositTx.class,
120132

121-
// We create our warn tx and our signature for the MS script.
122-
SellerCreatesWarningTx.class,
123-
SellerSignsOwnWarningTx.class,
133+
// // We create our warn tx and our signature for the MS script.
134+
// SellerCreatesWarningTx.class,
135+
// SellerSignsOwnWarningTx.class,
124136

125137
// We can now create the signed claim tx from out warn tx
126138
// CreateSignedClaimTx.class,
127139

128-
// We create our redirect tx using the buyers warn tx output and our signature for the MS script
129-
CreateRedirectTx.class,
130-
SellerSignsOwnRedirectTx.class,
140+
// // We create our redirect tx using the buyers warn tx output and our signature for the MS script
141+
// SellerSignsOwnRedirectTx.class,
131142

132-
// We sign the buyers warn tx
133-
SellerSignsPeersWarningTx.class,
143+
// // We sign the buyers warn tx
144+
// SellerSignsPeersWarningTx.class,
134145

135146
// // We send buyer sig for their warn tx and our warn and redirect tx including our signatures
136147
// SellerSendStagedPayoutTxRequest.class)

core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTx.java renamed to core/src/main/java/bisq/core/trade/protocol/bisq_v5/tasks/CreateRedirectTxs.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package bisq.core.trade.protocol.bisq_v5.tasks;
1919

20-
import bisq.core.btc.model.AddressEntry;
21-
import bisq.core.btc.wallet.BtcWalletService;
2220
import bisq.core.btc.wallet.TradeWalletService;
2321
import bisq.core.trade.model.bisq_v1.Trade;
2422
import bisq.core.trade.protocol.bisq_v1.model.TradingPeer;
@@ -35,9 +33,11 @@
3533

3634
import lombok.extern.slf4j.Slf4j;
3735

36+
import static com.google.common.base.Preconditions.checkArgument;
37+
3838
@Slf4j
39-
public class CreateRedirectTx extends TradeTask {
40-
public CreateRedirectTx(TaskRunner<Trade> taskHandler, Trade trade) {
39+
public class CreateRedirectTxs extends TradeTask {
40+
public CreateRedirectTxs(TaskRunner<Trade> taskHandler, Trade trade) {
4141
super(taskHandler, trade);
4242
}
4343

@@ -47,28 +47,44 @@ protected void run() {
4747
runInterceptHook();
4848

4949
TradeWalletService tradeWalletService = processModel.getTradeWalletService();
50-
BtcWalletService btcWalletService = processModel.getBtcWalletService();
51-
String tradeId = processModel.getOffer().getId();
5250
TradingPeer tradingPeer = processModel.getTradePeer();
5351

52+
// Get receiver amounts and addresses.
53+
TransactionOutput warningTxOutput = processModel.getWarningTx().getOutput(0);
5454
TransactionOutput peersWarningTxOutput = tradingPeer.getWarningTx().getOutput(0);
55+
5556
long inputAmount = peersWarningTxOutput.getValue().value;
57+
checkArgument(warningTxOutput.getValue().value == inputAmount,
58+
"Different warningTx output amounts. Ours: {}; Peer's: {}", warningTxOutput.getValue().value, inputAmount);
59+
5660
long depositTxFee = trade.getTradeTxFeeAsLong(); // Used for fee rate calculation inside getDelayedPayoutTxReceiverService
61+
long inputAmountMinusFeeForFeeBumpOutput = inputAmount - 32 * depositTxFee;
5762
int selectionHeight = processModel.getBurningManSelectionHeight();
5863
List<Tuple2<Long, String>> burningMen = processModel.getDelayedPayoutTxReceiverService().getReceivers(
5964
selectionHeight,
60-
inputAmount,
65+
inputAmountMinusFeeForFeeBumpOutput,
6166
depositTxFee);
62-
log.info("Create redirectionTx using selectionHeight {} and receivers {}", selectionHeight, burningMen);
6367

64-
AddressEntry feeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.REDIRECT_TX_FEE_BUMP);
65-
Tuple2<Long, String> feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddressEntry.getAddressString());
68+
log.info("Create redirectionTxs using selectionHeight {} and receivers {}", selectionHeight, burningMen);
69+
70+
// Create our redirect tx.
71+
String feeBumpAddress = processModel.getRedirectTxFeeBumpAddress();
72+
var feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddress);
6673

6774
Transaction unsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(peersWarningTxOutput,
6875
burningMen,
6976
feeBumpOutputAmountAndAddress);
7077
processModel.setRedirectTx(unsignedRedirectionTx);
7178

79+
// Create peer's redirect tx.
80+
String peersFeeBumpAddress = tradingPeer.getRedirectTxFeeBumpAddress();
81+
var peersFeeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, peersFeeBumpAddress);
82+
83+
Transaction peersUnsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(warningTxOutput,
84+
burningMen,
85+
peersFeeBumpOutputAmountAndAddress);
86+
tradingPeer.setRedirectTx(peersUnsignedRedirectionTx);
87+
7288
processModel.getTradeManager().requestPersistence();
7389

7490
complete();

0 commit comments

Comments
 (0)