diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index 47391d6af0..603dcd0f5f 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -5,15 +5,11 @@ import com.google.inject.Injector; import io.bitsquare.btc.WalletFacade; import io.bitsquare.di.BitSquareModule; import io.bitsquare.di.GuiceFXMLLoader; -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 javafx.application.Application; import javafx.scene.Parent; import javafx.scene.Scene; @@ -21,11 +17,6 @@ import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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); @@ -60,10 +51,6 @@ public class BitSquare extends Application final Storage storage = injector.getInstance(Storage.class); user.updateFromStorage((User) storage.read(user.getClass().getName())); - // mock - //initSettings(settings, storage, user); - - settings.updateFromStorage((Settings) storage.read(settings.getClass().getName())); if (ID.length() > 0) @@ -89,46 +76,6 @@ 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 @@ -144,88 +91,4 @@ public class BitSquare extends Application { 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.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.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(); - settings.addAcceptedArbitrator(new Arbitrator("uid_1", "Charlie Boom", Utils.bytesToHexString(new ECKey().getPubKey()), - getMessagePubKey(), "http://www.arbit.io/Charly_Boom", 10, 50, Utils.toNanoCoins("0.01"))); - settings.addAcceptedArbitrator(new Arbitrator("uid_2", "Tom Shang", Utils.bytesToHexString(new ECKey().getPubKey()), - getMessagePubKey(), "http://www.arbit.io/Tom_Shang", 10, 100, Utils.toNanoCoins("0.001"))); - settings.addAcceptedArbitrator(new Arbitrator("uid_3", "Edward Snow", Utils.bytesToHexString(new ECKey().getPubKey()), - getMessagePubKey(), "http://www.arbit.io/Edward_Swow", 20, 50, Utils.toNanoCoins("0.05"))); - settings.addAcceptedArbitrator(new Arbitrator("uid_4", "Julian Sander", Utils.bytesToHexString(new ECKey().getPubKey()), - getMessagePubKey(), "http://www.arbit.io/Julian_Sander", 10, 20, Utils.toNanoCoins("0.1"))); - - settings.setMinCollateral(1); - settings.setMaxCollateral(10); - - storage.write(settings.getClass().getName(), settings); - - //initMockUser(storage, user); - } - } */ - - /* private String getMessagePubKey() - { - try - { - KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); - keyGen.initialize(1024); - KeyPair generatedKeyPair = keyGen.genKeyPair(); - PublicKey pubKey = generatedKeyPair.getPublic(); - return DSAKeyUtil.getHexStringFromPublicKey(pubKey); - } catch (Exception e2) - { - return null; - } - } */ - - - /* private void initMockUser(Storage storage, User user) - { - user.getBankAccounts().clear(); - - BankAccount bankAccount1 = new BankAccount(new BankAccountType(BankAccountType.BankAccountTypeEnum.SEPA, "Iban", "Bic"), - MockData.getCurrencies().get(0), - MockData.getLocales().get(0), - "Main EUR account", - "Manfred Karrer", - "564613242346", - "23432432434" - ); - user.addBankAccount(bankAccount1); - - BankAccount bankAccount2 = new BankAccount(new BankAccountType(BankAccountType.BankAccountTypeEnum.INTERNATIONAL, "Number", "ID"), - MockData.getCurrencies().get(1), - MockData.getLocales().get(2), - "US account", - "Manfred Karrer", - "22312123123123123", - "asdasdasdas" - ); - user.addBankAccount(bankAccount2); - - user.setAccountID(Utils.bytesToHexString(new ECKey().getPubKey())); - - storage.write(user.getClass().getName(), user); - } */ } diff --git a/src/main/java/io/bitsquare/RelayNode.java b/src/main/java/io/bitsquare/RelayNode.java index d6da424815..1f5bea5b1d 100755 --- a/src/main/java/io/bitsquare/RelayNode.java +++ b/src/main/java/io/bitsquare/RelayNode.java @@ -4,6 +4,9 @@ import net.tomp2p.p2p.Peer; import net.tomp2p.p2p.PeerMaker; import net.tomp2p.peers.Number160; +/** + * Network node for relaying p2p msg + */ public class RelayNode { private static Peer masterPeer = null; diff --git a/src/main/java/io/bitsquare/bank/BankAccount.java b/src/main/java/io/bitsquare/bank/BankAccount.java index e6d2dc6e42..c66e1270bd 100644 --- a/src/main/java/io/bitsquare/bank/BankAccount.java +++ b/src/main/java/io/bitsquare/bank/BankAccount.java @@ -8,7 +8,6 @@ import java.util.Objects; public class BankAccount implements Serializable { - private static final long serialVersionUID = 1792577576443221268L; private BankAccountTypeInfo bankAccountTypeInfo; @@ -18,8 +17,6 @@ public class BankAccount implements Serializable private Country country; private Currency currency; private String uid; - - private String accountTitle; public BankAccount(BankAccountTypeInfo bankAccountTypeInfo, diff --git a/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java b/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java index 0e6ca836b2..f95cfb7d2a 100644 --- a/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java +++ b/src/main/java/io/bitsquare/bank/BankAccountTypeInfo.java @@ -6,7 +6,6 @@ import java.util.Objects; public class BankAccountTypeInfo implements Serializable { - private static final long serialVersionUID = -8772708150197835288L; public static enum BankAccountType diff --git a/src/main/java/io/bitsquare/btc/AddressInfo.java b/src/main/java/io/bitsquare/btc/AddressInfo.java new file mode 100644 index 0000000000..1bd0a5e031 --- /dev/null +++ b/src/main/java/io/bitsquare/btc/AddressInfo.java @@ -0,0 +1,57 @@ +package io.bitsquare.btc; + +import com.google.bitcoin.core.Address; +import com.google.bitcoin.core.ECKey; +import com.google.bitcoin.core.NetworkParameters; +import com.google.bitcoin.core.Utils; + +import java.beans.Transient; +import java.io.Serializable; + +public class AddressInfo implements Serializable +{ + private static final long serialVersionUID = 5501603992599920416L; + + private ECKey key; + private NetworkParameters params; + private String label; + + public AddressInfo(ECKey key, NetworkParameters params, String label) + { + this.key = key; + this.params = params; + this.label = label; + } + + public void setLabel(String label) + { + this.label = label; + } + + public String getLabel() + { + return label; + } + + public String getAddressString() + { + return getAddress().toString(); + } + + public String getPubKeyAsHexString() + { + return Utils.bytesToHexString(key.getPubKey()); + } + + @Transient + public ECKey getKey() + { + return key; + } + + @Transient + public Address getAddress() + { + return key.toAddress(params); + } +} diff --git a/src/main/java/io/bitsquare/btc/BalanceListener.java b/src/main/java/io/bitsquare/btc/BalanceListener.java deleted file mode 100644 index 12986a21c3..0000000000 --- a/src/main/java/io/bitsquare/btc/BalanceListener.java +++ /dev/null @@ -1,27 +0,0 @@ -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/BitSquareWalletAppKit.java b/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java new file mode 100644 index 0000000000..968e8a0524 --- /dev/null +++ b/src/main/java/io/bitsquare/btc/BitSquareWalletAppKit.java @@ -0,0 +1,150 @@ +package io.bitsquare.btc; + +import com.google.bitcoin.core.*; +import com.google.bitcoin.kits.WalletAppKit; +import com.google.bitcoin.net.discovery.DnsDiscovery; +import com.google.bitcoin.store.BlockStoreException; +import com.google.bitcoin.store.SPVBlockStore; +import com.google.bitcoin.store.WalletProtobufSerializer; +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +public class BitSquareWalletAppKit extends WalletAppKit +{ + + public BitSquareWalletAppKit(NetworkParameters params, File directory, String filePrefix) + { + super(params, directory, filePrefix); + } + + @Override + protected void startUp() throws Exception + { + // Runs in a separate thread. + if (!directory.exists()) + { + if (!directory.mkdir()) + { + throw new IOException("Could not create named directory."); + } + } + FileInputStream walletStream = null; + try + { + File chainFile = new File(directory, filePrefix + ".spvchain"); + boolean chainFileExists = chainFile.exists(); + vWalletFile = new File(directory, filePrefix + ".wallet"); + boolean shouldReplayWallet = vWalletFile.exists() && !chainFileExists; + + vStore = new SPVBlockStore(params, chainFile); + if (!chainFileExists && checkpoints != null) + { + // Ugly hack! We have to create the wallet once here to learn the earliest key time, and then throw it + // away. The reason is that wallet extensions might need access to peergroups/chains/etc so we have to + // create the wallet later, but we need to know the time early here before we create the BlockChain + // object. + long time = Long.MAX_VALUE; + if (vWalletFile.exists()) + { + Wallet wallet = new BitSquareWallet(params); + FileInputStream stream = new FileInputStream(vWalletFile); + new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(stream), wallet); + time = wallet.getEarliestKeyCreationTime(); + } + CheckpointManager.checkpoint(params, checkpoints, vStore, time); + } + vChain = new BlockChain(params, vStore); + vPeerGroup = createPeerGroup(); + if (this.userAgent != null) + vPeerGroup.setUserAgent(userAgent, version); + if (vWalletFile.exists()) + { + walletStream = new FileInputStream(vWalletFile); + vWallet = new BitSquareWallet(params); + addWalletExtensions(); // All extensions must be present before we deserialize + new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet); + if (shouldReplayWallet) + vWallet.clearTransactions(0); + } + else + { + vWallet = new BitSquareWallet(params); + vWallet.addKey(new ECKey()); + addWalletExtensions(); + } + if (useAutoSave) vWallet.autosaveToFile(vWalletFile, 1, TimeUnit.SECONDS, null); + // Set up peer addresses or discovery first, so if wallet extensions try to broadcast a transaction + // before we're actually connected the broadcast waits for an appropriate number of connections. + if (peerAddresses != null) + { + for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr); + peerAddresses = null; + } + else + { + vPeerGroup.addPeerDiscovery(new DnsDiscovery(params)); + } + vChain.addWallet(vWallet); + vPeerGroup.addWallet(vWallet); + onSetupCompleted(); + + if (blockingStartup) + { + vPeerGroup.startAndWait(); + // Make sure we shut down cleanly. + installShutdownHook(); + // TODO: Be able to use the provided download listener when doing a blocking startup. + final DownloadListener listener = new DownloadListener(); + vPeerGroup.startBlockChainDownload(listener); + listener.await(); + } + else + { + Futures.addCallback(vPeerGroup.start(), new FutureCallback() + { + @Override + public void onSuccess(State result) + { + final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener; + vPeerGroup.startBlockChainDownload(l); + } + + @Override + public void onFailure(Throwable t) + { + throw new RuntimeException(t); + } + }); + } + } catch (BlockStoreException e) + { + throw new IOException(e); + } finally + { + if (walletStream != null) walletStream.close(); + } + } + + private void installShutdownHook() + { + if (autoStop) Runtime.getRuntime().addShutdownHook(new Thread() + { + @Override + public void run() + { + try + { + BitSquareWalletAppKit.this.stopAndWait(); + } catch (Exception e) + { + throw new RuntimeException(e); + } + } + }); + } +} diff --git a/src/main/java/io/bitsquare/btc/BlockChainFacade.java b/src/main/java/io/bitsquare/btc/BlockChainFacade.java index 6aefeada6b..f92d5670a3 100644 --- a/src/main/java/io/bitsquare/btc/BlockChainFacade.java +++ b/src/main/java/io/bitsquare/btc/BlockChainFacade.java @@ -5,8 +5,6 @@ import io.bitsquare.bank.BankAccount; /** * That facade delivers blockchain functionality from the bitcoinJ library - * Code from BitcoinJ must not be used outside that facade. - * That way a change of the library will only affect that class. */ public class BlockChainFacade { diff --git a/src/main/java/io/bitsquare/btc/BtcFormatter.java b/src/main/java/io/bitsquare/btc/BtcFormatter.java index 2d4c80a09c..92e2318619 100644 --- a/src/main/java/io/bitsquare/btc/BtcFormatter.java +++ b/src/main/java/io/bitsquare/btc/BtcFormatter.java @@ -10,6 +10,7 @@ import java.math.BigInteger; import java.text.DecimalFormat; import java.util.Locale; +// TODO public class BtcFormatter { private static final Logger log = LoggerFactory.getLogger(BtcFormatter.class); diff --git a/src/main/java/io/bitsquare/btc/ConfidenceListener.java b/src/main/java/io/bitsquare/btc/ConfidenceListener.java deleted file mode 100644 index 10b67da046..0000000000 --- a/src/main/java/io/bitsquare/btc/ConfidenceListener.java +++ /dev/null @@ -1,28 +0,0 @@ -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/KeyPair.java b/src/main/java/io/bitsquare/btc/KeyPair.java deleted file mode 100644 index c99466a707..0000000000 --- a/src/main/java/io/bitsquare/btc/KeyPair.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.bitsquare.btc; - -public class KeyPair -{ - //TODO just for mock, remove later - private String pubKey; - private String privKey; - - public KeyPair(String pubKey, String privKey) - { - this.pubKey = pubKey; - this.privKey = privKey; - } - - public String getPrivKey() - { - return privKey; - } - - public void setPrivKey(String privKey) - { - this.privKey = privKey; - } - - public String getPubKey() - { - return pubKey; - } - - public void setPubKey(String pubKey) - { - this.pubKey = pubKey; - } -} diff --git a/src/main/java/io/bitsquare/btc/ScriptUtil.java b/src/main/java/io/bitsquare/btc/ScriptUtil.java new file mode 100644 index 0000000000..68c28b0d05 --- /dev/null +++ b/src/main/java/io/bitsquare/btc/ScriptUtil.java @@ -0,0 +1,23 @@ +package io.bitsquare.btc; + +import com.google.bitcoin.core.TransactionOutput; +import com.google.bitcoin.script.Script; +import com.google.bitcoin.script.ScriptBuilder; +import com.google.bitcoin.script.ScriptOpCodes; + +import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN; + +public class ScriptUtil +{ + public static Script getEmptyOP_RETURNScript() + { + return new ScriptBuilder() + .op(OP_RETURN) + .build(); + } + + public static boolean isOpReturnScript(TransactionOutput transactionOutput) + { + return transactionOutput.getScriptPubKey().getChunks().get(0).equalsOpCode(ScriptOpCodes.OP_RETURN); + } +} diff --git a/src/main/java/io/bitsquare/btc/WalletConfig.java b/src/main/java/io/bitsquare/btc/WalletConfig.java deleted file mode 100644 index cfd4b15fbe..0000000000 --- a/src/main/java/io/bitsquare/btc/WalletConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.bitsquare.btc; - -import com.google.bitcoin.core.NetworkParameters; -import com.google.bitcoin.kits.WalletAppKit; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; - -public class WalletConfig extends WalletAppKit -{ - private static final Logger log = LoggerFactory.getLogger(WalletConfig.class); - - - public WalletConfig(NetworkParameters params, File directory, String filePrefix) - { - super(params, directory, filePrefix); - } - - -} diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index 1d57dfe193..4d5eb39850 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -2,12 +2,10 @@ package io.bitsquare.btc; import com.google.bitcoin.core.*; import com.google.bitcoin.crypto.TransactionSignature; -import com.google.bitcoin.kits.WalletAppKit; 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; @@ -15,7 +13,10 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; import io.bitsquare.BitSquare; +import io.bitsquare.btc.listeners.BalanceListener; +import io.bitsquare.btc.listeners.ConfidenceListener; import io.bitsquare.crypto.CryptoFacade; +import io.bitsquare.storage.Storage; import javafx.application.Platform; import javafx.util.Pair; import org.slf4j.Logger; @@ -38,16 +39,15 @@ public class WalletFacade private static final Logger log = LoggerFactory.getLogger(WalletFacade.class); private NetworkParameters params; - private WalletAppKit walletAppKit; + private BitSquareWalletAppKit walletAppKit; private CryptoFacade cryptoFacade; - - private List downloadListeners = new ArrayList<>(); - - private Wallet wallet; - private ECKey arbitratorKey; + private Storage storage; + private BitSquareWallet wallet; private WalletEventListener walletEventListener; + private List downloadListeners = new ArrayList<>(); private List confidenceListeners = new ArrayList<>(); private List balanceListeners = new ArrayList<>(); + private List addressInfoList = new ArrayList<>(); /////////////////////////////////////////////////////////////////////////////////////////// @@ -55,11 +55,12 @@ public class WalletFacade /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public WalletFacade(NetworkParameters params, WalletAppKit walletAppKit, CryptoFacade cryptoFacade) + public WalletFacade(NetworkParameters params, BitSquareWalletAppKit walletAppKit, CryptoFacade cryptoFacade, Storage storage) { this.params = params; this.walletAppKit = walletAppKit; this.cryptoFacade = cryptoFacade; + this.storage = storage; } @@ -99,7 +100,7 @@ public class WalletFacade walletAppKit.startAsync(); walletAppKit.awaitRunning(); - wallet = walletAppKit.wallet(); + wallet = (BitSquareWallet) walletAppKit.wallet(); wallet.allowSpendingUnconfirmedTransactions(); @@ -152,14 +153,33 @@ public class WalletFacade } }; wallet.addEventListener(walletEventListener); + + + List savedAddressInfoList = (List) storage.read("addressInfoList"); + if (savedAddressInfoList != null) + { + addressInfoList = savedAddressInfoList; + } + else + { + addressInfoList.add(getRegistrationAddressInfo()); + storage.write("addressInfoList", addressInfoList); + } } public void shutDown() { + wallet.removeEventListener(walletEventListener); + walletAppKit.stopAsync(); walletAppKit.awaitTerminated(); } + public Wallet getWallet() + { + return wallet; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Listener @@ -204,7 +224,7 @@ public class WalletFacade for (int n = 0; n < transactionOutputs.size(); n++) { TransactionOutput transactionOutput = transactionOutputs.get(n); - if (!isOpReturnScript(transactionOutput)) + if (!ScriptUtil.isOpReturnScript(transactionOutput)) { Address address = transactionOutput.getScriptPubKey().getToAddress(params); if (address.equals(confidenceListener.getAddress())) @@ -216,11 +236,6 @@ public class WalletFacade } } - private boolean isOpReturnScript(TransactionOutput transactionOutput) - { - return transactionOutput.getScriptPubKey().getChunks().get(0).equalsOpCode(ScriptOpCodes.OP_RETURN); - } - private void notifyBalanceListeners(Transaction tx) { for (int i = 0; i < balanceListeners.size(); i++) @@ -230,7 +245,7 @@ public class WalletFacade for (int n = 0; n < transactionOutputs.size(); n++) { TransactionOutput transactionOutput = transactionOutputs.get(n); - if (!isOpReturnScript(transactionOutput)) + if (!ScriptUtil.isOpReturnScript(transactionOutput)) { Address address = transactionOutput.getScriptPubKey().getToAddress(params); if (address.equals(balanceListener.getAddress())) @@ -244,45 +259,34 @@ public class WalletFacade /////////////////////////////////////////////////////////////////////////////////////////// - // Key management + // Address management /////////////////////////////////////////////////////////////////////////////////////////// - public boolean isNewWallet() + public List getAddressInfoList() { - // walletAppKit creates first key - return wallet.getKeys().size() == 1; + return addressInfoList; } - public Address getRegistrationAddress() + public AddressInfo getRegistrationAddressInfo() { - ECKey key = wallet.getKeys().get(0); - return key.toAddress(params); + ECKey registrationKey = wallet.getKeys().get(0); + return new AddressInfo(registrationKey, params, "Registration"); } - public List
getTradingAddresses() - { - List
addresses = new ArrayList<>(); - - List keys = wallet.getKeys(); - for (int i = 0; i < keys.size(); i++) - { - ECKey key = keys.get(i); - addresses.add(key.toAddress(params)); - } - return addresses; - } - - public Address createNewAddress() + public AddressInfo getNewAddressInfo(String label) { ECKey key = new ECKey(); wallet.addKey(key); - return key.toAddress(params); + AddressInfo addressInfo = new AddressInfo(key, params, label); + addressInfoList.add(addressInfo); + storage.write("addressInfoList", addressInfoList); + return addressInfo; } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Address management - /////////////////////////////////////////////////////////////////////////////////////////// + public AddressInfo getNewArbitratorAddressInfo() + { + return getNewAddressInfo("Arbitrator deposit"); + } public TransactionConfidence getConfidence(Address address) { @@ -295,7 +299,7 @@ public class WalletFacade for (int n = 0; n < transactionOutputs.size(); n++) { TransactionOutput transactionOutput = transactionOutputs.get(n); - if (!isOpReturnScript(transactionOutput)) + if (!ScriptUtil.isOpReturnScript(transactionOutput)) { Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params); if (addressOutput.equals(address)) @@ -319,7 +323,7 @@ public class WalletFacade BigInteger value = BigInteger.ZERO; for (TransactionOutput transactionOutput : all) { - if (!isOpReturnScript(transactionOutput)) + if (!ScriptUtil.isOpReturnScript(transactionOutput)) { Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params); if (addressOutput.equals(address)) @@ -329,55 +333,31 @@ public class WalletFacade } } return value; - - /* Set transactions = wallet.getTransactions(true); - if (transactions != null) - { - for (Transaction tx : transactions) - { - List transactionOutputs = tx.getOutputs(); - for (int n = 0; n < transactionOutputs.size(); n++) - { - TransactionOutput transactionOutput = transactionOutputs.get(n); - if (!isOpReturnScript(transactionOutput)) - { - - Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params); - if (addressOutput.equals(address)) - { - return tx.getValueSentToMe(wallet); - } - } - else - { - return BigInteger.ZERO; - } - } - } - } - return BigInteger.ZERO; */ } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Trading wallet - /////////////////////////////////////////////////////////////////////////////////////////// - - public BigInteger getBalance() + public BigInteger getWalletBalance() { return wallet.getBalance(Wallet.BalanceType.ESTIMATED); } + public BigInteger getRegistrationBalance() + { + return getBalance(getRegistrationAddressInfo().getAddress()); + } + + public ECKey getRegistrationKey() + { + return getRegistrationAddressInfo().getKey(); + } + + + //TODO public String getTradingAddress() { return getTradingKey().toAddress(params).toString(); } - public Wallet getWallet() - { - return wallet; - } - + //TODO public String getPubKeyAsHex() { return Utils.bytesToHexString(getTradingKey().getPubKey()); @@ -390,21 +370,6 @@ public class WalletFacade } - /////////////////////////////////////////////////////////////////////////////////////////// - // Arbitration key - /////////////////////////////////////////////////////////////////////////////////////////// - - public String getArbitratorPubKeyAsHex() - { - if (arbitratorKey == null) - { - arbitratorKey = new ECKey(); - wallet.addKey(arbitratorKey); - } - - return Utils.bytesToHexString(arbitratorKey.getPubKey()); - } - //TODO separate wallets public BigInteger getCollateralBalance() { @@ -415,17 +380,6 @@ public class WalletFacade // Account registration /////////////////////////////////////////////////////////////////////////////////////////// - public BigInteger getRegistrationBalance() - { - return getBalance(getRegistrationAddress()); - } - - public ECKey getRegistrationKey() - { - return wallet.getKeys().get(0); - } - - public void publishRegistrationTxWithExtraData(String stringifiedBankAccounts) throws InsufficientMoneyException { log.debug("publishRegistrationTxWithExtraData"); @@ -471,7 +425,7 @@ public class WalletFacade { log.debug("payOfferFee fee=" + Utils.bitcoinValueToFriendlyString(fee)); Transaction tx = new Transaction(params); - tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, WalletUtil.getEmptyOP_RETURNScript()); + tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, ScriptUtil.getEmptyOP_RETURNScript()); Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx); sendRequest.fee = fee.subtract(Transaction.MIN_NONDUST_OUTPUT).subtract(Fees.TX_FEE); diff --git a/src/main/java/io/bitsquare/btc/WalletUtil.java b/src/main/java/io/bitsquare/btc/WalletUtil.java deleted file mode 100644 index a7e33715fc..0000000000 --- a/src/main/java/io/bitsquare/btc/WalletUtil.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.bitsquare.btc; - -import com.google.bitcoin.core.Transaction; -import com.google.bitcoin.core.TransactionConfidence; -import com.google.bitcoin.core.Wallet; -import com.google.bitcoin.script.Script; -import com.google.bitcoin.script.ScriptBuilder; - -import java.math.BigInteger; -import java.util.Set; - -import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN; - -public class WalletUtil -{ - - // TODO check if that is correct and safe - public static int getConfDepthInBlocks(Wallet wallet) - { - Transaction transaction = WalletUtil.getTransaction(wallet); - if (transaction != null && transaction.getConfidence() != null) - { - if (transaction.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) - return wallet.getLastBlockSeenHeight() - transaction.getConfidence().getAppearedAtChainHeight() + 1; - else - return 0; - } - else - { - return 0; - } - } - - // TODO check if that is correct and safe - public static Transaction getTransaction(Wallet wallet) - { - Set transactions = wallet.getTransactions(true); - if (transactions != null) - { - for (Transaction transaction : transactions) - { - if (transaction.getValueSentFromMe(wallet).compareTo(BigInteger.ZERO) == 0) - return transaction; - } - } - return null; - } - - public static Script getEmptyOP_RETURNScript() - { - return new ScriptBuilder() - .op(OP_RETURN) - .build(); - } -} diff --git a/src/main/java/io/bitsquare/crypto/CryptoFacade.java b/src/main/java/io/bitsquare/crypto/CryptoFacade.java index 13c0f82d2e..e68bde57ec 100644 --- a/src/main/java/io/bitsquare/crypto/CryptoFacade.java +++ b/src/main/java/io/bitsquare/crypto/CryptoFacade.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.security.SignatureException; -import java.util.UUID; /** * That facade delivers crypto functionality from the bitcoinJ library @@ -23,10 +22,6 @@ public class CryptoFacade { } - public String getRandomID() - { - return UUID.randomUUID().toString(); - } public byte[] getEmbeddedAccountRegistrationData(ECKey registrationKey, String stringifiedBankAccounts) { diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index b06001ceab..e109fcb51e 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -2,7 +2,6 @@ package io.bitsquare.di; import com.google.bitcoin.core.NetworkParameters; -import com.google.bitcoin.kits.WalletAppKit; import com.google.bitcoin.params.MainNetParams; import com.google.bitcoin.params.RegTestParams; import com.google.bitcoin.params.TestNet3Params; @@ -11,6 +10,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.name.Named; import com.google.inject.name.Names; +import io.bitsquare.btc.BitSquareWalletAppKit; import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.WalletFacade; import io.bitsquare.crypto.CryptoFacade; @@ -50,23 +50,23 @@ public class BitSquareModule extends AbstractModule //test net not working yet: http://sourceforge.net/p/bitcoin/mailman/message/32349208/ //bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.TEST_NET); bind(NetworkParameters.class).toProvider(NetworkParametersProvider.class).asEagerSingleton(); - bind(WalletAppKit.class).toProvider(WalletAppKitProvider.class).asEagerSingleton(); + bind(BitSquareWalletAppKit.class).toProvider(BitSquareWalletAppKitProvider.class).asEagerSingleton(); } } -class WalletAppKitProvider implements Provider +class BitSquareWalletAppKitProvider implements Provider { private NetworkParameters networkParameters; @Inject - public WalletAppKitProvider(NetworkParameters networkParameters) + public BitSquareWalletAppKitProvider(NetworkParameters networkParameters) { this.networkParameters = networkParameters; } - public WalletAppKit get() + public BitSquareWalletAppKit get() { - return new WalletAppKit(networkParameters, new File(Utilities.getRootDir()), WalletFacade.WALLET_PREFIX); + return new BitSquareWalletAppKit(networkParameters, new File(Utilities.getRootDir()), WalletFacade.WALLET_PREFIX); } } diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/MainController.java index 62779dcf0d..fbc47ce6c4 100644 --- a/src/main/java/io/bitsquare/gui/MainController.java +++ b/src/main/java/io/bitsquare/gui/MainController.java @@ -9,7 +9,6 @@ import io.bitsquare.btc.WalletFacade; import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.gui.components.NetworkSyncPane; import io.bitsquare.gui.market.MarketController; -import io.bitsquare.gui.setup.SetupController; import io.bitsquare.gui.util.Icons; import io.bitsquare.locale.Localisation; import io.bitsquare.msg.MessageFacade; @@ -54,7 +53,6 @@ public class MainController implements Initializable, NavigationController private ToggleButton prevToggleButton; private Image prevToggleButtonIcon; private Pane setupView; - private SetupController setupController; private NetworkSyncPane networkSyncPane; private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, historyButton, fundsButton, settingsButton; private Pane msgButtonHolder, buyButtonHolder, sellButtonHolder, ordersButtonButtonHolder; @@ -121,15 +119,6 @@ public class MainController implements Initializable, NavigationController walletFacade.initWallet(); - /*if (user.getAccountID() == null) - { - buildSetupView(); - anchorPane.setVisible(false); - setupController.setNetworkSyncPane(networkSyncPane); - rootContainer.getChildren().add(setupView); - } - else - { */ buildNavigation(); //homeButton.fire(); @@ -139,7 +128,6 @@ public class MainController implements Initializable, NavigationController // ordersButton.fire(); // homeButton.fire(); // msgButton.fire(); - // } AnchorPane.setBottomAnchor(networkSyncPane, 0.0); AnchorPane.setLeftAnchor(networkSyncPane, 0.0); @@ -212,7 +200,6 @@ public class MainController implements Initializable, NavigationController anchorPane.setVisible(true); rootContainer.getChildren().remove(setupView); setupView = null; - setupController = null; buildNavigation(); } @@ -240,20 +227,6 @@ public class MainController implements Initializable, NavigationController // Private methods /////////////////////////////////////////////////////////////////////////////////////////// - private void buildSetupView() - { - final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(NavigationController.SETUP), Localisation.getResourceBundle()); - try - { - setupView = loader.load(); - setupController = loader.getController(); - setupController.setNavigationController(this); - } catch (IOException e) - { - e.printStackTrace(); - } - } - private void buildNavigation() { toggleGroup = new ToggleGroup(); @@ -342,7 +315,7 @@ public class MainController implements Initializable, NavigationController balanceTextField.setPrefWidth(90); balanceTextField.setId("nav-balance-label"); - balanceTextField.setText(BtcFormatter.formatSatoshis(walletFacade.getBalance(), false)); + balanceTextField.setText(BtcFormatter.formatSatoshis(walletFacade.getWalletBalance(), false)); Label balanceCurrencyLabel = new Label("BTC"); balanceCurrencyLabel.setPadding(new Insets(6, 0, 0, 0)); @@ -361,7 +334,7 @@ public class MainController implements Initializable, NavigationController vBox.getChildren().setAll(hBox, titleLabel); parent.getChildren().add(vBox); - balanceTextField.setText(Utils.bitcoinValueToFriendlyString(walletFacade.getBalance())); + balanceTextField.setText(Utils.bitcoinValueToFriendlyString(walletFacade.getWalletBalance())); walletFacade.getWallet().addEventListener(new WalletEventListener() { @Override diff --git a/src/main/java/io/bitsquare/gui/arbitrators/overview/ArbitratorOverviewController.java b/src/main/java/io/bitsquare/gui/arbitrators/overview/ArbitratorOverviewController.java index 589ddfbf51..d0345ea712 100644 --- a/src/main/java/io/bitsquare/gui/arbitrators/overview/ArbitratorOverviewController.java +++ b/src/main/java/io/bitsquare/gui/arbitrators/overview/ArbitratorOverviewController.java @@ -64,6 +64,7 @@ public class ArbitratorOverviewController implements Initializable, ChildControl messageFacade.getArbitrators(LanguageUtil.getDefaultLanguageLocale()); } + /////////////////////////////////////////////////////////////////////////////////////////// // Interface implementation: Initializable /////////////////////////////////////////////////////////////////////////////////////////// @@ -221,6 +222,7 @@ public class ArbitratorOverviewController implements Initializable, ChildControl stage.close(); } + /////////////////////////////////////////////////////////////////////////////////////////// // Private methods /////////////////////////////////////////////////////////////////////////////////////////// @@ -230,6 +232,5 @@ public class ArbitratorOverviewController implements Initializable, ChildControl prevButton.setDisable(index < 1); nextButton.setDisable(index == allArbitrators.size() - 1 || index == -1); } - } diff --git a/src/main/java/io/bitsquare/gui/arbitrators/profile/ArbitratorProfileController.java b/src/main/java/io/bitsquare/gui/arbitrators/profile/ArbitratorProfileController.java index e1fea42a35..4fdb1c26b7 100644 --- a/src/main/java/io/bitsquare/gui/arbitrators/profile/ArbitratorProfileController.java +++ b/src/main/java/io/bitsquare/gui/arbitrators/profile/ArbitratorProfileController.java @@ -18,10 +18,8 @@ import java.util.ResourceBundle; public class ArbitratorProfileController implements Initializable, ChildController { - private Settings settings; private Storage storage; - private Arbitrator arbitrator; private NavigationController navigationController; @@ -33,6 +31,7 @@ public class ArbitratorProfileController implements Initializable, ChildControll @FXML private TextArea descriptionTextArea; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @@ -46,12 +45,7 @@ public class ArbitratorProfileController implements Initializable, ChildControll Settings savedSettings = (Settings) storage.read(settings.getClass().getName()); if (savedSettings != null) - { settings.updateFromStorage(savedSettings); - } - else - { - } } @@ -100,6 +94,7 @@ public class ArbitratorProfileController implements Initializable, ChildControll { } + /////////////////////////////////////////////////////////////////////////////////////////// // Interface implementation: ChildController /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/io/bitsquare/gui/arbitrators/registration/ArbitratorRegistrationController.java b/src/main/java/io/bitsquare/gui/arbitrators/registration/ArbitratorRegistrationController.java index 3bc211217b..53672f065e 100644 --- a/src/main/java/io/bitsquare/gui/arbitrators/registration/ArbitratorRegistrationController.java +++ b/src/main/java/io/bitsquare/gui/arbitrators/registration/ArbitratorRegistrationController.java @@ -84,6 +84,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon @FXML private ConfidenceProgressIndicator progressIndicator; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @@ -113,6 +114,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon } } + /////////////////////////////////////////////////////////////////////////////////////////// // Interface implementation: Initializable /////////////////////////////////////////////////////////////////////////////////////////// @@ -200,6 +202,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon }); } + /////////////////////////////////////////////////////////////////////////////////////////// // Interface implementation: ChildController /////////////////////////////////////////////////////////////////////////////////////////// @@ -275,7 +278,6 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon methodsTextField.setText(BitSquareFormatter.arbitrationMethodsToString(methodList)); methodsComboBox.getSelectionModel().clearSelection(); } - } @FXML @@ -302,7 +304,6 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon idVerificationsComboBox.getSelectionModel().clearSelection(); } - @FXML public void onClearIDVerifications(ActionEvent actionEvent) { @@ -310,7 +311,6 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon idVerificationsTextField.setText(""); } - @FXML public void onSaveProfile(ActionEvent actionEvent) { @@ -345,6 +345,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon //To change body of created methods use File | Settings | File Templates. } + /////////////////////////////////////////////////////////////////////////////////////////// // Private methods /////////////////////////////////////////////////////////////////////////////////////////// @@ -358,7 +359,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon "depending on the overall relation of negative to positive ratings you received after a dispute resolution.\n\n" + "Please pay in " + arbitrator.getMaxTradeVolume() * 10 + " BTC"); - String collateralAddress = walletFacade.getRegistrationAddress().toString(); + String collateralAddress = walletFacade.getRegistrationAddressInfo().toString(); collateralAddressTextField.setText(collateralAddress); AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY); @@ -448,7 +449,6 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon languageList = arbitrator.getLanguages(); methodList = arbitrator.getArbitrationMethods(); idVerificationList = arbitrator.getIdVerifications(); - } } @@ -464,7 +464,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon BitSquareValidator.resetTextFields(hasDoubleValueTextFields); BitSquareValidator.textFieldsHasDoubleValue(hasDoubleValueTextFields); - String pubKeyAsHex = walletFacade.getArbitratorPubKeyAsHex(); + String pubKeyAsHex = walletFacade.getNewArbitratorAddressInfo().getPubKeyAsHexString(); String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey()); String name = nameTextField.getText(); @@ -498,23 +498,6 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon } } - private boolean isInputValid() - { - String[] stringInputs = {nameTextField.getText(), - descriptionTextArea.getText() - }; - boolean result = BitSquareValidator.validateStringsNotEmpty(stringInputs); - - String[] doubleInputs = {maxTradeVolumeTextField.getText(), - passiveServiceFeeTextField.getText(), - minPassiveServiceFeeTextField.getText(), - arbitrationFeeTextField.getText(), - minArbitrationFeeTextField.getText() - }; - result &= BitSquareValidator.validateStringsAsDouble(doubleInputs); - return result; - } - private void close() { Stage stage = (Stage) rootContainer.getScene().getWindow(); diff --git a/src/main/java/io/bitsquare/gui/components/HSpacer.java b/src/main/java/io/bitsquare/gui/components/HSpacer.java index 479e51002e..43a93fc542 100644 --- a/src/main/java/io/bitsquare/gui/components/HSpacer.java +++ b/src/main/java/io/bitsquare/gui/components/HSpacer.java @@ -5,9 +5,6 @@ import javafx.scene.layout.Pane; public class HSpacer extends Pane { - public HSpacer() - { - } public HSpacer(double width) { diff --git a/src/main/java/io/bitsquare/gui/components/VSpacer.java b/src/main/java/io/bitsquare/gui/components/VSpacer.java index d0dc7f339a..b7b2b6624e 100644 --- a/src/main/java/io/bitsquare/gui/components/VSpacer.java +++ b/src/main/java/io/bitsquare/gui/components/VSpacer.java @@ -5,9 +5,6 @@ import javafx.scene.layout.Pane; public class VSpacer extends Pane { - public VSpacer() - { - } public VSpacer(double height) { diff --git a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java b/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java deleted file mode 100644 index 300b743b93..0000000000 --- a/src/main/java/io/bitsquare/gui/components/processbar/ProcessStepsBuilder.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.bitsquare.gui.components.processbar; - -import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; -import io.bitsquare.util.Utilities; -import javafx.animation.AnimationTimer; -import javafx.scene.control.Button; -import javafx.scene.control.Control; -import javafx.scene.layout.Pane; - -import java.util.ArrayList; -import java.util.List; - -public class ProcessStepsBuilder -{ - protected int index = 0; - private Control previousControl; - private Pane controlHolder; - protected Object controller; - protected List processStepItems = new ArrayList(); - protected ProcessStepBar processStepBar; - - public void build(Pane processStepBarHolder, Pane controlHolder, Object controller) - { - this.controlHolder = controlHolder; - this.controller = controller; - - fillProcessStepItems(); - - processStepBar = new ProcessStepBar(processStepItems); - processStepBar.relocate(10, 10); - - processStepBarHolder.getChildren().add(processStepBar); - - update(); - } - - public void next() - { - index++; - update(); - processStepBar.next(); - } - - // template - protected void fillProcessStepItems() - { - // to be defined in subclasses - } - - protected void update() - { - if (index < processStepItems.size()) - { - ProcessStepItem processStepItem = processStepItems.get(index); - if (previousControl != null) - controlHolder.getChildren().remove(previousControl); - - if (processStepItem.hasProgressIndicator()) - { - final ConfidenceProgressIndicator progressIndicator = new ConfidenceProgressIndicator(); - progressIndicator.setProgress(-1.0); - progressIndicator.setPrefSize(30.0, 30.0); - controlHolder.getChildren().add(progressIndicator); - previousControl = progressIndicator; - - // TODO - // mock simulate network delay - Utilities.setTimeout(100, (AnimationTimer animationTimer) -> { - next(); - return null; - }); - } - else - { - final Button button = new Button(processStepItem.getLabel()); - button.setOnAction(e -> next()); - - controlHolder.getChildren().add(button); - previousControl = button; - } - } - } -} - diff --git a/src/main/java/io/bitsquare/gui/funds/AddressListItem.java b/src/main/java/io/bitsquare/gui/funds/AddressListItem.java index e63550d6a4..49917b253f 100644 --- a/src/main/java/io/bitsquare/gui/funds/AddressListItem.java +++ b/src/main/java/io/bitsquare/gui/funds/AddressListItem.java @@ -22,7 +22,6 @@ public class AddressListItem this.isUsed.set(isUsed); } - // called form table columns public final StringProperty labelProperty() { @@ -39,7 +38,6 @@ public class AddressListItem return this.isUsed; } - public Address getAddress() { return address; diff --git a/src/main/java/io/bitsquare/gui/funds/FundsController.java b/src/main/java/io/bitsquare/gui/funds/FundsController.java index adc4190fde..2397a38071 100644 --- a/src/main/java/io/bitsquare/gui/funds/FundsController.java +++ b/src/main/java/io/bitsquare/gui/funds/FundsController.java @@ -1,14 +1,14 @@ package io.bitsquare.gui.funds; -import com.google.bitcoin.core.Address; import com.google.bitcoin.core.TransactionConfidence; import com.google.bitcoin.core.Utils; import com.google.inject.Inject; import de.jensd.fx.fontawesome.AwesomeDude; import de.jensd.fx.fontawesome.AwesomeIcon; -import io.bitsquare.btc.BalanceListener; -import io.bitsquare.btc.ConfidenceListener; +import io.bitsquare.btc.AddressInfo; import io.bitsquare.btc.WalletFacade; +import io.bitsquare.btc.listeners.BalanceListener; +import io.bitsquare.btc.listeners.ConfidenceListener; import io.bitsquare.gui.ChildController; import io.bitsquare.gui.NavigationController; import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; @@ -72,23 +72,16 @@ public class FundsController implements Initializable, ChildController setCopyColumnCellFactory(); setConfidenceColumnCellFactory(); - List
addresses = walletFacade.getTradingAddresses(); + List addressInfoList = walletFacade.getAddressInfoList(); - for (int i = 0; i < addresses.size(); i++) + for (int i = 0; i < addressInfoList.size(); i++) { - Address address = addresses.get(i); - String label; - if (i == 0) - label = "Registration"; - else - label = "Trade " + i; - addressList.add(new AddressListItem(label, address, false)); + AddressInfo addressInfo = addressInfoList.get(i); + addressList.add(new AddressListItem(addressInfo.getLabel(), addressInfo.getAddress(), false)); } addressesTable.setItems(addressList); addressesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); - - //Platform.runLater(() -> walletFacade.triggerConfidenceNotificationForAllTransactions()); } @@ -104,7 +97,6 @@ public class FundsController implements Initializable, ChildController @Override public void cleanup() { - } @@ -115,9 +107,8 @@ public class FundsController implements Initializable, ChildController @FXML public void onAddNewAddress(ActionEvent actionEvent) { - Address address = walletFacade.createNewAddress(); - addressList.add(new AddressListItem("Trade " + (walletFacade.getTradingAddresses().size() - 1), address, false)); - // walletFacade.triggerConfidenceNotificationForAllTransactions(); + AddressInfo addressInfo = walletFacade.getNewAddressInfo("New address"); + addressList.add(new AddressListItem(addressInfo.getLabel(), addressInfo.getAddress(), false)); } @@ -298,6 +289,5 @@ public class FundsController implements Initializable, ChildController } } } - } diff --git a/src/main/java/io/bitsquare/gui/history/HistoryController.java b/src/main/java/io/bitsquare/gui/history/HistoryController.java index 3f90c155f4..17cfa06ea8 100644 --- a/src/main/java/io/bitsquare/gui/history/HistoryController.java +++ b/src/main/java/io/bitsquare/gui/history/HistoryController.java @@ -16,7 +16,6 @@ public class HistoryController implements Initializable, ChildController public void initialize(URL url, ResourceBundle rb) { - } @Override diff --git a/src/main/java/io/bitsquare/gui/home/HomeController.java b/src/main/java/io/bitsquare/gui/home/HomeController.java index 610f1a9125..30b55769f0 100644 --- a/src/main/java/io/bitsquare/gui/home/HomeController.java +++ b/src/main/java/io/bitsquare/gui/home/HomeController.java @@ -96,7 +96,6 @@ public class HomeController implements Initializable, ChildController, Navigatio public void onArbitratorRegistration(ActionEvent actionEvent) { navigateToView(NavigationController.ARBITRATOR_REGISTRATION, "Registration as Arbitrator"); - } @FXML diff --git a/src/main/java/io/bitsquare/gui/market/createOffer/CreateOfferController.java b/src/main/java/io/bitsquare/gui/market/createOffer/CreateOfferController.java index d331f4852e..cd671e5759 100644 --- a/src/main/java/io/bitsquare/gui/market/createOffer/CreateOfferController.java +++ b/src/main/java/io/bitsquare/gui/market/createOffer/CreateOfferController.java @@ -243,6 +243,7 @@ public class CreateOfferController implements Initializable, ChildController navigationController.navigateToView(NavigationController.ORDER_BOOK, "Orderbook"); } + /////////////////////////////////////////////////////////////////////////////////////////// // Private methods /////////////////////////////////////////////////////////////////////////////////////////// @@ -279,6 +280,7 @@ public class CreateOfferController implements Initializable, ChildController return BtcFormatter.stringValueToSatoshis(amountTextField.getText()); } + //TODO private boolean inputValid() { double priceAsDouble = BitSquareConverter.stringToDouble2(priceTextField.getText()); diff --git a/src/main/java/io/bitsquare/gui/market/orderbook/OrderBookController.java b/src/main/java/io/bitsquare/gui/market/orderbook/OrderBookController.java index e884268a3d..7bc6d8ac87 100644 --- a/src/main/java/io/bitsquare/gui/market/orderbook/OrderBookController.java +++ b/src/main/java/io/bitsquare/gui/market/orderbook/OrderBookController.java @@ -61,7 +61,6 @@ public class OrderBookController implements Initializable, ChildController private static final Logger log = LoggerFactory.getLogger(OrderBookController.class); private NavigationController navigationController; private OrderBook orderBook; - private SortedList offerList; private final OrderBookFilter orderBookFilter; private User user; @@ -70,7 +69,6 @@ public class OrderBookController implements Initializable, ChildController private Settings settings; private Storage storage; private AnimationTimer pollingTimer; - private Image buyIcon = Icons.getIconImage(Icons.BUY); private Image sellIcon = Icons.getIconImage(Icons.SELL); @@ -197,7 +195,7 @@ public class OrderBookController implements Initializable, ChildController try { walletFacade.publishRegistrationTxWithExtraData(user.getStringifiedBankAccounts()); - user.setAccountID(walletFacade.getRegistrationAddress().toString()); + user.setAccountID(walletFacade.getRegistrationAddressInfo().toString()); user.setMessagePubKeyAsHex(DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey())); storage.write(user.getClass().getName(), user); diff --git a/src/main/java/io/bitsquare/gui/market/trade/TakerTradeController.java b/src/main/java/io/bitsquare/gui/market/trade/TakerTradeController.java index 90860c2fbc..74ca88d80f 100644 --- a/src/main/java/io/bitsquare/gui/market/trade/TakerTradeController.java +++ b/src/main/java/io/bitsquare/gui/market/trade/TakerTradeController.java @@ -54,9 +54,7 @@ public class TakerTradeController implements Initializable, ChildController private BigInteger requestedAmount; private boolean offererIsOnline; private int row; - private List processStepItems = new ArrayList(); - private NavigationController navigationController; private TextField amountTextField, totalToPayLabel, totalLabel, collateralTextField, isOnlineTextField; private Label statusTextField, infoLabel; @@ -64,7 +62,7 @@ public class TakerTradeController implements Initializable, ChildController private ProgressBar progressBar; private AnimationTimer checkOnlineStatusTimer; private Pane isOnlineCheckerHolder; - TakerPaymentProtocol takerPaymentProtocol; + private TakerPaymentProtocol takerPaymentProtocol; private Label headerLabel; @FXML @@ -448,7 +446,6 @@ public class TakerTradeController implements Initializable, ChildController } } - private void applyCollateral() { collateralTextField.setText(BtcFormatter.formatSatoshis(getCollateralInSatoshis(), false)); diff --git a/src/main/java/io/bitsquare/gui/orders/OrdersController.java b/src/main/java/io/bitsquare/gui/orders/OrdersController.java index f179ed550e..11535870c9 100644 --- a/src/main/java/io/bitsquare/gui/orders/OrdersController.java +++ b/src/main/java/io/bitsquare/gui/orders/OrdersController.java @@ -59,7 +59,6 @@ public class OrdersController implements Initializable, ChildController private Image sellIcon = Icons.getIconImage(Icons.SELL); private ConfidenceDisplay confidenceDisplay; - @FXML private VBox rootContainer; @FXML @@ -179,7 +178,6 @@ public class OrdersController implements Initializable, ChildController public void close(ActionEvent actionEvent) { - } diff --git a/src/main/java/io/bitsquare/gui/settings/SettingsController.java b/src/main/java/io/bitsquare/gui/settings/SettingsController.java index 51218bf99a..7f056779f0 100644 --- a/src/main/java/io/bitsquare/gui/settings/SettingsController.java +++ b/src/main/java/io/bitsquare/gui/settings/SettingsController.java @@ -1,19 +1,25 @@ package io.bitsquare.gui.settings; +import com.google.bitcoin.core.ECKey; +import com.google.bitcoin.core.Utils; import com.google.inject.Inject; import io.bitsquare.BitSquare; import io.bitsquare.bank.BankAccount; import io.bitsquare.bank.BankAccountTypeInfo; +import io.bitsquare.btc.WalletFacade; import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.gui.ChildController; import io.bitsquare.gui.NavigationController; import io.bitsquare.gui.util.BitSquareValidator; import io.bitsquare.gui.util.Icons; import io.bitsquare.locale.*; +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 javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; @@ -37,14 +43,16 @@ import java.io.IOException; import java.net.URL; import java.util.*; +// TODO separate in 2 view/controllers public class SettingsController implements Initializable, ChildController, NavigationController { private User user; private Settings settings; private Storage storage; + private WalletFacade walletFacade; + private MessageFacade messageFacade; private NavigationController navigationController; private ChildController childController; - private ObservableList languageList; private ObservableList countryList; private List regionList; @@ -80,11 +88,13 @@ public class SettingsController implements Initializable, ChildController, Navig /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public SettingsController(User user, Settings settings, Storage storage) + public SettingsController(User user, Settings settings, Storage storage, WalletFacade walletFacade, MessageFacade messageFacade) { this.user = user; this.settings = settings; this.storage = storage; + this.walletFacade = walletFacade; + this.messageFacade = messageFacade; Settings savedSettings = (Settings) storage.read(settings.getClass().getName()); if (savedSettings != null) @@ -127,6 +137,46 @@ public class SettingsController implements Initializable, ChildController, Navig setupGeneralSettingsScreen(); initBankAccountScreen(); + + addMockArbitrator(); + } + + private void addMockArbitrator() + { + String pubKeyAsHex = Utils.bytesToHexString(new ECKey().getPubKey()); + 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. + } } diff --git a/src/main/java/io/bitsquare/gui/setup/SetupController.java b/src/main/java/io/bitsquare/gui/setup/SetupController.java deleted file mode 100644 index 816fd6c48c..0000000000 --- a/src/main/java/io/bitsquare/gui/setup/SetupController.java +++ /dev/null @@ -1,393 +0,0 @@ -package io.bitsquare.gui.setup; - -import com.google.bitcoin.core.*; -import com.google.bitcoin.script.Script; -import com.google.inject.Inject; -import de.jensd.fx.fontawesome.AwesomeDude; -import de.jensd.fx.fontawesome.AwesomeIcon; -import io.bitsquare.bank.BankAccount; -import io.bitsquare.bank.BankAccountTypeInfo; -import io.bitsquare.btc.WalletFacade; -import io.bitsquare.gui.ChildController; -import io.bitsquare.gui.NavigationController; -import io.bitsquare.gui.components.NetworkSyncPane; -import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; -import io.bitsquare.gui.util.ConfidenceDisplay; -import io.bitsquare.gui.util.Popups; -import io.bitsquare.locale.Country; -import io.bitsquare.locale.CountryUtil; -import io.bitsquare.locale.CurrencyUtil; -import io.bitsquare.locale.Localisation; -import io.bitsquare.msg.MessageFacade; -import io.bitsquare.storage.Storage; -import io.bitsquare.user.User; -import io.bitsquare.util.DSAKeyUtil; -import javafx.collections.FXCollections; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.control.*; -import javafx.scene.input.Clipboard; -import javafx.scene.input.ClipboardContent; -import javafx.scene.layout.AnchorPane; -import javafx.util.StringConverter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigInteger; -import java.net.URL; -import java.util.Currency; -import java.util.List; -import java.util.ResourceBundle; - -public class SetupController implements Initializable, ChildController -{ - private static final Logger log = LoggerFactory.getLogger(SetupController.class); - - private final User user; - private final WalletFacade walletFacade; - private NavigationController navigationController; - private MessageFacade messageFacade; - private final Storage storage; - private ConfidenceDisplay confidenceDisplay; - - @FXML - private AnchorPane rootContainer; - @FXML - private TitledPane payRegistrationFeePane, addBankAccountPane, settingsPane; - @FXML - private Label payRegFeeInfoLabel, addBankAccountInfoLabel, copyIcon, confirmationLabel; - @FXML - private TextField registrationAddressTextField, balanceTextField, accountTitle, accountHolderName, accountPrimaryID, accountSecondaryID; - @FXML - private Button createAccountButton, addBankAccountButton, paymentDoneButton; - @FXML - private Accordion accordion; - @FXML - private ComboBox countryComboBox; - @FXML - private ComboBox bankAccountTypesComboBox; - @FXML - private ComboBox currencyComboBox; - @FXML - private ConfidenceProgressIndicator progressIndicator; - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Constructor - /////////////////////////////////////////////////////////////////////////////////////////// - - @Inject - public SetupController(User user, WalletFacade walletFacade, MessageFacade messageFacade, Storage storage) - { - this.user = user; - this.walletFacade = walletFacade; - this.messageFacade = messageFacade; - this.storage = storage; - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Public methods - /////////////////////////////////////////////////////////////////////////////////////////// - - // pass in NetworkSyncPane from parent view - public void setNetworkSyncPane(NetworkSyncPane networkSyncPane) - { - rootContainer.getChildren().add(networkSyncPane); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Interface implementation: Initializable - /////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void initialize(URL url, ResourceBundle rb) - { - setupRegistrationScreen(); - setupBankAccountScreen(); - setupSettingsScreen(); - - accordion.setExpandedPane(payRegistrationFeePane); - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Interface implementation: ChildController - /////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void setNavigationController(NavigationController navigationController) - { - this.navigationController = navigationController; - } - - @Override - public void cleanup() - { - - } - - /////////////////////////////////////////////////////////////////////////////////////////// - // Button handlers - /////////////////////////////////////////////////////////////////////////////////////////// - - public void onPaymentDone(ActionEvent actionEvent) - { - accordion.setExpandedPane(addBankAccountPane); - } - - public void onSkipPayment(ActionEvent actionEvent) - { - accordion.setExpandedPane(addBankAccountPane); - } - - public void onAddBankAccount(ActionEvent actionEvent) - { - addBankAccount(); - storage.write(user.getClass().getName(), user); - - if (verifyBankAccountData()) - { - bankAccountTypesComboBox.getSelectionModel().clearSelection(); - accountPrimaryID.setText(""); - accountPrimaryID.setPromptText(""); - accountSecondaryID.setText(""); - accountSecondaryID.setPromptText(""); - } - } - - public void onCreateAccount(ActionEvent actionEvent) - { - addBankAccount(); - if (user.getBankAccounts().size() > 0) - { - try - { - walletFacade.publishRegistrationTxWithExtraData(user.getStringifiedBankAccounts()); - user.setAccountID(walletFacade.getRegistrationAddress().toString()); - user.setMessagePubKeyAsHex(DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey())); - - storage.write(user.getClass().getName(), user); - - accordion.setExpandedPane(settingsPane); - } catch (InsufficientMoneyException e1) - { - Popups.openErrorPopup("Not enough money available", "There is not enough money available. Please pay in first to your wallet."); - } - } - } - - public void onSkipBankAccountSetup(ActionEvent actionEvent) - { - accordion.setExpandedPane(settingsPane); - } - - public void onClose(ActionEvent actionEvent) - { - navigationController.navigateToView(NavigationController.FUNDS); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Screens setup - /////////////////////////////////////////////////////////////////////////////////////////// - - private void setupRegistrationScreen() - { - payRegFeeInfoLabel.setText("You need to pay 0.01 BTC to the registration address.\n\n" + - "That payment will be used to create a unique account connected with your bank account number.\n" + - "The privacy of your bank account number will be protected and only revealed to your trading partners.\n" + - "The payment will be spent to miners and is needed to store data into the blockchain.\n" + - "Your trading account will be the source for your reputation in the trading platform.\n\n" + - "You need at least 1 confirmation for doing the registration payment."); - - String registrationAddress = walletFacade.getRegistrationAddress().toString(); - registrationAddressTextField.setText(registrationAddress); - - copyIcon.setId("copy-icon"); - AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY); - Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard")); - copyIcon.setOnMouseClicked(e -> { - Clipboard clipboard = Clipboard.getSystemClipboard(); - ClipboardContent content = new ClipboardContent(); - content.putString(registrationAddress); - clipboard.setContent(content); - }); - - confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, balanceTextField, progressIndicator); - paymentDoneButton.setDisable(walletFacade.getRegistrationBalance().compareTo(BigInteger.ZERO) == 0); - log.debug("getAccountRegistrationBalance " + walletFacade.getRegistrationBalance().toString()); - walletFacade.getWallet().addEventListener(new WalletEventListener() - { - @Override - public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance) - { - paymentDoneButton.setDisable(newBalance.compareTo(BigInteger.ZERO) == 0); - } - - @Override - public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) - { - } - - @Override - public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance) - { - } - - @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