mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -04:00
Replace VerifyOffer class with Offer#validate method
This commit is contained in:
parent
b3670c5201
commit
7fffa81f02
@ -19,6 +19,7 @@ package io.bitsquare.offer;
|
||||
|
||||
import io.bitsquare.arbitrator.Arbitrator;
|
||||
import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.btc.Restrictions;
|
||||
import io.bitsquare.locale.Country;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
@ -34,6 +35,9 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static io.bitsquare.btc.Restrictions.MIN_TRADE_AMOUNT;
|
||||
|
||||
//TODO flatten down?
|
||||
|
||||
public class Offer implements Serializable {
|
||||
@ -194,6 +198,37 @@ public class Offer implements Serializable {
|
||||
return bankAccountUID;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void validate() throws Exception {
|
||||
checkNotNull(getAcceptedCountries(), "AcceptedCountries is null");
|
||||
checkNotNull(getAcceptedLanguageLocales(), "AcceptedLanguageLocales is null");
|
||||
checkNotNull(getAmount(), "Amount is null");
|
||||
checkNotNull(getArbitrators(), "Arbitrator is null");
|
||||
checkNotNull(getBankAccountId(), "BankAccountId is null");
|
||||
checkNotNull(getSecurityDeposit(), "SecurityDeposit is null");
|
||||
checkNotNull(getCreationDate(), "CreationDate is null");
|
||||
checkNotNull(getCurrency(), "Currency is null");
|
||||
checkNotNull(getDirection(), "Direction is null");
|
||||
checkNotNull(getId(), "Id is null");
|
||||
checkNotNull(getMessagePublicKey(), "MessagePublicKey is null");
|
||||
checkNotNull(getMinAmount(), "MinAmount is null");
|
||||
checkNotNull(getPrice(), "Price is null");
|
||||
|
||||
checkArgument(getMinAmount().compareTo(MIN_TRADE_AMOUNT) >= 0, "MinAmount is less then " + MIN_TRADE_AMOUNT);
|
||||
checkArgument(getAmount().compareTo(MIN_TRADE_AMOUNT) >= 0, "Amount is less then " + MIN_TRADE_AMOUNT);
|
||||
checkArgument(getAmount().compareTo(getMinAmount()) >= 0, "MinAmount is larger then Amount");
|
||||
checkArgument(getSecurityDeposit().isPositive(), "SecurityDeposit is not positive");
|
||||
checkArgument(getPrice().isPositive(), "Price is 0 or negative");
|
||||
|
||||
// TODO check balance
|
||||
// securityDeposit
|
||||
// Coin totalsToFund
|
||||
// getAddressInfoByTradeID(offerId)
|
||||
// TODO when offer is flattened continue here...
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -215,9 +250,4 @@ public class Offer implements Serializable {
|
||||
", arbitrator=" + arbitrators +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,10 @@ import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.offer.OfferRepository;
|
||||
import io.bitsquare.persistence.Persistence;
|
||||
import io.bitsquare.util.task.FaultHandler;
|
||||
import io.bitsquare.trade.handlers.TransactionResultHandler;
|
||||
import io.bitsquare.trade.protocol.createoffer.tasks.BroadCastOfferFeeTx;
|
||||
import io.bitsquare.trade.protocol.createoffer.tasks.CreateOfferFeeTx;
|
||||
import io.bitsquare.trade.protocol.createoffer.tasks.VerifyOffer;
|
||||
import io.bitsquare.util.task.FaultHandler;
|
||||
|
||||
import org.bitcoinj.core.Transaction;
|
||||
|
||||
@ -115,11 +114,15 @@ public class CreateOfferCoordinator {
|
||||
|
||||
public void start() {
|
||||
model.setState(State.STARTED);
|
||||
VerifyOffer.run(this::onOfferValidated, faultHandler, offer);
|
||||
}
|
||||
|
||||
private void onOfferValidated() {
|
||||
model.setState(State.VALIDATED);
|
||||
try {
|
||||
offer.validate();
|
||||
model.setState(State.VALIDATED);
|
||||
} catch (Exception ex) {
|
||||
faultHandler.handleFault("Offer validation failed", ex);
|
||||
return;
|
||||
}
|
||||
|
||||
CreateOfferFeeTx.run(this::onOfferFeeTxCreated, faultHandler, walletFacade, offer.getId());
|
||||
}
|
||||
|
||||
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare 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.
|
||||
*
|
||||
* Bitsquare 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 Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.trade.protocol.createoffer.tasks;
|
||||
|
||||
import io.bitsquare.btc.Restrictions;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.util.task.FaultHandler;
|
||||
import io.bitsquare.util.task.ResultHandler;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
@Immutable
|
||||
public class VerifyOffer {
|
||||
private static final Logger log = LoggerFactory.getLogger(VerifyOffer.class);
|
||||
|
||||
public static void run(ResultHandler resultHandler, FaultHandler faultHandler, Offer offer) {
|
||||
try {
|
||||
checkNotNull(offer.getAcceptedCountries(), "AcceptedCountries is null");
|
||||
checkNotNull(offer.getAcceptedLanguageLocales(), "AcceptedLanguageLocales is null");
|
||||
checkNotNull(offer.getAmount(), "Amount is null");
|
||||
checkNotNull(offer.getArbitrators(), "Arbitrator is null");
|
||||
//checkNotNull(offer.getBankAccountCountry(), "BankAccountCountry is null");
|
||||
checkNotNull(offer.getBankAccountId(), "BankAccountId is null");
|
||||
checkNotNull(offer.getSecurityDeposit(), "SecurityDeposit is null");
|
||||
checkNotNull(offer.getCreationDate(), "CreationDate is null");
|
||||
checkNotNull(offer.getCurrency(), "Currency is null");
|
||||
checkNotNull(offer.getDirection(), "Direction is null");
|
||||
checkNotNull(offer.getId(), "Id is null");
|
||||
checkNotNull(offer.getMessagePublicKey(), "MessagePublicKey is null");
|
||||
checkNotNull(offer.getMinAmount(), "MinAmount is null");
|
||||
checkNotNull(offer.getPrice(), "Price is null");
|
||||
|
||||
//checkArgument(!offer.getAcceptedCountries().isEmpty(), "AcceptedCountries is empty");
|
||||
//checkArgument(!offer.getAcceptedLanguageLocales().isEmpty(), "AcceptedLanguageLocales is empty");
|
||||
checkArgument(offer.getMinAmount().compareTo(Restrictions.MIN_TRADE_AMOUNT) >= 0,
|
||||
"MinAmount is less then " + Restrictions.MIN_TRADE_AMOUNT);
|
||||
checkArgument(offer.getAmount().compareTo(Restrictions.MIN_TRADE_AMOUNT) >= 0,
|
||||
"Amount is less then " + Restrictions.MIN_TRADE_AMOUNT);
|
||||
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger then Amount");
|
||||
checkArgument(offer.getSecurityDeposit().isPositive(), "SecurityDeposit is not positive");
|
||||
checkArgument(offer.getPrice().isPositive(), "Price is 0 or negative");
|
||||
|
||||
// TODO check balance
|
||||
// securityDeposit
|
||||
// Coin totalsToFund
|
||||
// getAddressInfoByTradeID(offerId)
|
||||
// TODO when offer is flattened continue here...
|
||||
|
||||
resultHandler.handleResult();
|
||||
} catch (Throwable t) {
|
||||
faultHandler.handleFault("Offer validation failed.", t);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user