Skip to content

Commit

Permalink
Merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosseel committed Sep 28, 2018
1 parent e049478 commit 272910b
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 99 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import bisq.core.alert.PrivateNotificationPayload;
import bisq.core.arbitration.ArbitratorManager;
import bisq.core.arbitration.DisputeManager;
import bisq.core.btc.AddressEntry;
import bisq.core.btc.Balances;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.DaoSetup;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/btc/BalanceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.core.btc;

import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.offer.OpenOffer;
import bisq.core.offer.OpenOfferManager;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/btc/model/BalanceModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void updateBalance() {
}

private void updateAvailableBalance() {
Coin totalAvailableBalance = Coin.valueOf(tradeManager.getAddressEntriesForAvailableBalanceStream()
Coin totalAvailableBalance = Coin.valueOf(tradeManager.getAddressEntriesForAvailableFundsStream()
.mapToLong(addressEntry -> btcWalletService.getBalanceForAddress(addressEntry.getAddress()).getValue())
.sum());
availableBalance.set(totalAvailableBalance);
Expand Down
99 changes: 99 additions & 0 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.filter.FilterManager;
import bisq.core.locale.Country;
import bisq.core.locale.CurrencyUtil;
Expand Down Expand Up @@ -266,4 +267,102 @@ static Coin getAdjustedAmount(Coin amount, Price price, long maxTradeLimit, int
adjustedAmount = Math.min(maxTradeLimit, adjustedAmount);
return Coin.valueOf(adjustedAmount);
}

public static ArrayList<String> getAcceptedCountryCodes(PaymentAccount paymentAccount) {
ArrayList<String> acceptedCountryCodes = null;
if (paymentAccount instanceof SepaAccount) {
acceptedCountryCodes = new ArrayList<>(((SepaAccount) paymentAccount).getAcceptedCountryCodes());
} else if (paymentAccount instanceof SepaInstantAccount) {
acceptedCountryCodes = new ArrayList<>(((SepaInstantAccount) paymentAccount).getAcceptedCountryCodes());
} else if (paymentAccount instanceof CountryBasedPaymentAccount) {
acceptedCountryCodes = new ArrayList<>();
Country country = ((CountryBasedPaymentAccount) paymentAccount).getCountry();
if (country != null)
acceptedCountryCodes.add(country.code);
}
return acceptedCountryCodes;
}

public static ArrayList<String> getAcceptedBanks(PaymentAccount paymentAccount) {
ArrayList<String> acceptedBanks = null;
if (paymentAccount instanceof SpecificBanksAccount) {
acceptedBanks = new ArrayList<>(((SpecificBanksAccount) paymentAccount).getAcceptedBanks());
} else if (paymentAccount instanceof SameBankAccount) {
acceptedBanks = new ArrayList<>();
acceptedBanks.add(((SameBankAccount) paymentAccount).getBankId());
}
return acceptedBanks;
}

public static String getBankId(PaymentAccount paymentAccount) {
return paymentAccount instanceof BankAccount ? ((BankAccount) paymentAccount).getBankId() : null;
}

// That is optional and set to null if not supported (AltCoins, OKPay,...)
public static String getCountryCode(PaymentAccount paymentAccount) {
if (paymentAccount instanceof CountryBasedPaymentAccount) {
Country country = ((CountryBasedPaymentAccount) paymentAccount).getCountry();
return country != null ? country.code : null;
} else {
return null;
}
}

public static long getMaxTradeLimit(AccountAgeWitnessService accountAgeWitnessService, PaymentAccount paymentAccount, String currencyCode) {
if (paymentAccount != null)
return accountAgeWitnessService.getMyTradeLimit(paymentAccount, currencyCode);
else
return 0;
}

public static long getMaxTradePeriod(PaymentAccount paymentAccount) {
return paymentAccount.getPaymentMethod().getMaxTradePeriod();
}

public static Map<String, String> getExtraDataMap(AccountAgeWitnessService accountAgeWitnessService,
ReferralIdService referralIdService,
PaymentAccount paymentAccount,
String currencyCode) {
Map<String, String> extraDataMap = null;
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
extraDataMap = new HashMap<>();
final String myWitnessHashAsHex = accountAgeWitnessService.getMyWitnessHashAsHex(paymentAccount.getPaymentAccountPayload());
extraDataMap.put(OfferPayload.ACCOUNT_AGE_WITNESS_HASH, myWitnessHashAsHex);
}

if (referralIdService.getOptionalReferralId().isPresent()) {
if (extraDataMap == null)
extraDataMap = new HashMap<>();
extraDataMap.put(OfferPayload.REFERRAL_ID, referralIdService.getOptionalReferralId().get());
}

if (paymentAccount instanceof F2FAccount) {
if (extraDataMap == null)
extraDataMap = new HashMap<>();
extraDataMap.put(OfferPayload.F2F_CITY, ((F2FAccount) paymentAccount).getCity());
extraDataMap.put(OfferPayload.F2F_EXTRA_INFO, ((F2FAccount) paymentAccount).getExtraInfo());
}

return extraDataMap;
}

public static void validateOfferData(FilterManager filterManager,
P2PService p2PService,
Coin buyerSecurityDepositAsCoin,
PaymentAccount paymentAccount,
String currencyCode, Coin makerFeeAsCoin) {
checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMaxBuyerSecurityDeposit()) <= 0,
"securityDeposit must be not exceed " +
Restrictions.getMaxBuyerSecurityDeposit().toFriendlyString());
checkArgument(buyerSecurityDepositAsCoin.compareTo(Restrictions.getMinBuyerSecurityDeposit()) >= 0,
"securityDeposit must be not be less than " +
Restrictions.getMinBuyerSecurityDeposit().toFriendlyString());

