mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-19 05:44:05 +01:00
Add CheckRestrictions task
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
48b8eb6231
commit
4b48ce079b
@ -78,6 +78,10 @@ public class Restrictions {
|
||||
return 0.15; // 15% of trade amount.
|
||||
}
|
||||
|
||||
public static double getMinSellerSecurityDepositAsPercent() {
|
||||
return 0.15; // 15% of trade amount.
|
||||
}
|
||||
|
||||
public static Coin getMinSellerSecurityDepositAsCoin() {
|
||||
if (SELLER_SECURITY_DEPOSIT == null)
|
||||
SELLER_SECURITY_DEPOSIT = Coin.parseCoin("0.001"); // 0.001 BTC is 60 USD @ 60000 USD/BTC
|
||||
|
@ -26,6 +26,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest;
|
||||
import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckRestrictions;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest;
|
||||
@ -75,6 +76,7 @@ public class BuyerAsMakerProtocol extends BuyerProtocol implements MakerProtocol
|
||||
CheckIfDaoStateIsInSync.class,
|
||||
MakerProcessesInputsForDepositTxRequest.class,
|
||||
ApplyFilter.class,
|
||||
CheckRestrictions.class,
|
||||
getVerifyPeersFeePaymentClass(),
|
||||
MakerSetsLockTime.class,
|
||||
MakerCreateAndSignContract.class,
|
||||
|
@ -28,6 +28,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxResponse;
|
||||
import bisq.core.trade.protocol.bisq_v1.messages.PayoutTxPublishedMessage;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckRestrictions;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerFinalizesDelayedPayoutTx;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.buyer.BuyerProcessDelayedPayoutTxSignatureRequest;
|
||||
@ -80,6 +81,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
||||
.setup(tasks(
|
||||
CheckIfDaoStateIsInSync.class,
|
||||
ApplyFilter.class,
|
||||
CheckRestrictions.class,
|
||||
getVerifyPeersFeePaymentClass(),
|
||||
CreateTakerFeeTx.class,
|
||||
BuyerAsTakerCreatesDepositTxInputs.class,
|
||||
|
@ -28,6 +28,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.DepositTxMessage;
|
||||
import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxRequest;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckRestrictions;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerCreateAndSignContract;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.maker.MakerProcessesInputsForDepositTxRequest;
|
||||
@ -78,6 +79,7 @@ public class SellerAsMakerProtocol extends SellerProtocol implements MakerProtoc
|
||||
MaybeCreateSubAccount.class,
|
||||
MakerProcessesInputsForDepositTxRequest.class,
|
||||
ApplyFilter.class,
|
||||
CheckRestrictions.class,
|
||||
getVerifyPeersFeePaymentClass(),
|
||||
MakerSetsLockTime.class,
|
||||
MakerCreateAndSignContract.class,
|
||||
|
@ -27,6 +27,7 @@ import bisq.core.trade.protocol.bisq_v1.messages.DelayedPayoutTxSignatureRespons
|
||||
import bisq.core.trade.protocol.bisq_v1.messages.InputsForDepositTxResponse;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.ApplyFilter;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckIfDaoStateIsInSync;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.CheckRestrictions;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.TradeTask;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.seller.MaybeCreateSubAccount;
|
||||
import bisq.core.trade.protocol.bisq_v1.tasks.seller.SellerCreatesDelayedPayoutTx;
|
||||
@ -77,6 +78,7 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
||||
CheckIfDaoStateIsInSync.class,
|
||||
MaybeCreateSubAccount.class,
|
||||
ApplyFilter.class,
|
||||
CheckRestrictions.class,
|
||||
getVerifyPeersFeePaymentClass(),
|
||||
CreateTakerFeeTx.class,
|
||||
SellerAsTakerCreatesDepositTxInputs.class,
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.trade.protocol.bisq_v1.tasks;
|
||||
|
||||
import bisq.core.btc.wallet.Restrictions;
|
||||
import bisq.core.trade.model.bisq_v1.Trade;
|
||||
import bisq.core.util.coin.CoinUtil;
|
||||
|
||||
import bisq.common.taskrunner.TaskRunner;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
@Slf4j
|
||||
public class CheckRestrictions extends TradeTask {
|
||||
public CheckRestrictions(TaskRunner<Trade> taskHandler, Trade trade) {
|
||||
super(taskHandler, trade);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run() {
|
||||
try {
|
||||
runInterceptHook();
|
||||
|
||||
Coin amount = trade.getAmount();
|
||||
|
||||
Coin buyerSecurityDeposit = trade.getOffer().getBuyerSecurityDeposit();
|
||||
Coin minBuyerSecurityDeposit = Restrictions.getMinBuyerSecurityDepositAsCoin();
|
||||
checkArgument(buyerSecurityDeposit.getValue() >= minBuyerSecurityDeposit.getValue(),
|
||||
"Buyer security deposit is less then the min. buyer security deposit (as coin)");
|
||||
|
||||
double minBuyerSecurityDepositAsPercent = Restrictions.getMinBuyerSecurityDepositAsPercent();
|
||||
Coin minBuyerSecurityDepositFromPercentage = CoinUtil.getPercentOfAmountAsCoin(minBuyerSecurityDepositAsPercent, amount);
|
||||
checkArgument(buyerSecurityDeposit.getValue() >= minBuyerSecurityDepositFromPercentage.getValue(),
|
||||
"Buyer security deposit is less then the min. buyer security deposit (as percentage)");
|
||||
|
||||
Coin sellerSecurityDeposit = trade.getOffer().getSellerSecurityDeposit();
|
||||
Coin minSellerSecurityDeposit = Restrictions.getMinSellerSecurityDepositAsCoin();
|
||||
checkArgument(sellerSecurityDeposit.getValue() >= minSellerSecurityDeposit.getValue(),
|
||||
"Seller security deposit is less then the min. seller security deposit (as coin)");
|
||||
|
||||
double minSellerSecurityDepositAsPercent = Restrictions.getMinSellerSecurityDepositAsPercent();
|
||||
Coin minSellerSecurityDepositFromPercentage = CoinUtil.getPercentOfAmountAsCoin(minSellerSecurityDepositAsPercent, amount);
|
||||
checkArgument(sellerSecurityDeposit.getValue() >= minSellerSecurityDepositFromPercentage.getValue(),
|
||||
"Seller security deposit is less then the min. seller security deposit (as percentage)");
|
||||
|
||||
complete();
|
||||
} catch (Throwable t) {
|
||||
failed(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user