mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Add more checks for delayed payout tx
This commit is contained in:
parent
99f542bc4b
commit
8cf6d42309
5 changed files with 62 additions and 11 deletions
|
@ -724,11 +724,29 @@ public class TradeWalletService {
|
||||||
return delayedPayoutTx;
|
return delayedPayoutTx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verifiesDepositTxAndDelayedPayoutTx(@SuppressWarnings("unused") Transaction depositTx,
|
public boolean verifiesDepositTxAndDelayedPayoutTx(Transaction depositTx,
|
||||||
Transaction delayedPayoutTx) {
|
Transaction delayedPayoutTx,
|
||||||
// todo add more checks
|
long lockTime) {
|
||||||
if (delayedPayoutTx.getLockTime() == 0) {
|
|
||||||
log.error("Time lock is not set");
|
TransactionOutput p2SHMultiSigOutput = depositTx.getOutput(0);
|
||||||
|
if (delayedPayoutTx.getInputs().size() != 1) {
|
||||||
|
log.error("Number of inputs must be 1");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransactionOutput connectedOutput = delayedPayoutTx.getInput(0).getConnectedOutput();
|
||||||
|
if (connectedOutput == null) {
|
||||||
|
log.error("connectedOutput must not be null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connectedOutput.equals(p2SHMultiSigOutput)) {
|
||||||
|
log.error("connectedOutput must be p2SHMultiSigOutput");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delayedPayoutTx.getLockTime() != lockTime) {
|
||||||
|
log.error("LockTime must match trades lockTime");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,11 +1246,10 @@ public class TradeWalletService {
|
||||||
private boolean removeDust(Transaction transaction) {
|
private boolean removeDust(Transaction transaction) {
|
||||||
List<TransactionOutput> originalTransactionOutputs = transaction.getOutputs();
|
List<TransactionOutput> originalTransactionOutputs = transaction.getOutputs();
|
||||||
List<TransactionOutput> keepTransactionOutputs = new ArrayList<>();
|
List<TransactionOutput> keepTransactionOutputs = new ArrayList<>();
|
||||||
for (TransactionOutput transactionOutput: originalTransactionOutputs) {
|
for (TransactionOutput transactionOutput : originalTransactionOutputs) {
|
||||||
if (transactionOutput.getValue().isLessThan(Restrictions.getMinNonDustOutput())) {
|
if (transactionOutput.getValue().isLessThan(Restrictions.getMinNonDustOutput())) {
|
||||||
log.info("your transaction would have contained a dust output of {}", transactionOutput.toString());
|
log.info("your transaction would have contained a dust output of {}", transactionOutput.toString());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
keepTransactionOutputs.add(transactionOutput);
|
keepTransactionOutputs.add(transactionOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.bitcoinj.core.TransactionOutput;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -71,6 +72,9 @@ public class DonationAddressValidation {
|
||||||
// In case the seller has deactivated the DAO the default address will be used.
|
// In case the seller has deactivated the DAO the default address will be used.
|
||||||
String defaultDonationAddressString = Param.RECIPIENT_BTC_ADDRESS.getDefaultValue();
|
String defaultDonationAddressString = Param.RECIPIENT_BTC_ADDRESS.getDefaultValue();
|
||||||
|
|
||||||
|
checkArgument(delayedPayoutTx.getOutputs().size() == 1,
|
||||||
|
"preparedDelayedPayoutTx must have 1 output");
|
||||||
|
|
||||||
TransactionOutput output = delayedPayoutTx.getOutput(0);
|
TransactionOutput output = delayedPayoutTx.getOutput(0);
|
||||||
NetworkParameters params = btcWalletService.getParams();
|
NetworkParameters params = btcWalletService.getParams();
|
||||||
Address address = output.getAddressFromP2PKHScript(params);
|
Address address = output.getAddressFromP2PKHScript(params);
|
||||||
|
|
|
@ -42,7 +42,9 @@ public class BuyerVerifiesFinalDelayedPayoutTx extends TradeTask {
|
||||||
|
|
||||||
Transaction depositTx = checkNotNull(trade.getDepositTx());
|
Transaction depositTx = checkNotNull(trade.getDepositTx());
|
||||||
Transaction delayedPayoutTx = checkNotNull(trade.getDelayedPayoutTx());
|
Transaction delayedPayoutTx = checkNotNull(trade.getDelayedPayoutTx());
|
||||||
if (processModel.getTradeWalletService().verifiesDepositTxAndDelayedPayoutTx(depositTx, delayedPayoutTx)) {
|
if (processModel.getTradeWalletService().verifiesDepositTxAndDelayedPayoutTx(depositTx,
|
||||||
|
delayedPayoutTx,
|
||||||
|
trade.getLockTime())) {
|
||||||
complete();
|
complete();
|
||||||
} else {
|
} else {
|
||||||
failed("DelayedPayoutTx is not spending depositTx correctly");
|
failed("DelayedPayoutTx is not spending depositTx correctly");
|
||||||
|
|
|
@ -17,14 +17,22 @@
|
||||||
|
|
||||||
package bisq.core.trade.protocol.tasks.buyer;
|
package bisq.core.trade.protocol.tasks.buyer;
|
||||||
|
|
||||||
|
import bisq.core.offer.Offer;
|
||||||
import bisq.core.trade.DonationAddressValidation;
|
import bisq.core.trade.DonationAddressValidation;
|
||||||
import bisq.core.trade.Trade;
|
import bisq.core.trade.Trade;
|
||||||
import bisq.core.trade.protocol.tasks.TradeTask;
|
import bisq.core.trade.protocol.tasks.TradeTask;
|
||||||
|
|
||||||
import bisq.common.taskrunner.TaskRunner;
|
import bisq.common.taskrunner.TaskRunner;
|
||||||
|
|
||||||
|
import org.bitcoinj.core.Coin;
|
||||||
|
import org.bitcoinj.core.Transaction;
|
||||||
|
import org.bitcoinj.core.TransactionInput;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BuyerVerifiesPreparedDelayedPayoutTx extends TradeTask {
|
public class BuyerVerifiesPreparedDelayedPayoutTx extends TradeTask {
|
||||||
@SuppressWarnings({"unused"})
|
@SuppressWarnings({"unused"})
|
||||||
|
@ -37,9 +45,29 @@ public class BuyerVerifiesPreparedDelayedPayoutTx extends TradeTask {
|
||||||
try {
|
try {
|
||||||
runInterceptHook();
|
runInterceptHook();
|
||||||
|
|
||||||
DonationAddressValidation.validate(processModel.getPreparedDelayedPayoutTx(),
|
Transaction preparedDelayedPayoutTx = processModel.getPreparedDelayedPayoutTx();
|
||||||
|
|
||||||
|
// Check donation address
|
||||||
|
DonationAddressValidation.validate(preparedDelayedPayoutTx,
|
||||||
processModel.getDaoFacade(),
|
processModel.getDaoFacade(),
|
||||||
processModel.getBtcWalletService());
|
processModel.getBtcWalletService());
|
||||||
|
|
||||||
|
// Check amount
|
||||||
|
Offer offer = checkNotNull(trade.getOffer());
|
||||||
|
Coin msOutputAmount = offer.getBuyerSecurityDeposit()
|
||||||
|
.add(offer.getSellerSecurityDeposit())
|
||||||
|
.add(checkNotNull(trade.getTradeAmount()));
|
||||||
|
checkArgument(preparedDelayedPayoutTx.getOutput(0).getValue().equals(msOutputAmount),
|
||||||
|
"output value of deposit tx and delayed payout tx must match");
|
||||||
|
|
||||||
|
// Check lock time
|
||||||
|
checkArgument(preparedDelayedPayoutTx.getLockTime() == trade.getLockTime(),
|
||||||
|
"preparedDelayedPayoutTx lock time must match trade.getLockTime()");
|
||||||
|
|
||||||
|
// Check seq num
|
||||||
|
checkArgument(preparedDelayedPayoutTx.getInputs().stream().anyMatch(e -> e.getSequenceNumber() == TransactionInput.NO_SEQUENCE - 1),
|
||||||
|
"Sequence number must be 0xFFFFFFFE");
|
||||||
|
|
||||||
complete();
|
complete();
|
||||||
} catch (DonationAddressValidation.DonationAddressException e) {
|
} catch (DonationAddressValidation.DonationAddressException e) {
|
||||||
failed("Sellers donation address is invalid." +
|
failed("Sellers donation address is invalid." +
|
||||||
|
|
|
@ -231,7 +231,7 @@ public abstract class MutableOfferViewModel<M extends MutableOfferDataModel> ext
|
||||||
if (DevEnv.isDevMode()) {
|
if (DevEnv.isDevMode()) {
|
||||||
UserThread.runAfter(() -> {
|
UserThread.runAfter(() -> {
|
||||||
amount.set("0.001");
|
amount.set("0.001");
|
||||||
price.set("75000"); // for CNY
|
price.set("0.0001"); // for BSQ
|
||||||
minAmount.set(amount.get());
|
minAmount.set(amount.get());
|
||||||
onFocusOutPriceAsPercentageTextField(true, false);
|
onFocusOutPriceAsPercentageTextField(true, false);
|
||||||
applyMakerFee();
|
applyMakerFee();
|
||||||
|
|
Loading…
Add table
Reference in a new issue