checkArgument(!filterManager.isCurrencyBanned(currencyCode),
Res.get("offerbook.warning.currencyBanned"));
checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()),
Res.get("offerbook.warning.paymentMethodBanned"));
checkNotNull(makerFeeAsCoin, "makerFee must not be null");
checkNotNull(p2PService.getAddress(), "Address must not be null");
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/offer/TxFeeEstimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

package bisq.core.offer;

import bisq.core.btc.AddressEntry;
import bisq.core.btc.Restrictions;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.btc.wallet.TradeWalletService;
import bisq.core.provider.fee.FeeService;
import bisq.core.user.Preferences;
Expand Down
2 changes: 1 addition & 1 deletion http-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'network.bisq'
version = '-SNAPSHOT'
version = '0.8.0-SNAPSHOT'

sourceCompatibility = 1.10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import bisq.core.app.AppOptionKeys;
import bisq.core.arbitration.Arbitrator;
import bisq.core.arbitration.ArbitratorManager;
import bisq.core.btc.AddressEntry;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.user.User;

import bisq.httpapi.exceptions.NotFoundException;

import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;

Expand All @@ -27,6 +25,7 @@



import bisq.httpapi.exceptions.NotFoundException;
import javax.validation.ValidationException;

public class ArbitratorFacade {
Expand Down
16 changes: 9 additions & 7 deletions http-api/src/main/java/bisq/httpapi/facade/NetworkFacade.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package bisq.httpapi.facade;

import bisq.core.btc.BitcoinNodes;
import bisq.core.btc.wallet.WalletsSetup;
import bisq.core.btc.nodes.BtcNodes;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.user.Preferences;

import bisq.httpapi.model.BitcoinNetworkStatus;
import bisq.httpapi.model.P2PNetworkConnection;
import bisq.httpapi.model.P2PNetworkStatus;

import bisq.network.p2p.NodeAddress;
import bisq.network.p2p.P2PService;
import bisq.network.p2p.network.Statistic;
Expand All @@ -20,6 +16,12 @@
import java.util.List;
import java.util.stream.Collectors;



import bisq.httpapi.model.BitcoinNetworkStatus;
import bisq.httpapi.model.P2PNetworkConnection;
import bisq.httpapi.model.P2PNetworkStatus;

public class NetworkFacade {

private final P2PService p2PService;
Expand Down Expand Up @@ -56,7 +58,7 @@ public BitcoinNetworkStatus getBitcoinNetworkStatus() {
else
networkStatus.peers = Collections.emptyList();
networkStatus.useTorForBitcoinJ = preferences.getUseTorForBitcoinJ();
networkStatus.bitcoinNodesOption = BitcoinNodes.BitcoinNodesOption.values()[preferences.getBitcoinNodesOptionOrdinal()];
networkStatus.bitcoinNodesOption = BtcNodes.BitcoinNodesOption.values()[preferences.getBitcoinNodesOptionOrdinal()];
networkStatus.bitcoinNodes = preferences.getBitcoinNodes();
return networkStatus;
}
Expand Down
27 changes: 13 additions & 14 deletions http-api/src/main/java/bisq/httpapi/facade/OfferFacade.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bisq.httpapi.facade;

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.Restrictions;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.Restrictions;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferBookService;
import bisq.core.offer.OfferPayload;
Expand All @@ -18,19 +18,6 @@
import bisq.core.user.User;
import bisq.core.util.CoinUtil;

import bisq.httpapi.exceptions.AmountTooHighException;
import bisq.httpapi.exceptions.IncompatiblePaymentAccountException;
import bisq.httpapi.exceptions.InsufficientMoneyException;
import bisq.httpapi.exceptions.NotBootstrappedException;
import bisq.httpapi.exceptions.NotFoundException;
import bisq.httpapi.exceptions.OfferTakerSameAsMakerException;
import bisq.httpapi.exceptions.PaymentAccountNotFoundException;
import bisq.httpapi.model.InputDataForOffer;
import bisq.httpapi.model.OfferDetail;
import bisq.httpapi.model.PriceType;
import bisq.httpapi.service.endpoint.OfferBuilder;
import bisq.httpapi.util.ResourceHelper;

import bisq.network.p2p.P2PService;

import bisq.common.UserThread;
Expand All @@ -51,6 +38,18 @@



import bisq.httpapi.exceptions.AmountTooHighException;
import bisq.httpapi.exceptions.IncompatiblePaymentAccountException;
import bisq.httpapi.exceptions.InsufficientMoneyException;
import bisq.httpapi.exceptions.NotBootstrappedException;
import bisq.httpapi.exceptions.NotFoundException;
import bisq.httpapi.exceptions.OfferTakerSameAsMakerException;
import bisq.httpapi.exceptions.PaymentAccountNotFoundException;
import bisq.httpapi.model.InputDataForOffer;
import bisq.httpapi.model.OfferDetail;
import bisq.httpapi.model.PriceType;
import bisq.httpapi.service.endpoint.OfferBuilder;
import bisq.httpapi.util.ResourceHelper;
import javax.validation.ValidationException;

public class OfferFacade {
Expand Down
5 changes: 2 additions & 3 deletions http-api/src/main/java/bisq/httpapi/facade/TradeFacade.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bisq.httpapi.facade;

import bisq.core.btc.AddressEntry;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.trade.BuyerAsMakerTrade;
import bisq.core.trade.SellerAsMakerTrade;
Expand All @@ -12,8 +12,6 @@
import bisq.core.trade.protocol.SellerAsTakerProtocol;
import bisq.core.trade.protocol.TradeProtocol;

import bisq.httpapi.exceptions.NotFoundException;

import bisq.common.handlers.ErrorMessageHandler;
import bisq.common.handlers.ResultHandler;

Expand All @@ -30,6 +28,7 @@



import bisq.httpapi.exceptions.NotFoundException;
import javax.validation.ValidationException;

public class TradeFacade {
Expand Down
45 changes: 14 additions & 31 deletions http-api/src/main/java/bisq/httpapi/facade/WalletFacade.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
package bisq.httpapi.facade;

import bisq.common.storage.FileUtil;
import bisq.common.storage.Storage;
import bisq.common.util.Tuple2;
import bisq.core.app.BisqEnvironment;
import bisq.core.btc.AddressEntry;
import bisq.core.btc.AddressEntryException;
import bisq.core.btc.BalanceUtil;
import bisq.core.btc.InsufficientFundsException;
import bisq.core.btc.exceptions.AddressEntryException;
import bisq.core.btc.exceptions.InsufficientFundsException;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletService;
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.btc.wallet.WalletsSetup;
import bisq.core.locale.Res;
import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager;
import bisq.core.util.validation.BtcAddressValidator;

import bisq.httpapi.exceptions.AmountTooLowException;
import bisq.httpapi.exceptions.UnauthorizedException;
import bisq.httpapi.model.SeedWords;
import bisq.httpapi.model.WalletAddress;
import bisq.httpapi.model.WalletAddressList;
import bisq.httpapi.model.WalletTransaction;
import bisq.httpapi.model.WalletTransactionList;

import bisq.common.storage.FileUtil;
import bisq.common.storage.Storage;
import bisq.common.util.Tuple2;

import bisq.httpapi.model.*;
import com.google.common.util.concurrent.FutureCallback;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.KeyCrypterScrypt;
import org.bitcoinj.wallet.DeterministicSeed;
import org.bitcoinj.wallet.Wallet;
import org.jetbrains.annotations.NotNull;
import org.spongycastle.crypto.params.KeyParameter;

import javax.inject.Inject;
import javax.inject.Named;

import com.google.common.util.concurrent.FutureCallback;

import org.spongycastle.crypto.params.KeyParameter;

import javax.validation.ValidationException;
import java.io.File;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZoneOffset;

import java.io.File;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand All @@ -57,18 +48,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;

import static bisq.httpapi.facade.FacadeUtil.failFuture;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.stream.Collectors.toList;



import javax.validation.ValidationException;

@Slf4j
public class WalletFacade {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bisq.httpapi.model;

import bisq.core.btc.BitcoinNodes;
import bisq.core.btc.nodes.BtcNodes;

import java.util.List;

public class BitcoinNetworkStatus {

public BitcoinNodes.BitcoinNodesOption bitcoinNodesOption;
public BtcNodes.BitcoinNodesOption bitcoinNodesOption;

public String bitcoinNodes;

Expand Down
Loading

0 comments on commit 272910b

Please sign in to comment.