Remove TomP2P dependency in ArbitratorBrowser

This commit is contained in:
Manfred Karrer 2014-09-26 09:57:17 +02:00
parent d207b65cc7
commit a7e6fd96c7
10 changed files with 57 additions and 282 deletions

View File

@ -183,7 +183,7 @@ public class AddressTextField extends AnchorPane {
this.paymentLabel.set(paymentLabel); this.paymentLabel.set(paymentLabel);
} }
// TODO find better solution // TODO find better solution without OverlayManager dependency
public void setOverlayManager(OverlayManager overlayManager) { public void setOverlayManager(OverlayManager overlayManager) {
this.overlayManager = overlayManager; this.overlayManager = overlayManager;
} }

View File

@ -1,233 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.gui.components;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import com.google.bitcoin.core.Coin;
import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.TransactionConfidence;
import com.google.bitcoin.core.Wallet;
import com.google.bitcoin.core.WalletEventListener;
import com.google.bitcoin.script.Script;
import java.util.List;
import java.util.Set;
import javafx.scene.control.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO in new design not used anymore
@Deprecated
public class ConfidenceDisplay {
private static final Logger log = LoggerFactory.getLogger(ConfidenceDisplay.class);
private final WalletEventListener walletEventListener;
private final Wallet wallet;
private final Label confirmationLabel;
private TextField balanceTextField;
private Transaction transaction;
private final ConfidenceProgressIndicator progressIndicator;
public ConfidenceDisplay(Wallet wallet, Label confirmationLabel, TextField balanceTextField,
ConfidenceProgressIndicator progressIndicator) {
this.wallet = wallet;
this.confirmationLabel = confirmationLabel;
this.balanceTextField = balanceTextField;
this.progressIndicator = progressIndicator;
balanceTextField.setText("");
confirmationLabel.setVisible(false);
progressIndicator.setVisible(false);
progressIndicator.setProgress(0);
updateBalance(wallet.getBalance());
walletEventListener = new WalletEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
updateBalance(newBalance);
// log.debug("onCoinsReceived " + newBalance);
}
@Override
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
updateBalance(newBalance);
}
@Override
public void onReorganize(Wallet wallet) {
}
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) {
updateConfidence(tx);
// log.debug("onTransactionConfidenceChanged tx " + tx.getHashAsString());
}
@Override
public void onWalletChanged(Wallet wallet) {
}
@Override
public void onScriptsAdded(Wallet wallet, List<Script> scripts) {
}
@Override
public void onKeysAdded(List<ECKey> keys) {
}
};
wallet.addEventListener(walletEventListener);
}
public ConfidenceDisplay(Wallet wallet, Label confirmationLabel, final Transaction transaction,
ConfidenceProgressIndicator progressIndicator) {
this.wallet = wallet;
this.confirmationLabel = confirmationLabel;
this.transaction = transaction;
this.progressIndicator = progressIndicator;
confirmationLabel.setVisible(false);
progressIndicator.setVisible(false);
progressIndicator.setProgress(0);
updateBalance(wallet.getBalance());
updateConfidence(transaction);
walletEventListener = new WalletEventListener() {
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
if (tx.getHashAsString().equals(transaction.getHashAsString())) {
updateBalance(newBalance);
}
// log.debug("onCoinsReceived " + newBalance);
}
@Override
public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
if (tx.getHashAsString().equals(transaction.getHashAsString())) {
updateBalance(newBalance);
}
}
@Override
public void onReorganize(Wallet wallet) {
}
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx) {
if (tx.getHashAsString().equals(transaction.getHashAsString())) {
updateConfidence(transaction);
}
// log.debug("onTransactionConfidenceChanged newTransaction " + newTransaction.getHashAsString());
}
@Override
public void onWalletChanged(Wallet wallet) {
}
@Override
public void onScriptsAdded(Wallet wallet, List<Script> scripts) {
}
@Override
public void onKeysAdded(List<ECKey> keys) {
}
};
wallet.addEventListener(walletEventListener);
}
public void destroy() {
wallet.removeEventListener(walletEventListener);
progressIndicator.setProgress(0);
confirmationLabel.setText("");
if (balanceTextField != null) {
balanceTextField.setText("");
}
}
private void updateBalance(Coin balance) {
if (balance.compareTo(Coin.ZERO) > 0) {
confirmationLabel.setVisible(true);
progressIndicator.setVisible(true);
progressIndicator.setProgress(-1);
Set<Transaction> transactions = wallet.getTransactions(false);
Transaction latestTransaction = null;
for (Transaction transaction : transactions) {
if (latestTransaction != null) {
if (transaction.getUpdateTime().compareTo(latestTransaction.getUpdateTime()) > 0) {
latestTransaction = transaction;
}
}
else {
latestTransaction = transaction;
}
}
if (latestTransaction != null && (transaction == null ||
latestTransaction.getHashAsString().equals(transaction.getHashAsString()))) {
updateConfidence(latestTransaction);
}
}
if (balanceTextField != null) {
//TODO
balanceTextField.setText(balance.toFriendlyString());
}
}
private void updateConfidence(Transaction tx) {
TransactionConfidence confidence = tx.getConfidence();
double progressIndicatorSize = 50;
switch (confidence.getConfidenceType()) {
case UNKNOWN:
confirmationLabel.setText("");
progressIndicator.setProgress(0);
break;
case PENDING:
confirmationLabel.setText("Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 confirmations");
progressIndicator.setProgress(-1.0);
progressIndicatorSize = 20;
break;
case BUILDING:
confirmationLabel.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
break;
case DEAD:
confirmationLabel.setText("Transaction is invalid.");
break;
}
progressIndicator.setMaxHeight(progressIndicatorSize);
progressIndicator.setPrefHeight(progressIndicatorSize);
progressIndicator.setMaxWidth(progressIndicatorSize);
progressIndicator.setPrefWidth(progressIndicatorSize);
}
}

