mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Merge pull request #4860 from stejbac/add-deposit-amount-taker-check
Add taker check for deposit amount
This commit is contained in:
commit
cae09f8ff5
@ -565,19 +565,21 @@ public class TradeWalletService {
|
|||||||
* @param takerIsSeller the flag indicating if we are in the taker as seller role or the opposite
|
* @param takerIsSeller the flag indicating if we are in the taker as seller role or the opposite
|
||||||
* @param contractHash the hash of the contract to be added to the OP_RETURN output
|
* @param contractHash the hash of the contract to be added to the OP_RETURN output
|
||||||
* @param makersDepositTxSerialized the prepared deposit transaction signed by the maker
|
* @param makersDepositTxSerialized the prepared deposit transaction signed by the maker
|
||||||
|
* @param msOutputAmount the MultiSig output amount, as determined by the taker
|
||||||
* @param buyerInputs the connected outputs for all inputs of the buyer
|
* @param buyerInputs the connected outputs for all inputs of the buyer
|
||||||
* @param sellerInputs the connected outputs for all inputs of the seller
|
* @param sellerInputs the connected outputs for all inputs of the seller
|
||||||
* @param buyerPubKey the public key of the buyer
|
* @param buyerPubKey the public key of the buyer
|
||||||
* @param sellerPubKey the public key of the seller
|
* @param sellerPubKey the public key of the seller
|
||||||
* @throws SigningException if (one of) the taker input(s) was of an unrecognized type for signing
|
* @throws SigningException if (one of) the taker input(s) was of an unrecognized type for signing
|
||||||
* @throws TransactionVerificationException if a non-P2WH maker-as-buyer input wasn't signed, the maker's MultiSig
|
* @throws TransactionVerificationException if a non-P2WH maker-as-buyer input wasn't signed, the maker's MultiSig
|
||||||
* script or contract hash doesn't match the taker's, or there was an unexpected problem with the final deposit tx
|
* script, contract hash or output amount doesn't match the taker's, or there was an unexpected problem with the
|
||||||
* or its signatures
|
* final deposit tx or its signatures
|
||||||
* @throws WalletException if the taker's wallet is null or structurally inconsistent
|
* @throws WalletException if the taker's wallet is null or structurally inconsistent
|
||||||
*/
|
*/
|
||||||
public Transaction takerSignsDepositTx(boolean takerIsSeller,
|
public Transaction takerSignsDepositTx(boolean takerIsSeller,
|
||||||
byte[] contractHash,
|
byte[] contractHash,
|
||||||
byte[] makersDepositTxSerialized,
|
byte[] makersDepositTxSerialized,
|
||||||
|
Coin msOutputAmount,
|
||||||
List<RawTransactionInput> buyerInputs,
|
List<RawTransactionInput> buyerInputs,
|
||||||
List<RawTransactionInput> sellerInputs,
|
List<RawTransactionInput> sellerInputs,
|
||||||
byte[] buyerPubKey,
|
byte[] buyerPubKey,
|
||||||
@ -588,10 +590,15 @@ public class TradeWalletService {
|
|||||||
checkArgument(!buyerInputs.isEmpty());
|
checkArgument(!buyerInputs.isEmpty());
|
||||||
checkArgument(!sellerInputs.isEmpty());
|
checkArgument(!sellerInputs.isEmpty());
|
||||||
|
|
||||||
// Check if maker's MultiSig script is identical to the takers
|
// Check if maker's MultiSig script is identical to the taker's
|
||||||
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey, false);
|
Script hashedMultiSigOutputScript = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey, false);
|
||||||
if (!makersDepositTx.getOutput(0).getScriptPubKey().equals(hashedMultiSigOutputScript)) {
|
if (!makersDepositTx.getOutput(0).getScriptPubKey().equals(hashedMultiSigOutputScript)) {
|
||||||
throw new TransactionVerificationException("Maker's hashedMultiSigOutputScript does not match to takers hashedMultiSigOutputScript");
|
throw new TransactionVerificationException("Maker's hashedMultiSigOutputScript does not match taker's hashedMultiSigOutputScript");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if maker's MultiSig output value is identical to the taker's
|
||||||
|
if (!makersDepositTx.getOutput(0).getValue().equals(msOutputAmount)) {
|
||||||
|
throw new TransactionVerificationException("Maker's MultiSig output amount does not match taker's MultiSig output amount");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The outpoints are not available from the serialized makersDepositTx, so we cannot use that tx directly, but we use it to construct a new
|
// The outpoints are not available from the serialized makersDepositTx, so we cannot use that tx directly, but we use it to construct a new
|
||||||
@ -642,7 +649,7 @@ public class TradeWalletService {
|
|||||||
TransactionOutput makersContractHashOutput = makersDepositTx.getOutputs().get(1);
|
TransactionOutput makersContractHashOutput = makersDepositTx.getOutputs().get(1);
|
||||||
log.debug("makersContractHashOutput {}", makersContractHashOutput);
|
log.debug("makersContractHashOutput {}", makersContractHashOutput);
|
||||||
if (!makersContractHashOutput.getScriptPubKey().equals(contractHashOutput.getScriptPubKey())) {
|
if (!makersContractHashOutput.getScriptPubKey().equals(contractHashOutput.getScriptPubKey())) {
|
||||||
throw new TransactionVerificationException("Maker's transaction output for the contract hash is not matching takers version.");
|
throw new TransactionVerificationException("Maker's transaction output for the contract hash is not matching taker's version.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all outputs from makersDepositTx to depositTx
|
// Add all outputs from makersDepositTx to depositTx
|
||||||
|
@ -20,6 +20,7 @@ package bisq.core.trade.protocol.tasks.buyer_as_taker;
|
|||||||
import bisq.core.btc.model.AddressEntry;
|
import bisq.core.btc.model.AddressEntry;
|
||||||
import bisq.core.btc.model.RawTransactionInput;
|
import bisq.core.btc.model.RawTransactionInput;
|
||||||
import bisq.core.btc.wallet.BtcWalletService;
|
import bisq.core.btc.wallet.BtcWalletService;
|
||||||
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.protocol.TradingPeer;
|
import bisq.core.trade.protocol.TradingPeer;
|
||||||
import bisq.core.trade.protocol.tasks.TradeTask;
|
import bisq.core.trade.protocol.tasks.TradeTask;
|
||||||
@ -71,6 +72,10 @@ public class BuyerAsTakerSignsDepositTx extends TradeTask {
|
|||||||
buyerMultiSigAddressEntry.setCoinLockedInMultiSig(buyerInput.subtract(trade.getTxFee().multiply(2)));
|
buyerMultiSigAddressEntry.setCoinLockedInMultiSig(buyerInput.subtract(trade.getTxFee().multiply(2)));
|
||||||
walletService.saveAddressEntryList();
|
walletService.saveAddressEntryList();
|
||||||
|
|
||||||
|
Offer offer = trade.getOffer();
|
||||||
|
Coin msOutputAmount = offer.getBuyerSecurityDeposit().add(offer.getSellerSecurityDeposit()).add(trade.getTxFee())
|
||||||
|
.add(checkNotNull(trade.getTradeAmount()));
|
||||||
|
|
||||||
TradingPeer tradingPeer = processModel.getTradingPeer();
|
TradingPeer tradingPeer = processModel.getTradingPeer();
|
||||||
byte[] buyerMultiSigPubKey = processModel.getMyMultiSigPubKey();
|
byte[] buyerMultiSigPubKey = processModel.getMyMultiSigPubKey();
|
||||||
checkArgument(Arrays.equals(buyerMultiSigPubKey, buyerMultiSigAddressEntry.getPubKey()),
|
checkArgument(Arrays.equals(buyerMultiSigPubKey, buyerMultiSigAddressEntry.getPubKey()),
|
||||||
@ -82,6 +87,7 @@ public class BuyerAsTakerSignsDepositTx extends TradeTask {
|
|||||||
false,
|
false,
|
||||||
contractHash,
|
contractHash,
|
||||||
processModel.getPreparedDepositTx(),
|
processModel.getPreparedDepositTx(),
|
||||||
|
msOutputAmount,
|
||||||
buyerInputs,
|
buyerInputs,
|
||||||
sellerInputs,
|
sellerInputs,
|
||||||
buyerMultiSigPubKey,
|
buyerMultiSigPubKey,
|
||||||
|
@ -20,6 +20,7 @@ package bisq.core.trade.protocol.tasks.seller_as_taker;
|
|||||||
import bisq.core.btc.model.AddressEntry;
|
import bisq.core.btc.model.AddressEntry;
|
||||||
import bisq.core.btc.model.RawTransactionInput;
|
import bisq.core.btc.model.RawTransactionInput;
|
||||||
import bisq.core.btc.wallet.BtcWalletService;
|
import bisq.core.btc.wallet.BtcWalletService;
|
||||||
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.trade.Contract;
|
import bisq.core.trade.Contract;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.protocol.TradingPeer;
|
import bisq.core.trade.protocol.TradingPeer;
|
||||||
@ -69,12 +70,17 @@ public class SellerAsTakerSignsDepositTx extends TradeTask {
|
|||||||
sellerMultiSigAddressEntry.setCoinLockedInMultiSig(sellerInput.subtract(totalFee));
|
sellerMultiSigAddressEntry.setCoinLockedInMultiSig(sellerInput.subtract(totalFee));
|
||||||
walletService.saveAddressEntryList();
|
walletService.saveAddressEntryList();
|
||||||
|
|
||||||
|
Offer offer = trade.getOffer();
|
||||||
|
Coin msOutputAmount = offer.getBuyerSecurityDeposit().add(offer.getSellerSecurityDeposit()).add(trade.getTxFee())
|
||||||
|
.add(checkNotNull(trade.getTradeAmount()));
|
||||||
|
|
||||||
TradingPeer tradingPeer = processModel.getTradingPeer();
|
TradingPeer tradingPeer = processModel.getTradingPeer();
|
||||||
|
|
||||||
Transaction depositTx = processModel.getTradeWalletService().takerSignsDepositTx(
|
Transaction depositTx = processModel.getTradeWalletService().takerSignsDepositTx(
|
||||||
true,
|
true,
|
||||||
trade.getContractHash(),
|
trade.getContractHash(),
|
||||||
processModel.getPreparedDepositTx(),
|
processModel.getPreparedDepositTx(),
|
||||||
|
msOutputAmount,
|
||||||
checkNotNull(tradingPeer.getRawTransactionInputs()),
|
checkNotNull(tradingPeer.getRawTransactionInputs()),
|
||||||
sellerInputs,
|
sellerInputs,
|
||||||
tradingPeer.getMultiSigPubKey(),
|
tradingPeer.getMultiSigPubKey(),
|
||||||
|
Loading…
Reference in New Issue
Block a user