mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 23:56:30 -04:00
Add btc peers to list in UI
This commit is contained in:
parent
67fb7aa825
commit
16baa3ec8d
@ -31,7 +31,7 @@ public final class Arbitrator implements PubKeyProtectedExpirablePayload {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
|
||||
public static final long TTL = 10 * 24 * 60 * 60 * 1000; // 10 days
|
||||
public static final long TTL = 1 * 24 * 60 * 60 * 1000; // 1 day
|
||||
|
||||
// Persisted fields
|
||||
private final byte[] btcPubKey;
|
||||
|
@ -89,6 +89,7 @@ public class WalletService {
|
||||
private Wallet wallet;
|
||||
private AddressEntry arbitratorAddressEntry;
|
||||
private final IntegerProperty numPeers = new SimpleIntegerProperty(0);
|
||||
private final ObjectProperty<List<Peer>> connectedPeers = new SimpleObjectProperty<>();
|
||||
public final BooleanProperty shutDownDone = new SimpleBooleanProperty();
|
||||
|
||||
|
||||
@ -107,7 +108,7 @@ public class WalletService {
|
||||
// TODO remove after sufficient testing with testnet
|
||||
checkArgument(!params.getId().equals(NetworkParameters.ID_MAINNET),
|
||||
"Mainnet is not allowed to be used at that stage of development");
|
||||
|
||||
|
||||
this.walletDir = new File(walletDir, "bitcoin");
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
@ -165,11 +166,13 @@ public class WalletService {
|
||||
@Override
|
||||
public void onPeerConnected(Peer peer, int peerCount) {
|
||||
numPeers.set(peerCount);
|
||||
connectedPeers.set(walletAppKit.peerGroup().getConnectedPeers());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPeerDisconnected(Peer peer, int peerCount) {
|
||||
numPeers.set(peerCount);
|
||||
connectedPeers.set(walletAppKit.peerGroup().getConnectedPeers());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -506,6 +509,10 @@ public class WalletService {
|
||||
return numPeers;
|
||||
}
|
||||
|
||||
public ReadOnlyObjectProperty<List<Peer>> connectedPeersProperty() {
|
||||
return connectedPeers;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private methods
|
||||
|
@ -48,20 +48,18 @@ public class Preferences implements Serializable {
|
||||
// Deactivate mBit for now as most screens are not supporting it yet
|
||||
transient private static final List<String> BTC_DENOMINATIONS = Arrays.asList(MonetaryFormat.CODE_BTC/*, MonetaryFormat.CODE_MBTC*/);
|
||||
transient static final private ArrayList<BlockChainExplorer> blockChainExplorersTestNet = new ArrayList<>(Arrays.asList(
|
||||
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/testnet/transactions/", "https://www.biteasy.com/testnet/addresses/"),
|
||||
new BlockChainExplorer("Blocktrail", "https://www.blocktrail.com/tBTC/tx/", "https://www.blocktrail.com/tBTC/address/"),
|
||||
new BlockChainExplorer("Blockr.io", "https://tbtc.blockr.io/tx/info/", "https://tbtc.blockr.io/address/info/"),
|
||||
new BlockChainExplorer("Web BTC", "http://test.webbtc.com/tx/", "http://test.webbtc.com/address/"),
|
||||
new BlockChainExplorer("Blockexplorer", "https://blockexplorer.com/testnet/tx/", "https://blockexplorer.com/testnet/address/"),
|
||||
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/testnet/transactions/", "https://www.biteasy.com/testnet/addresses/")
|
||||
new BlockChainExplorer("Blockexplorer", "https://blockexplorer.com/testnet/tx/", "https://blockexplorer.com/testnet/address/")
|
||||
));
|
||||
|
||||
transient static final private ArrayList<BlockChainExplorer> blockChainExplorersMainNet = new ArrayList<>(Arrays.asList(
|
||||
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/transactions/", "https://www.biteasy.com/addresses/"),
|
||||
new BlockChainExplorer("Blockchain.info", "https://blockchain.info/tx/", "https://blockchain.info/address/"),
|
||||
new BlockChainExplorer("Blocktrail", "https://www.blocktrail.com/BTC/tx/", "https://www.blocktrail.com/BTC/address/"),
|
||||
new BlockChainExplorer("Blockr.io", "https://btc.blockr.io/tx/info/", "https://btc.blockr.io/address/info/"),
|
||||
new BlockChainExplorer("Web BTC", "http://webbtc.com/tx/", "http://webbtc.com/address/"),
|
||||
new BlockChainExplorer("Blockexplorer", "https://blockexplorer.com/tx/", "https://blockexplorer.com/address/"),
|
||||
new BlockChainExplorer("Biteasy", "https://www.biteasy.com/transactions/", "https://www.biteasy.com/addresses/")
|
||||
new BlockChainExplorer("Blockexplorer", "https://blockexplorer.com/tx/", "https://blockexplorer.com/address/")
|
||||
));
|
||||
|
||||
public static List<String> getBtcDenominations() {
|
||||
|
@ -28,6 +28,7 @@ import io.bitsquare.gui.util.Layout;
|
||||
import io.bitsquare.locale.LanguageUtil;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.geometry.HPos;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.*;
|
||||
@ -187,6 +188,8 @@ public class ArbitratorSelectionView extends ActivatableViewAndModel<GridPane, A
|
||||
root.getChildren().add(table);
|
||||
|
||||
autoSelectAllMatchingCheckBox = addCheckBox(root, ++gridRow, "Auto select all with matching language");
|
||||
GridPane.setColumnSpan(autoSelectAllMatchingCheckBox, 2);
|
||||
GridPane.setHalignment(autoSelectAllMatchingCheckBox, HPos.LEFT);
|
||||
GridPane.setColumnIndex(autoSelectAllMatchingCheckBox, 0);
|
||||
GridPane.setMargin(autoSelectAllMatchingCheckBox, new Insets(0, -10, 0, -10));
|
||||
autoSelectAllMatchingCheckBox.setOnAction(event -> model.setAutoSelectArbitrators(autoSelectAllMatchingCheckBox.isSelected()));
|
||||
|
@ -33,24 +33,13 @@
|
||||
|
||||
<TitledGroupBg text="Bitcoin network" GridPane.rowSpan="3"/>
|
||||
|
||||
<Label text="Bitcoin network type:" GridPane.rowIndex="0">
|
||||
<GridPane.margin>
|
||||
<Insets top="10"/>
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField fx:id="bitcoinNetwork" GridPane.rowIndex="0" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false">
|
||||
<GridPane.margin>
|
||||
<Insets top="10"/>
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
<Label text="Select Network:" GridPane.rowIndex="0"/>
|
||||
<ComboBox fx:id="netWorkComboBox" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="Select Network:" GridPane.rowIndex="1"/>
|
||||
<ComboBox fx:id="netWorkComboBox" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="bitcoinPeersLabel" text="Connected peers:" GridPane.rowIndex="1"/>
|
||||
<TextArea fx:id="bitcoinPeersTextArea" GridPane.rowIndex="1" GridPane.columnIndex="1"
|
||||
editable="false" focusTraversable="false"/>
|
||||
|
||||
<Label text="Bitcoin network connected peers:" GridPane.rowIndex="2"/>
|
||||
<TextField fx:id="connectedPeersBTC" GridPane.rowIndex="2" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<TitledGroupBg text="P2P network" GridPane.rowIndex="3" GridPane.rowSpan="5">
|
||||
<padding>
|
||||
|
@ -42,57 +42,69 @@ import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.StringConverter;
|
||||
import org.bitcoinj.core.Peer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static javafx.beans.binding.Bindings.createStringBinding;
|
||||
|
||||
@FxmlView
|
||||
public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activatable> {
|
||||
|
||||
private final String bitcoinNetworkString;
|
||||
private final WalletService walletService;
|
||||
private final Preferences preferences;
|
||||
private BSFormatter formatter;
|
||||
private final P2PService p2PService;
|
||||
|
||||
|
||||
@FXML
|
||||
TextField bitcoinNetwork, onionAddress, connectedPeersBTC;
|
||||
TextField onionAddress;
|
||||
@FXML
|
||||
ComboBox<BitcoinNetwork> netWorkComboBox;
|
||||
@FXML
|
||||
TextArea authenticatedPeersTextArea;
|
||||
TextArea bitcoinPeersTextArea, authenticatedPeersTextArea;
|
||||
@FXML
|
||||
Label authenticatedPeersLabel;
|
||||
Label bitcoinPeersLabel, authenticatedPeersLabel;
|
||||
|
||||
private P2PServiceListener p2PServiceListener;
|
||||
private ChangeListener<Number> numAuthenticatedPeersChangeListener;
|
||||
private ChangeListener<List<Peer>> bitcoinPeersChangeListener;
|
||||
private Set<Address> seedNodeAddresses;
|
||||
|
||||
@Inject
|
||||
public NetworkSettingsView(WalletService walletService, P2PService p2PService, SeedNodesRepository seedNodesRepository, Preferences preferences, BSFormatter
|
||||
formatter) {
|
||||
public NetworkSettingsView(WalletService walletService, P2PService p2PService, Preferences preferences,
|
||||
SeedNodesRepository seedNodesRepository, BSFormatter formatter) {
|
||||
this.walletService = walletService;
|
||||
this.preferences = preferences;
|
||||
BitcoinNetwork bitcoinNetwork = preferences.getBitcoinNetwork();
|
||||
this.bitcoinNetworkString = formatter.formatBitcoinNetwork(bitcoinNetwork);
|
||||
this.p2PService = p2PService;
|
||||
this.preferences = preferences;
|
||||
this.formatter = formatter;
|
||||
BitcoinNetwork bitcoinNetwork = preferences.getBitcoinNetwork();
|
||||
|
||||
boolean useLocalhost = p2PService.getNetworkNode() instanceof LocalhostNetworkNode;
|
||||
this.seedNodeAddresses = seedNodesRepository.geSeedNodeAddresses(useLocalhost, bitcoinNetwork.ordinal());
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
GridPane.setMargin(bitcoinPeersLabel, new Insets(4, 0, 0, 0));
|
||||
GridPane.setValignment(bitcoinPeersLabel, VPos.TOP);
|
||||
GridPane.setMargin(authenticatedPeersLabel, new Insets(4, 0, 0, 0));
|
||||
GridPane.setValignment(authenticatedPeersLabel, VPos.TOP);
|
||||
bitcoinNetwork.setText(bitcoinNetworkString);
|
||||
connectedPeersBTC.textProperty().bind(createStringBinding(() -> String.valueOf(walletService.numPeersProperty().get()), walletService
|
||||
.numPeersProperty()));
|
||||
|
||||
bitcoinPeersTextArea.setPrefRowCount(12);
|
||||
netWorkComboBox.setItems(FXCollections.observableArrayList(BitcoinNetwork.values()));
|
||||
netWorkComboBox.getSelectionModel().select(preferences.getBitcoinNetwork());
|
||||
netWorkComboBox.setOnAction(e -> onSelectNetwork());
|
||||
netWorkComboBox.setConverter(new StringConverter<BitcoinNetwork>() {
|
||||
@Override
|
||||
public String toString(BitcoinNetwork bitcoinNetwork) {
|
||||
return formatter.formatBitcoinNetwork(bitcoinNetwork);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitcoinNetwork fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,6 +143,10 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
||||
onionAddress.setText(address.getFullAddress());
|
||||
}
|
||||
|
||||
bitcoinPeersChangeListener = (observable, oldValue, newValue) -> updateBitcoinPeersTextArea();
|
||||
walletService.connectedPeersProperty().addListener(bitcoinPeersChangeListener);
|
||||
updateBitcoinPeersTextArea();
|
||||
|
||||
numAuthenticatedPeersChangeListener = (observable, oldValue, newValue) -> updateAuthenticatedPeersTextArea();
|
||||
p2PService.getNumAuthenticatedPeers().addListener(numAuthenticatedPeersChangeListener);
|
||||
updateAuthenticatedPeersTextArea();
|
||||
@ -140,6 +156,10 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
||||
public void deactivate() {
|
||||
if (p2PServiceListener != null)
|
||||
p2PService.removeP2PServiceListener(p2PServiceListener);
|
||||
|
||||
if (bitcoinPeersChangeListener != null)
|
||||
walletService.connectedPeersProperty().removeListener(bitcoinPeersChangeListener);
|
||||
|
||||
if (numAuthenticatedPeersChangeListener != null)
|
||||
p2PService.getNumAuthenticatedPeers().removeListener(numAuthenticatedPeersChangeListener);
|
||||
}
|
||||
@ -155,6 +175,18 @@ public class NetworkSettingsView extends ActivatableViewAndModel<GridPane, Activ
|
||||
});
|
||||
}
|
||||
|
||||
private void updateBitcoinPeersTextArea() {
|
||||
bitcoinPeersTextArea.clear();
|
||||
List<Peer> peerList = walletService.connectedPeersProperty().get();
|
||||
if (peerList != null) {
|
||||
peerList.stream().forEach(e -> {
|
||||
if (bitcoinPeersTextArea.getText().length() > 0)
|
||||
bitcoinPeersTextArea.appendText("\n");
|
||||
bitcoinPeersTextArea.appendText(e.getAddress().getSocketAddress().toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void onSelectNetwork() {
|
||||
if (netWorkComboBox.getSelectionModel().getSelectedItem() != preferences.getBitcoinNetwork()) {
|
||||
if (netWorkComboBox.getSelectionModel().getSelectedItem() == BitcoinNetwork.MAINNET) {
|
||||
|
@ -20,7 +20,7 @@ public abstract class AuthenticationMessage implements Message {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ", address=" + senderAddress.toString() +
|
||||
return ", address=" + (senderAddress != null ? senderAddress.toString() : "") +
|
||||
", networkId=" + networkId +
|
||||
'}';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user