View File

@ -161,7 +161,7 @@ class MainModel extends UIModel {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void onFacadesInitialised() { private void onFacadesInitialised() {
// TODO Consider to use version from Mike Hearn // TODO Consider to use version sync notification pane from Mike Hearn
walletFacade.addDownloadListener(new WalletFacade.DownloadListener() { walletFacade.addDownloadListener(new WalletFacade.DownloadListener() {
@Override @Override
public void progress(double percent) { public void progress(double percent) {

View File

@ -34,7 +34,6 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.inject.Inject; import javax.inject.Inject;
@ -46,17 +45,10 @@ import javafx.scene.control.*;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.stage.Stage; import javafx.stage.Stage;
import net.tomp2p.peers.Number640;
import net.tomp2p.storage.Data;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* TODO remove tomp2p dependencies
* import net.tomp2p.peers.Number160;
* import net.tomp2p.storage.Data;
* <p>
* Arbitration is not much developed yet * Arbitration is not much developed yet
*/ */
public class ArbitratorBrowserController extends CachedViewController implements ArbitratorListener { public class ArbitratorBrowserController extends CachedViewController implements ArbitratorListener {
@ -147,29 +139,13 @@ public class ArbitratorBrowserController extends CachedViewController implements
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override @Override
public void onArbitratorAdded(Data offerData, boolean success) { public void onArbitratorAdded(Arbitrator arbitrator) {
} }
@Override @Override
public void onArbitratorsReceived(Map<Number640, Data> dataMap, boolean success) { public void onArbitratorsReceived(List<Arbitrator> arbitrators) {
if (success && dataMap != null) { allArbitrators.clear();
allArbitrators.clear(); allArbitrators.addAll(arbitrators);
for (Data arbitratorData : dataMap.values()) {
try {
Object arbitratorDataObject = arbitratorData.object();
if (arbitratorDataObject instanceof Arbitrator) {
Arbitrator arbitrator = (Arbitrator) arbitratorDataObject;
allArbitrators.add(arbitrator);
}
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
}
else {
allArbitrators.clear();
}
if (!allArbitrators.isEmpty()) { if (!allArbitrators.isEmpty()) {
index = 0; index = 0;
@ -180,7 +156,7 @@ public class ArbitratorBrowserController extends CachedViewController implements
} }
@Override @Override
public void onArbitratorRemoved(Data data, boolean success) { public void onArbitratorRemoved(Arbitrator arbitrator) {
} }

View File

@ -22,7 +22,6 @@ import io.bitsquare.arbitrator.Reputation;
import io.bitsquare.btc.WalletFacade; import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController; import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.Navigation; import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.components.ConfidenceDisplay;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator; import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController; import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.BSFormatter;
@ -83,7 +82,6 @@ public class ArbitratorRegistrationController extends CachedViewController {
private List<Arbitrator.ID_VERIFICATION> idVerificationList = new ArrayList<>(); private List<Arbitrator.ID_VERIFICATION> idVerificationList = new ArrayList<>();
private Arbitrator.ID_TYPE idType; private Arbitrator.ID_TYPE idType;
private ConfidenceDisplay confidenceDisplay;
@FXML Accordion accordion; @FXML Accordion accordion;
@FXML TitledPane profileTitledPane, payCollateralTitledPane; @FXML TitledPane profileTitledPane, payCollateralTitledPane;
@ -374,8 +372,6 @@ public class ArbitratorRegistrationController extends CachedViewController {
clipboard.setContent(content); clipboard.setContent(content);
}); });
confidenceDisplay = new ConfidenceDisplay(
walletFacade.getWallet(), confirmationLabel, balanceTextField, progressIndicator);
paymentDoneButton.setDisable(walletFacade.getArbitratorDepositBalance().isZero()); paymentDoneButton.setDisable(walletFacade.getArbitratorDepositBalance().isZero());
log.debug("getArbitratorDepositBalance " + walletFacade.getArbitratorDepositBalance()); log.debug("getArbitratorDepositBalance " + walletFacade.getArbitratorDepositBalance());
walletFacade.getWallet().addEventListener(new WalletEventListener() { walletFacade.getWallet().addEventListener(new WalletEventListener() {

View File

@ -230,7 +230,7 @@ public class PendingTradesPM extends PresentationModel<PendingTradesModel> {
state.set(model.isOfferer() ? State.OFFERER_BUYER_COMPLETED : State.TAKER_SELLER_COMPLETED); state.set(model.isOfferer() ? State.OFFERER_BUYER_COMPLETED : State.TAKER_SELLER_COMPLETED);
break; break;
case FAILED: case FAILED:
// TODO // TODO error states not implemented yet
break; break;
default: default:
log.warn("unhandled state " + state); log.warn("unhandled state " + state);

View File

@ -138,7 +138,7 @@ public class PendingTradesViewCB extends CachedViewCB<PendingTradesPM> {
table.getSelectionModel().select(presentationModel.getSelectedItem()); table.getSelectionModel().select(presentationModel.getSelectedItem());
table.getSelectionModel().selectedItemProperty().addListener(selectedItemChangeListener); table.getSelectionModel().selectedItemProperty().addListener(selectedItemChangeListener);
// TODO Set focus does not work yet... // TODO Set focus to row does not work yet...
/* table.requestFocus(); /* table.requestFocus();
table.getFocusModel().focus( table.getSelectionModel().getSelectedIndex());*/ table.getFocusModel().focus( table.getSelectionModel().getSelectedIndex());*/
@ -371,7 +371,7 @@ public class PendingTradesViewCB extends CachedViewCB<PendingTradesPM> {
} }
private void onFault(Throwable fault) { private void onFault(Throwable fault) {
// TODO // TODO error handling not implemented yet
if (fault != null) if (fault != null)
log.error(fault.toString()); log.error(fault.toString());
} }

View File

@ -184,7 +184,7 @@ class OrderBookModel extends UIModel {
"\n\nThe country of your payments account (" + user.getCurrentBankAccount().getCountry().getName() + "\n\nThe country of your payments account (" + user.getCurrentBankAccount().getCountry().getName() +
") is not included in that list."); ") is not included in that list.");
// TODO Leave that for now as it is not so clear how the restrictions will be handled // TODO Not so clear how the restrictions will be handled
// we might get rid of languages (handles viy arbitrators) // we might get rid of languages (handles viy arbitrators)
/* /*
// disjoint returns true if the two specified collections have no elements in common. // disjoint returns true if the two specified collections have no elements in common.

View File

@ -349,7 +349,18 @@ public class MessageFacade implements MessageBroker {
@Override @Override
public void operationComplete(BaseFuture future) throws Exception { public void operationComplete(BaseFuture future) throws Exception {
Platform.runLater(() -> arbitratorListeners.stream().forEach(listener -> Platform.runLater(() -> arbitratorListeners.stream().forEach(listener ->
listener.onArbitratorAdded(arbitratorData, addFuture.isSuccess()))); {
try {
Object arbitratorDataObject = arbitratorData.object();
if (arbitratorDataObject instanceof Arbitrator) {
listener.onArbitratorAdded((Arbitrator) arbitratorDataObject);
}
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
log.error(e.toString());
}
}));
if (addFuture.isSuccess()) { if (addFuture.isSuccess()) {
log.trace("Add arbitrator to DHT was successful. Stored data: [key: " + locationKey + ", " + log.trace("Add arbitrator to DHT was successful. Stored data: [key: " + locationKey + ", " +
"values: " + arbitratorData + "]"); "values: " + arbitratorData + "]");
@ -372,7 +383,19 @@ public class MessageFacade implements MessageBroker {
@Override @Override
public void operationComplete(BaseFuture future) throws Exception { public void operationComplete(BaseFuture future) throws Exception {
Platform.runLater(() -> arbitratorListeners.stream().forEach(listener -> Platform.runLater(() -> arbitratorListeners.stream().forEach(listener ->
listener.onArbitratorRemoved(arbitratorData, removeFuture.isSuccess()))); {
for (Data arbitratorData : removeFuture.dataMap().values()) {
try {
Object arbitratorDataObject = arbitratorData.object();
if (arbitratorDataObject instanceof Arbitrator) {
Arbitrator arbitrator = (Arbitrator) arbitratorDataObject;
listener.onArbitratorRemoved(arbitrator);
}
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
}));
if (removeFuture.isSuccess()) { if (removeFuture.isSuccess()) {
log.trace("Remove arbitrator from DHT was successful. Stored data: [key: " + locationKey + ", " + log.trace("Remove arbitrator from DHT was successful. Stored data: [key: " + locationKey + ", " +
"values: " + arbitratorData + "]"); "values: " + arbitratorData + "]");
@ -390,8 +413,22 @@ public class MessageFacade implements MessageBroker {
futureGet.addListener(new BaseFutureAdapter<BaseFuture>() { futureGet.addListener(new BaseFutureAdapter<BaseFuture>() {
@Override @Override
public void operationComplete(BaseFuture baseFuture) throws Exception { public void operationComplete(BaseFuture baseFuture) throws Exception {
Platform.runLater(() -> arbitratorListeners.stream().forEach(listener -> listener Platform.runLater(() -> arbitratorListeners.stream().forEach(listener ->
.onArbitratorsReceived(futureGet.dataMap(), baseFuture.isSuccess()))); {
List<Arbitrator> arbitrators = new ArrayList<>();
for (Data arbitratorData : futureGet.dataMap().values()) {
try {
Object arbitratorDataObject = arbitratorData.object();
if (arbitratorDataObject instanceof Arbitrator) {
arbitrators.add((Arbitrator) arbitratorDataObject);
}
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
}
listener.onArbitratorsReceived(arbitrators);
}));
if (baseFuture.isSuccess()) { if (baseFuture.isSuccess()) {
log.trace("Get arbitrators from DHT was successful. Stored data: [key: " + locationKey + ", " + log.trace("Get arbitrators from DHT was successful. Stored data: [key: " + locationKey + ", " +
"values: " + futureGet.dataMap() + "]"); "values: " + futureGet.dataMap() + "]");

View File

@ -17,16 +17,15 @@
package io.bitsquare.msg.listeners; package io.bitsquare.msg.listeners;
import java.util.Map; import io.bitsquare.arbitrator.Arbitrator;
import net.tomp2p.peers.Number640; import java.util.List;
import net.tomp2p.storage.Data;
// Arbitration is not much developed yet // Arbitration is not much developed yet
public interface ArbitratorListener { public interface ArbitratorListener {
void onArbitratorAdded(Data offerData, boolean success); void onArbitratorAdded(Arbitrator arbitrator);
void onArbitratorsReceived(Map<Number640, Data> dataMap, boolean success); void onArbitratorsReceived(List<Arbitrator> arbitrators);
void onArbitratorRemoved(Data data, boolean success); void onArbitratorRemoved(Arbitrator arbitrator);
} }