Skip to content

Commit

Permalink
More temp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stejbac committed Jul 2, 2024
1 parent f21dcfb commit 9c1f04c
Show file tree
Hide file tree
Showing 19 changed files with 241 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

public class RedirectionTransactionFactory {

private final NetworkParameters params;

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

public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOutput,
Transaction redirectionTx,
byte[] buyerPubKey,
byte[] sellerPubKey,
byte[] buyerSignature,
byte[] sellerSignature,
Coin inputValue)
Expand All @@ -105,6 +106,8 @@ public Transaction finalizeRedirectionTransaction(TransactionOutput warningTxOut
TransactionInput input = redirectionTx.getInput(0);
input.setScriptSig(ScriptBuilder.createEmpty());

// FIXME: This redeem script is all wrong. It needs to be build from pubKeys, not signatures,
// and we cannot use TransactionWitness.redeemP2WSH with it, as it isn't a simple multisig script.
Script redeemScript = createRedeemScript(buyerSignature, sellerSignature);
TransactionWitness witness = TransactionWitness.redeemP2WSH(redeemScript);
input.setWitness(witness);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,13 +886,17 @@ public byte[] signRedirectionTx(Transaction redirectionTx,

public Transaction finalizeRedirectionTx(TransactionOutput warningTxOutput,
Transaction redirectionTx,
byte[] buyerPubKey,
byte[] sellerPubKey,
byte[] buyerSignature,
byte[] sellerSignature,
Coin inputValue)
throws AddressFormatException, TransactionVerificationException {
return redirectionTransactionFactory.finalizeRedirectionTransaction(
warningTxOutput,
redirectionTx,
buyerPubKey,
sellerPubKey,
buyerSignature,
sellerSignature,
inputValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
// persist them.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ public final class TradingPeer implements TradePeer {
transient private byte[] warningTxSellerSignature;
@Setter
transient private byte[] warningTxBuyerSignature;
@Setter
private Transaction finalizedWarningTx;

@Setter
transient private Transaction redirectTx;
@Setter
transient private byte[] redirectTxSellerSignature;
@Setter
transient private byte[] redirectTxBuyerSignature;
@Setter
private Transaction finalizedRedirectTx;


// Transient/Mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerVerifyTakerFeePayment;
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesRequest;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerCreatesWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer_as_maker.BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest;
import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5;

Expand Down Expand Up @@ -101,10 +107,14 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message,
BuyerAsMakerCreatesAndSignsDepositTx.class,
BuyerSetupDepositTxListener.class,

// We create our warn tx and our signature for the MS script
// // We create our warn tx and our signature for the MS script
CreateFeeBumpAddressEntries.class,
BuyerCreatesWarningTx.class,
CreateWarningTxs.class,
CreateRedirectTxs.class,
BuyerSignsOwnWarningTx.class,
BuyerSignsPeersWarningTx.class,
BuyerSignsOwnRedirectTx.class,
BuyerSignsPeersRedirectTx.class,

MakerSendsInputsForDepositTxResponse_v5.class)

Expand All @@ -130,6 +140,8 @@ protected void handle(PreparedTxBuyerSignaturesRequest message, NodeAddress peer
.from(peer))
.setup(tasks(
BuyerAsMakerProcessPreparedTxBuyerSignaturesRequest.class,
FinalizeWarningTxs.class,
FinalizeRedirectTxs.class,
MakerRemovesOpenOffer.class,
BuyerSendsPreparedTxBuyerSignaturesMessage.class)
.withTimeout(120))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyAndSignContract;
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment;
import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSendsPreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsOwnWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.buyer.BuyerSignsPeersWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5;

import bisq.network.p2p.NodeAddress;
Expand Down Expand Up @@ -114,6 +122,16 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) {
.from(peer))
.setup(tasks(TakerProcessInputsForDepositTxResponse_v5.class,
ApplyFilter.class,

CreateWarningTxs.class,
CreateRedirectTxs.class,
BuyerSignsOwnWarningTx.class,
BuyerSignsPeersWarningTx.class,
BuyerSignsOwnRedirectTx.class,
BuyerSignsPeersRedirectTx.class,
FinalizeWarningTxs.class,
FinalizeRedirectTxs.class,

TakerVerifyAndSignContract.class,
TakerPublishFeeTx.class,
BuyerAsTakerSignsDepositTx.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@
import bisq.core.trade.protocol.bisq_v1.tasks.seller_as_maker.SellerAsMakerFinalizesDepositTx;
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.maker.MakerSendsInputsForDepositTxResponse_v5;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerProcessPreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx;

import bisq.network.p2p.NodeAddress;

Expand Down Expand Up @@ -93,7 +101,15 @@ public void handleTakeOfferRequest(InputsForDepositTxRequest message,
MakerSetsLockTime.class,
MakerCreateAndSignContract.class,
SellerAsMakerCreatesUnsignedDepositTx.class,

CreateFeeBumpAddressEntries.class,
CreateWarningTxs.class,
CreateRedirectTxs.class,
SellerSignsOwnWarningTx.class,
SellerSignsPeersWarningTx.class,
SellerSignsOwnRedirectTx.class,
SellerSignsPeersRedirectTx.class,

MakerSendsInputsForDepositTxResponse_v5.class)
.using(new TradeTaskRunner(trade,
() -> handleTaskRunnerSuccess(message),
Expand Down Expand Up @@ -132,8 +148,9 @@ protected void handle(PreparedTxBuyerSignaturesMessage message, NodeAddress peer
.from(peer))
.setup(tasks(
SellerProcessPreparedTxBuyerSignaturesMessage.class,
FinalizeWarningTxs.class,
FinalizeRedirectTxs.class,
SellerAsMakerFinalizesDepositTx.class,
// SellerFinalizesDelayedPayoutTx.class,
MakerRemovesOpenOffer.class,
SellerSendsDepositTxAndDelayedPayoutTxMessage.class,
SellerPublishesDepositTx.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
import bisq.core.trade.protocol.bisq_v1.tasks.taker.TakerVerifyMakerFeePayment;
import bisq.core.trade.protocol.bisq_v5.messages.InputsForDepositTxResponse_v5;
import bisq.core.trade.protocol.bisq_v5.messages.PreparedTxBuyerSignaturesMessage;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerCreatesWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeRedirectTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.FinalizeWarningTxs;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsOwnWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersRedirectTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller.SellerSignsPeersWarningTx;
import bisq.core.trade.protocol.bisq_v5.tasks.seller_as_taker.SellerAsTakerSendsPreparedTxBuyerSignaturesRequest;
import bisq.core.trade.protocol.bisq_v5.tasks.CreateFeeBumpAddressEntries;
import bisq.core.trade.protocol.bisq_v5.tasks.taker.TakerProcessInputsForDepositTxResponse_v5;

import bisq.network.p2p.NodeAddress;
Expand Down Expand Up @@ -112,25 +115,33 @@ private void handle(InputsForDepositTxResponse_v5 message, NodeAddress peer) {
.from(peer))
.setup(tasks(
TakerProcessInputsForDepositTxResponse_v5.class,

ApplyFilter.class,

CreateWarningTxs.class,
CreateRedirectTxs.class,
SellerSignsOwnWarningTx.class,
SellerSignsPeersWarningTx.class,
SellerSignsOwnRedirectTx.class,
SellerSignsPeersRedirectTx.class,
FinalizeWarningTxs.class,
FinalizeRedirectTxs.class,

TakerVerifyAndSignContract.class,
TakerPublishFeeTx.class,
SellerAsTakerSignsDepositTx.class,

// We create our warn tx and our signature for the MS script.
SellerCreatesWarningTx.class,
SellerSignsOwnWarningTx.class,
// // We create our warn tx and our signature for the MS script.
// SellerCreatesWarningTx.class,
// SellerSignsOwnWarningTx.class,

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

// We create our redirect tx using the buyers warn tx output and our signature for the MS script
CreateRedirectTx.class,
SellerSignsOwnRedirectTx.class,
// // We create our redirect tx using the buyers warn tx output and our signature for the MS script
// SellerSignsOwnRedirectTx.class,

// We sign the buyers warn tx
SellerSignsPeersWarningTx.class,
// // We sign the buyers warn tx
// SellerSignsPeersWarningTx.class,

// // We send buyer sig for their warn tx and our warn and redirect tx including our signatures
// SellerSendStagedPayoutTxRequest.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

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

import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.trade.model.bisq_v1.Trade;
import bisq.core.trade.protocol.bisq_v1.model.TradingPeer;
Expand All @@ -35,9 +33,11 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

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

Expand All @@ -47,28 +47,44 @@ protected void run() {
runInterceptHook();

TradeWalletService tradeWalletService = processModel.getTradeWalletService();
BtcWalletService btcWalletService = processModel.getBtcWalletService();
String tradeId = processModel.getOffer().getId();
TradingPeer tradingPeer = processModel.getTradePeer();

// Get receiver amounts and addresses.
TransactionOutput warningTxOutput = processModel.getWarningTx().getOutput(0);
TransactionOutput peersWarningTxOutput = tradingPeer.getWarningTx().getOutput(0);

long inputAmount = peersWarningTxOutput.getValue().value;
checkArgument(warningTxOutput.getValue().value == inputAmount,
"Different warningTx output amounts. Ours: {}; Peer's: {}", warningTxOutput.getValue().value, inputAmount);

long depositTxFee = trade.getTradeTxFeeAsLong(); // Used for fee rate calculation inside getDelayedPayoutTxReceiverService
long inputAmountMinusFeeForFeeBumpOutput = inputAmount - 32 * depositTxFee;
int selectionHeight = processModel.getBurningManSelectionHeight();
List<Tuple2<Long, String>> burningMen = processModel.getDelayedPayoutTxReceiverService().getReceivers(
selectionHeight,
inputAmount,
inputAmountMinusFeeForFeeBumpOutput,
depositTxFee);
log.info("Create redirectionTx using selectionHeight {} and receivers {}", selectionHeight, burningMen);

AddressEntry feeBumpAddressEntry = btcWalletService.getOrCreateAddressEntry(tradeId, AddressEntry.Context.REDIRECT_TX_FEE_BUMP);
Tuple2<Long, String> feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddressEntry.getAddressString());
log.info("Create redirectionTxs using selectionHeight {} and receivers {}", selectionHeight, burningMen);

// Create our redirect tx.
String feeBumpAddress = processModel.getRedirectTxFeeBumpAddress();
var feeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, feeBumpAddress);

Transaction unsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(peersWarningTxOutput,
burningMen,
feeBumpOutputAmountAndAddress);
processModel.setRedirectTx(unsignedRedirectionTx);

// Create peer's redirect tx.
String peersFeeBumpAddress = tradingPeer.getRedirectTxFeeBumpAddress();
var peersFeeBumpOutputAmountAndAddress = new Tuple2<>(StagedPayoutTxParameters.REDIRECT_TX_FEE_BUMP_OUTPUT_VALUE, peersFeeBumpAddress);

Transaction peersUnsignedRedirectionTx = tradeWalletService.createUnsignedRedirectionTx(warningTxOutput,
burningMen,
peersFeeBumpOutputAmountAndAddress);
tradingPeer.setRedirectTx(peersUnsignedRedirectionTx);

processModel.getTradeManager().requestPersistence();

complete();
Expand Down
Loading

0 comments on commit 9c1f04c

Please sign in to comment.