-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check for account age to apply restrictions #2801
Merged
ripcurlx
merged 15 commits into
bisq-network:master
from
ManfredKarrer:restrict-new-accounts
May 3, 2019
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8ab348c
Add check for account age to apply restrictions
ManfredKarrer 6d6e869
Revert changes with filtering not mature accounts
ManfredKarrer 4947352
Update text
ManfredKarrer c74025b
Remove check for makerHasNoMatureAccountForBuyOffer
ManfredKarrer 8e0ec54
Refactor restriction handling
ManfredKarrer 9df5437
Fix verify task
ManfredKarrer 08cf993
Add amount limit to take offer view
ManfredKarrer e51844a
Improve dispute handling of failed trades
ManfredKarrer e0cf683
Update text
ManfredKarrer c4e30e5
Fix limitations
ManfredKarrer 3b613be
Improve handling of filter
ManfredKarrer 830e693
Refactoring: Rename CheckIfPeerIsBanned to ApplyFilter
ManfredKarrer 8f56f4a
Refactoring: Extract variable
ManfredKarrer 8735892
Add null check
ManfredKarrer 364f666
Only show information popup when actual amount was set
ripcurlx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.offer; | ||
|
||
import bisq.core.payment.payload.PaymentMethod; | ||
import bisq.core.trade.Trade; | ||
|
||
import org.bitcoinj.core.Coin; | ||
|
||
public class OfferRestrictions { | ||
public static Coin TOLERATED_SMALL_TRADE_AMOUNT = Coin.parseCoin("0.01"); | ||
|
||
public static boolean isOfferRisky(Offer offer) { | ||
return offer != null && | ||
offer.isBuyOffer() && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
isMinTradeAmountRisky(offer); | ||
} | ||
|
||
public static boolean isSellOfferRisky(Offer offer) { | ||
return offer != null && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
isMinTradeAmountRisky(offer); | ||
} | ||
|
||
public static boolean isTradeRisky(Trade trade) { | ||
if (trade == null) | ||
return false; | ||
|
||
Offer offer = trade.getOffer(); | ||
return offer != null && | ||
PaymentMethod.hasChargebackRisk(offer.getPaymentMethod()) && | ||
trade.getTradeAmount() != null && | ||
isAmountRisky(trade.getTradeAmount()); | ||
} | ||
|
||
public static boolean isMinTradeAmountRisky(Offer offer) { | ||
return isAmountRisky(offer.getMinAmount()); | ||
} | ||
|
||
public static boolean isAmountRisky(Coin amount) { | ||
return amount.isGreaterThan(TOLERATED_SMALL_TRADE_AMOUNT); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
core/src/main/java/bisq/core/payment/AccountAgeRestrictions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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.payment; | ||
|
||
import bisq.core.offer.Offer; | ||
import bisq.core.offer.OfferPayload; | ||
import bisq.core.offer.OfferRestrictions; | ||
import bisq.core.payment.payload.PaymentMethod; | ||
import bisq.core.trade.Trade; | ||
|
||
import bisq.common.util.Utilities; | ||
|
||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class AccountAgeRestrictions { | ||
public static final long SAFE_ACCOUNT_AGE_DATE = Utilities.getUTCDate(2019, GregorianCalendar.MARCH, 15).getTime(); | ||
|
||
public static boolean isMakersAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, Offer offer) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getMakersAccountAge(offer, new Date()); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static boolean isTradePeersAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, Trade trade) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getTradingPeersAccountAge(trade); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static boolean isMyAccountAgeImmature(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount myPaymentAccount) { | ||
long accountCreationDate = new Date().getTime() - accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload()); | ||
return accountCreationDate > SAFE_ACCOUNT_AGE_DATE; | ||
} | ||
|
||
public static long getMyTradeLimitAtCreateOffer(AccountAgeWitnessService accountAgeWitnessService, | ||
PaymentAccount paymentAccount, | ||
String currencyCode, | ||
OfferPayload.Direction direction) { | ||
if (direction == OfferPayload.Direction.BUY && | ||
PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) { | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else { | ||
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode); | ||
} | ||
} | ||
|
||
public static long getMyTradeLimitAtTakeOffer(AccountAgeWitnessService accountAgeWitnessService, | ||
PaymentAccount paymentAccount, | ||
Offer offer, | ||
String currencyCode, | ||
OfferPayload.Direction direction) { | ||
if (direction == OfferPayload.Direction.BUY && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMakersAccountAgeImmature(accountAgeWitnessService, offer)) { | ||
// Taker is seller | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else if (direction == OfferPayload.Direction.SELL && PaymentMethod.hasChargebackRisk(paymentAccount.getPaymentMethod()) && | ||
AccountAgeRestrictions.isMyAccountAgeImmature(accountAgeWitnessService, paymentAccount)) { | ||
// Taker is buyer | ||
return OfferRestrictions.TOLERATED_SMALL_TRADE_AMOUNT.value; | ||
} else { | ||
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should re-use the static from AccountAgeRestrictions