diff --git a/design/navIcons.psd b/design/navIcons.psd index 5448deedf5..f656b9e888 100644 Binary files a/design/navIcons.psd and b/design/navIcons.psd differ diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 9f6419d7aa..47391d6af0 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -1,22 +1,19 @@ package io.bitsquare; -import com.google.bitcoin.core.ECKey; -import com.google.bitcoin.core.Utils; import com.google.inject.Guice; import com.google.inject.Injector; -import io.bitsquare.bank.BankAccount; -import io.bitsquare.bank.BankAccountType; import io.bitsquare.btc.WalletFacade; import io.bitsquare.di.BitSquareModule; import io.bitsquare.di.GuiceFXMLLoader; -import io.bitsquare.gui.util.Localisation; +import io.bitsquare.locale.LanguageUtil; +import io.bitsquare.locale.Localisation; import io.bitsquare.msg.MessageFacade; import io.bitsquare.settings.Settings; import io.bitsquare.storage.Storage; import io.bitsquare.user.Arbitrator; +import io.bitsquare.user.Reputation; import io.bitsquare.user.User; import io.bitsquare.util.DSAKeyUtil; -import io.bitsquare.util.MockData; import javafx.application.Application; import javafx.scene.Parent; import javafx.scene.Scene; @@ -24,15 +21,16 @@ import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.PublicKey; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; public class BitSquare extends Application { private static final Logger log = LoggerFactory.getLogger(BitSquare.class); public static String ID = "bitsquare"; + private static Stage stage; private WalletFacade walletFacade; private MessageFacade messageFacade; @@ -48,6 +46,7 @@ public class BitSquare extends Application @Override public void start(Stage stage) throws Exception { + BitSquare.stage = stage; log.debug("Startup: start"); final Injector injector = Guice.createInjector(new BitSquareModule()); walletFacade = injector.getInstance(WalletFacade.class); @@ -62,7 +61,8 @@ public class BitSquare extends Application user.updateFromStorage((User) storage.read(user.getClass().getName())); // mock - initSettings(settings, storage, user); + //initSettings(settings, storage, user); + settings.updateFromStorage((Settings) storage.read(settings.getClass().getName())); @@ -89,6 +89,46 @@ public class BitSquare extends Application stage.show(); log.debug("Startup: stage displayed"); + + addMockArbitrator(); + } + + private void addMockArbitrator() + { + String pubKeyAsHex = walletFacade.getArbitratorPubKeyAsHex(); + String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey()); + List languages = new ArrayList<>(); + languages.add(LanguageUtil.getDefaultLanguageLocale()); + List arbitrationMethods = new ArrayList<>(); + arbitrationMethods.add(Arbitrator.METHODS.TLS_NOTARY); + List idVerifications = new ArrayList<>(); + idVerifications.add(Arbitrator.ID_VERIFICATIONS.PASSPORT); + idVerifications.add(Arbitrator.ID_VERIFICATIONS.GOV_ID); + + Arbitrator arbitrator = new Arbitrator(pubKeyAsHex, + messagePubKeyAsHex, + "Manfred Karrer", + Arbitrator.ID_TYPE.REAL_LIFE_ID, + languages, + new Reputation(), + 1, + 0.01, + 0.001, + 10, + 0.1, + arbitrationMethods, + idVerifications, + "http://bitsquare.io/", + "Bla bla..." + ); + + try + { + messageFacade.addArbitrator(arbitrator); + } catch (IOException e) + { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } } @Override @@ -100,24 +140,29 @@ public class BitSquare extends Application super.stop(); } - private void initSettings(Settings settings, Storage storage, User user) + public static Stage getStage() + { + return stage; + } + + /* private void initSettings(Settings settings, Storage storage, User user) { Settings savedSettings = (Settings) storage.read(settings.getClass().getName()); if (savedSettings == null) { // write default settings - settings.getAcceptedCountryLocales().clear(); + settings.getAcceptedCountries().clear(); // settings.addAcceptedLanguageLocale(Locale.getDefault()); settings.addAcceptedLanguageLocale(MockData.getLocales().get(0)); settings.addAcceptedLanguageLocale(new Locale("en", "US")); settings.addAcceptedLanguageLocale(new Locale("es", "ES")); - settings.getAcceptedCountryLocales().clear(); - //settings.addAcceptedCountryLocale(Locale.getDefault()); - settings.addAcceptedCountryLocale(MockData.getLocales().get(0)); - settings.addAcceptedCountryLocale(new Locale("en", "US")); - settings.addAcceptedCountryLocale(new Locale("de", "DE")); - settings.addAcceptedCountryLocale(new Locale("es", "ES")); + settings.getAcceptedCountries().clear(); + //settings.addAcceptedCountry(Locale.getDefault()); + settings.addAcceptedCountry(MockData.getLocales().get(0)); + settings.addAcceptedCountry(new Locale("en", "US")); + settings.addAcceptedCountry(new Locale("de", "DE")); + settings.addAcceptedCountry(new Locale("es", "ES")); settings.getAcceptedArbitrators().clear(); @@ -137,9 +182,9 @@ public class BitSquare extends Application //initMockUser(storage, user); } - } + } */ - private String getMessagePubKey() + /* private String getMessagePubKey() { try { @@ -152,10 +197,10 @@ public class BitSquare extends Application { return null; } - } + } */ - private void initMockUser(Storage storage, User user) + /* private void initMockUser(Storage storage, User user) { user.getBankAccounts().clear(); @@ -182,5 +227,5 @@ public class BitSquare extends Application user.setAccountID(Utils.bytesToHexString(new ECKey().getPubKey())); storage.write(user.getClass().getName(), user); - } + } */ } diff --git a/src/main/java/io/bitsquare/bank/BankAccount.java b/src/main/java/io/bitsquare/bank/BankAccount.java index bf31ac626b..e6d2dc6e42 100644 --- a/src/main/java/io/bitsquare/bank/BankAccount.java +++ b/src/main/java/io/bitsquare/bank/BankAccount.java @@ -1,42 +1,60 @@ package io.bitsquare.bank; +import io.bitsquare.locale.Country; + import java.io.Serializable; import java.util.Currency; -import java.util.Locale; +import java.util.Objects; public class BankAccount implements Serializable { private static final long serialVersionUID = 1792577576443221268L; - private BankAccountType bankAccountType; + private BankAccountTypeInfo bankAccountTypeInfo; private String accountPrimaryID; private String accountSecondaryID; private String accountHolderName; - private Locale countryLocale; + private Country country; private Currency currency; private String uid; private String accountTitle; - public BankAccount(BankAccountType bankAccountType, + public BankAccount(BankAccountTypeInfo bankAccountTypeInfo, Currency currency, - Locale countryLocale, + Country country, String accountTitle, String accountHolderName, String accountPrimaryID, String accountSecondaryID) { - this.bankAccountType = bankAccountType; + this.bankAccountTypeInfo = bankAccountTypeInfo; this.currency = currency; - this.countryLocale = countryLocale; + this.country = country; this.accountTitle = accountTitle; this.accountHolderName = accountHolderName; this.accountPrimaryID = accountPrimaryID; this.accountSecondaryID = accountSecondaryID; - uid = bankAccountType + "_" + accountPrimaryID + "_" + accountSecondaryID + "_" + accountHolderName + "_" + countryLocale.getCountry(); + uid = accountTitle; + } + + public int hashCode() + { + return Objects.hashCode(uid); + } + + public boolean equals(Object obj) + { + if (!(obj instanceof BankAccount)) + return false; + if (obj == this) + return true; + + BankAccount other = (BankAccount) obj; + return other.getUid().equals(uid); } public String getAccountPrimaryID() @@ -54,9 +72,9 @@ public class BankAccount implements Serializable return accountHolderName; } - public BankAccountType getBankAccountType() + public BankAccountTypeInfo getBankAccountTypeInfo() { - return bankAccountType; + return bankAccountTypeInfo; } public Currency getCurrency() @@ -64,9 +82,9 @@ public class BankAccount implements Serializable return currency; } - public Locale getCountryLocale() + public Country getCountry() { - return countryLocale; + return country; } public String getUid() @@ -83,11 +101,11 @@ public class BankAccount implements Serializable public String toString() { return "BankAccount{" + - "bankAccountType=" + bankAccountType + + "bankAccountType=" + bankAccountTypeInfo.getType() + ", accountPrimaryID='" + accountPrimaryID + '\'' + ", accountSecondaryID='" + accountSecondaryID + '\'' + ", accountHolderName='" + accountHolderName + '\'' + - ", countryLocale=" + countryLocale + + ", countryLocale=" + country + ", currency=" + currency + ", uid='" + uid + '\'' + ", accountTitle='" + accountTitle + '\'' + diff --git a/src/main/java/io/bitsquare/bank/BankAccountType.java b/src/main/java/io/bitsquare/bank/BankAccountType.java deleted file mode 100644 index 0f9c57d926..0000000000 --- a/src/main/java/io/bitsquare/bank/BankAccountType.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.bitsquare.bank; - -import java.io.Serializable; - -public class BankAccountType implements Serializable -{ - - private static final long serialVersionUID = -8772708150197835288L; - - public static enum BankAccountTypeEnum - { - SEPA, WIRE, INTERNATIONAL, OK_PAY, NET_TELLER, PERFECT_MONEY, OTHER - } - - private BankAccountTypeEnum type; - private String primaryIDName; - private String secondaryIDName; - - public BankAccountType(BankAccountTypeEnum type, String primaryIDName, String secondaryIDName) - { - this.type = type; - this.primaryIDName = primaryIDName; - this.secondaryIDName = secondaryIDName; - } - - public BankAccountTypeEnum getType() - { - return type; - } - - public String getPrimaryIDName() - { - return primaryIDName; - } - - public String getSecondaryIDName() - { - return secondaryIDName; - } - - @Override - public String toString() - { - //TODO localisation - return type.toString(); - } - -} diff --git a/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java b/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java new file mode 100644 index 0000000000..0e6ca836b2 --- /dev/null +++ b/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java @@ -0,0 +1,71 @@ +package io.bitsquare.bank; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Objects; + +public class BankAccountTypeInfo implements Serializable +{ + + private static final long serialVersionUID = -8772708150197835288L; + + public static enum BankAccountType + { + SEPA, WIRE, INTERNATIONAL, OK_PAY, NET_TELLER, PERFECT_MONEY, OTHER + } + + public static ArrayList getAllBankAccountTypeInfoObjects() + { + ArrayList bankTransferTypes = new ArrayList<>(); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.SEPA, "IBAN", "BIC")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.WIRE, "Prim_todo", "Sec_todo")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.INTERNATIONAL, "Prim_todo", "Sec_todo")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.OK_PAY, "Prim_todo", "Sec_todo")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.NET_TELLER, "Prim_todo", "Sec_todo")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.PERFECT_MONEY, "Prim_todo", "Sec_todo")); + bankTransferTypes.add(new BankAccountTypeInfo(BankAccountType.OTHER, "Prim_todo", "Sec_todo")); + return bankTransferTypes; + } + + private BankAccountType type; + private String primaryIDName; + private String secondaryIDName; + + public BankAccountTypeInfo(BankAccountType type, String primaryIDName, String secondaryIDName) + { + this.type = type; + this.primaryIDName = primaryIDName; + this.secondaryIDName = secondaryIDName; + } + + public int hashCode() + { + return Objects.hashCode(type); + } + + public boolean equals(Object obj) + { + if (!(obj instanceof BankAccountTypeInfo)) + return false; + if (obj == this) + return true; + + BankAccountTypeInfo other = (BankAccountTypeInfo) obj; + return other.getType().equals(type); + } + + public BankAccountType getType() + { + return type; + } + + public String getPrimaryIDName() + { + return primaryIDName; + } + + public String getSecondaryIDName() + { + return secondaryIDName; + } +} diff --git a/src/main/java/io/bitsquare/btc/BalanceListener.java b/src/main/java/io/bitsquare/btc/BalanceListener.java new file mode 100644 index 0000000000..12986a21c3 --- /dev/null +++ b/src/main/java/io/bitsquare/btc/BalanceListener.java @@ -0,0 +1,27 @@ +package io.bitsquare.btc; + +import com.google.bitcoin.core.Address; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigInteger; + +public class BalanceListener +{ + private static final Logger log = LoggerFactory.getLogger(BalanceListener.class); + private Address address; + + public BalanceListener(Address address) + { + this.address = address; + } + + public Address getAddress() + { + return address; + } + + public void onBalanceChanged(BigInteger balance) + { + } +} \ No newline at end of file diff --git a/src/main/java/io/bitsquare/btc/BtcFormatter.java b/src/main/java/io/bitsquare/btc/BtcFormatter.java index d395eb62e2..2d4c80a09c 100644 --- a/src/main/java/io/bitsquare/btc/BtcFormatter.java +++ b/src/main/java/io/bitsquare/btc/BtcFormatter.java @@ -1,8 +1,8 @@ package io.bitsquare.btc; import com.google.bitcoin.core.Utils; -import io.bitsquare.gui.util.Converter; -import io.bitsquare.gui.util.Formatter; +import io.bitsquare.gui.util.BitSquareConverter; +import io.bitsquare.gui.util.BitSquareFormatter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,7 +25,7 @@ public class BtcFormatter public static BigInteger stringValueToSatoshis(String value) { - return Utils.toNanoCoins(String.valueOf(Converter.stringToDouble(value))); + return Utils.toNanoCoins(String.valueOf(BitSquareConverter.stringToDouble2(value))); } public static BigInteger doubleValueToSatoshis(double value) @@ -48,8 +48,8 @@ public class BtcFormatter public static String formatSatoshis(BigInteger satoshis, boolean useBTC) { if (useBTC) - return Formatter.formatDouble(satoshiToBTC(satoshis), 8) + " BTC"; + return BitSquareFormatter.formatDouble(satoshiToBTC(satoshis), 8) + " BTC"; else - return Formatter.formatDouble(satoshiToBTC(satoshis), 8); + return BitSquareFormatter.formatDouble(satoshiToBTC(satoshis), 8); } } diff --git a/src/main/java/io/bitsquare/btc/ConfidenceListener.java b/src/main/java/io/bitsquare/btc/ConfidenceListener.java new file mode 100644 index 0000000000..10b67da046 --- /dev/null +++ b/src/main/java/io/bitsquare/btc/ConfidenceListener.java @@ -0,0 +1,28 @@ +package io.bitsquare.btc; + +import com.google.bitcoin.core.Address; +import com.google.bitcoin.core.TransactionConfidence; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfidenceListener +{ + private static final Logger log = LoggerFactory.getLogger(ConfidenceListener.class); + private Address address; + + public ConfidenceListener(Address address) + { + + this.address = address; + } + + public Address getAddress() + { + return address; + } + + public void onTransactionConfidenceChanged(TransactionConfidence confidence) + { + + } +} \ No newline at end of file diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index 273f1dbcef..1d57dfe193 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -7,6 +7,7 @@ import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.RegTestParams; import com.google.bitcoin.script.Script; import com.google.bitcoin.script.ScriptBuilder; +import com.google.bitcoin.script.ScriptOpCodes; import com.google.bitcoin.utils.Threading; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.FutureCallback; @@ -21,9 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.ExecutionException; import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN; @@ -45,8 +44,10 @@ public class WalletFacade private List downloadListeners = new ArrayList<>(); private Wallet wallet; - private ECKey registrationKey; - private ECKey tradingKey; + private ECKey arbitratorKey; + private WalletEventListener walletEventListener; + private List confidenceListeners = new ArrayList<>(); + private List balanceListeners = new ArrayList<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -100,9 +101,6 @@ public class WalletFacade wallet = walletAppKit.wallet(); - registrationKey = wallet.getKeys().get(0); - tradingKey = new ECKey(); - wallet.addKey(tradingKey); wallet.allowSpendingUnconfirmedTransactions(); //walletAppKit.peerGroup().setMaxConnections(11); @@ -111,6 +109,49 @@ public class WalletFacade walletAppKit.peerGroup().setMinBroadcastConnections(1); /* else walletAppKit.peerGroup().setMinBroadcastConnections(2); */ + + + walletEventListener = new WalletEventListener() + { + @Override + public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance) + { + notifyBalanceListeners(tx); + } + + @Override + public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) + { + notifyConfidenceListeners(tx); + } + + @Override + public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance) + { + notifyBalanceListeners(tx); + } + + @Override + public void onReorganize(Wallet wallet) + { + } + + @Override + public void onWalletChanged(Wallet wallet) + { + } + + @Override + public void onKeysAdded(Wallet wallet, List keys) + { + } + + @Override + public void onScriptsAdded(Wallet wallet, List