diff --git a/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java b/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java index c5823e23c..58f22fca9 100644 --- a/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/ConnectPanel.java @@ -1,6 +1,7 @@ package convex.gui.components; import java.awt.Color; +import java.awt.Component; import java.net.InetSocketAddress; import javax.swing.JComponent; @@ -16,6 +17,7 @@ import convex.core.crypto.wallet.AWalletEntry; import convex.core.cvm.Address; import convex.core.init.Init; +import convex.core.lang.RT; import convex.gui.components.account.AddressCombo; import convex.gui.keys.KeyRingPanel; import convex.gui.keys.UnlockWalletDialog; @@ -113,4 +115,22 @@ public static Convex tryConnect(JComponent parent,String prompt) { } return null; } + + public static void showConnectionInfo(Component parent,Convex convex) { + StringBuilder sb=new StringBuilder(); + if (convex instanceof ConvexRemote) { + sb.append("Remote host: " + convex.getHostAddress() + "\n"); + } + try { + sb.append("Sequence: " + convex.getSequence() + "\n"); + } catch (Exception e1) { + log.info("Failed to get sequence number"); + } + sb.append("Account: " + RT.print(convex.getAddress()) + "\n"); + sb.append("Public Key: " + RT.toString(convex.getAccountKey()) + "\n"); + sb.append("Connected: " + convex.isConnected()+"\n"); + + String infoString = sb.toString(); + JOptionPane.showMessageDialog(parent, infoString); + } } diff --git a/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java b/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java index d2d2b6152..75b65b9cc 100644 --- a/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/account/AccountChooserPanel.java @@ -21,6 +21,7 @@ import convex.core.data.AccountKey; import convex.core.exceptions.ResultException; import convex.gui.components.BalanceLabel; +import convex.gui.components.ConnectPanel; import convex.gui.components.DropdownMenu; import convex.gui.keys.KeyRingPanel; import convex.gui.keys.UnlockWalletDialog; @@ -43,6 +44,9 @@ public class AccountChooserPanel extends JPanel { private BalanceLabel balanceLabel; protected Convex convex; + + AWalletEntry previousSelection = null; + public AccountChooserPanel(Convex convex) { this.convex=convex; @@ -69,13 +73,11 @@ public AccountChooserPanel(Convex convex) { keyCombo=KeyPairCombo.forConvex(convex); keyCombo.setToolTipText("Select a key pair from your Keyring. This will be used to sign transactions."); keyCombo.addItemListener(e->{ + AWalletEntry we=(AWalletEntry)e.getItem(); if (e.getStateChange()==ItemEvent.DESELECTED) { - // key pair was deselected and/or set to null - setKeyPair(null); + previousSelection=we; return; - }; - AWalletEntry we=(AWalletEntry)e.getItem(); - if (we!=keyCombo.getWalletEntry()) { + } else { setKeyPair(we); } }); @@ -126,7 +128,7 @@ public AccountChooserPanel(Convex convex) { }); popupMenu.add(setSeqButton); - JMenuItem reconnectButton = new JMenuItem("Reconnect",Toolkit.menuIcon(0xe9d5)); + JMenuItem reconnectButton = new JMenuItem("Reconnect",Toolkit.menuIcon(0xe157)); reconnectButton.addActionListener(e -> { try { convex.reconnect(); @@ -135,6 +137,16 @@ public AccountChooserPanel(Convex convex) { } }); popupMenu.add(reconnectButton); + + JMenuItem connInfoButton = new JMenuItem("Connection Info...",Toolkit.menuIcon(0xe157)); + connInfoButton.addActionListener(e -> { + try { + ConnectPanel.showConnectionInfo(this, convex); + } catch (Exception ex) { + log.info("Reconnect failed",ex); + } + }); + popupMenu.add(connInfoButton); @@ -186,6 +198,12 @@ public void updateAddress(Address a) { } public void setKeyPair(AWalletEntry we) { + // In case we are re-entering + if (we!=keyCombo.getWalletEntry()) { + keyCombo.setSelectedItem(we); + return; + } + System.err.println("Setting wallet entry:" +we); if (we==null) { convex.setKeyPair(null); @@ -194,18 +212,16 @@ public void setKeyPair(AWalletEntry we) { if (we.isLocked()) { boolean unlock=UnlockWalletDialog.offerUnlock(this, we); if (!unlock) { - convex.setKeyPair(null); - keyCombo.setSelectedItem(null); + keyCombo.setSelectedItem(previousSelection); return; + } else { + kp=we.getKeyPair(); + we.lock(); } - - kp=we.getKeyPair(); - we.lock(); } else { kp=we.getKeyPair(); } convex.setKeyPair(kp); - keyCombo.setSelectedItem(kp); } } diff --git a/convex-gui/src/main/java/convex/gui/components/account/KeyPairCombo.java b/convex-gui/src/main/java/convex/gui/components/account/KeyPairCombo.java index 9bd341a25..90445accc 100644 --- a/convex-gui/src/main/java/convex/gui/components/account/KeyPairCombo.java +++ b/convex-gui/src/main/java/convex/gui/components/account/KeyPairCombo.java @@ -146,7 +146,7 @@ public static void main (String... args) { } public AWalletEntry getWalletEntry() { - Object a = getSelectedItem(); + Object a = getModel().getSelectedItem(); return (AWalletEntry)a; } diff --git a/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java b/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java index d152856d8..479623ae0 100644 --- a/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java +++ b/convex-gui/src/main/java/convex/gui/peer/PeerComponent.java @@ -7,10 +7,14 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import convex.api.Convex; import convex.api.ConvexLocal; import convex.api.ConvexRemote; import convex.core.crypto.AKeyPair; +import convex.core.crypto.wallet.AWalletEntry; import convex.core.cvm.Address; import convex.core.cvm.Peer; import convex.core.cvm.PeerStatus; @@ -25,6 +29,7 @@ import convex.gui.components.DropdownMenu; import convex.gui.components.Identicon; import convex.gui.etch.EtchWindow; +import convex.gui.keys.KeyRingPanel; import convex.gui.models.StateModel; import convex.gui.repl.REPLClient; import convex.gui.server.PeerWindow; @@ -40,12 +45,31 @@ public class PeerComponent extends BaseListComponent { public ConvexLocal convex; CodeLabel description; + + private static final Logger log = LoggerFactory.getLogger(PeerComponent.class.getName()); + public void launchPeerWindow(ConvexLocal peer) { - PeerWindow pw = new PeerWindow(peer); + Server server=peer.getLocalServer(); + ConvexLocal newConvex=connectLocalControllerWallet(server); + PeerWindow pw = new PeerWindow(newConvex); pw.run(); } + private ConvexLocal connectLocalControllerWallet(Server server) { + AKeyPair kp=null; + Address controller=server.getPeerController(); + if (controller!=null) try { + AccountKey key=server.getPeer().getConsensusState().getAccount(controller).getAccountKey(); + AWalletEntry we=KeyRingPanel.getKeyRingEntry(key); + kp=we.getKeyPair(); + } catch (Exception e) { + log.warn("Error getting controller details",e); + } + ConvexLocal convex=ConvexLocal.connect(server,controller,kp); + return convex; + } + public void launchEtchWindow(ConvexLocal peer) { EtchWindow ew = new EtchWindow(peer); ew.run(); @@ -139,7 +163,7 @@ public PeerComponent(ConvexLocal value) { JMenuItem walletButton = new JMenuItem("Open controller Wallet",Toolkit.menuIcon(0xe850)); walletButton.addActionListener(e -> { - new WalletApp(convex).run(); + new WalletApp(connectLocalControllerWallet(server)).run(); }); popupMenu.add(walletButton); diff --git a/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java b/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java index e3e867d20..4695bf627 100644 --- a/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java +++ b/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java @@ -12,7 +12,6 @@ import javax.swing.JButton; import javax.swing.JCheckBox; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; @@ -27,26 +26,26 @@ import org.slf4j.LoggerFactory; import convex.api.Convex; -import convex.api.ConvexRemote; import convex.core.Result; import convex.core.crypto.AKeyPair; +import convex.core.cvm.Address; +import convex.core.cvm.Symbols; import convex.core.cvm.transactions.ATransaction; import convex.core.data.ACell; import convex.core.data.AList; import convex.core.data.AString; import convex.core.data.AVector; -import convex.core.cvm.Address; import convex.core.data.SignedData; import convex.core.exceptions.ParseException; import convex.core.exceptions.ResultException; import convex.core.lang.RT; import convex.core.lang.Reader; -import convex.core.cvm.Symbols; import convex.core.util.Utils; import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; import convex.gui.components.BaseTextPane; import convex.gui.components.CodePane; +import convex.gui.components.ConnectPanel; import convex.gui.components.account.AccountChooserPanel; import convex.gui.utils.CVXHighlighter; import convex.gui.utils.Toolkit; @@ -211,21 +210,7 @@ public REPLPanel(Convex convex) { actionPanel.add(btnClear); btnInfo = new ActionButton("Connection Info",0xe88e,e -> { - StringBuilder sb=new StringBuilder(); - if (convex instanceof ConvexRemote) { - sb.append("Remote host: " + convex.getHostAddress() + "\n"); - } - try { - sb.append("Sequence: " + convex.getSequence() + "\n"); - } catch (Exception e1) { - log.info("Failed to get sequence number"); - } - sb.append("Account: " + RT.print(convex.getAddress()) + "\n"); - sb.append("Public Key: " + RT.toString(convex.getAccountKey()) + "\n"); - sb.append("Connected: " + convex.isConnected()+"\n"); - - String infoString = sb.toString(); - JOptionPane.showMessageDialog(this, infoString); + ConnectPanel.showConnectionInfo(REPLPanel.this,convex); }); actionPanel.setToolTipText("Show diagnostic information for the Convex connection"); actionPanel.add(btnInfo); diff --git a/convex-gui/src/main/java/convex/gui/server/PeerWindow.java b/convex-gui/src/main/java/convex/gui/server/PeerWindow.java index 7c4875d83..5f3ed3259 100644 --- a/convex-gui/src/main/java/convex/gui/server/PeerWindow.java +++ b/convex-gui/src/main/java/convex/gui/server/PeerWindow.java @@ -33,19 +33,19 @@ public Convex getPeerView() { JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); - public PeerWindow(ConvexLocal peer) { - super("Peer Control Panel - " + peer.toString()); - this.peer = peer; + public PeerWindow(ConvexLocal convex) { + super("Peer Control Panel - " + convex.toString()); + this.peer = convex; this.setPreferredSize(new Dimension(1200,1000)); setLayout(new MigLayout()); add(tabbedPane, "dock center"); - Server server=peer.getLocalServer(); + Server server=convex.getLocalServer(); if (server!=null) { try { // Convex convex = Convex.connect(server.getHostAddress(), server.getPeerController(),server.getKeyPair()); - tabbedPane.addTab("REPL", null, new REPLPanel(peer), null); + tabbedPane.addTab("REPL", null, new REPLPanel(convex), null); } catch (Exception t) { String msg=("Failed to connect to Peer: "+t); t.printStackTrace(); @@ -55,10 +55,10 @@ public PeerWindow(ConvexLocal peer) { } tabbedPane.addTab("Observation", null, new JScrollPane(new ObserverPanel(server)), null); } - tabbedPane.addTab("Stress", null, new StressPanel(peer), null); - tabbedPane.addTab("Info", null, new PeerInfoPanel(peer), null); + tabbedPane.addTab("Stress", null, new StressPanel(convex), null); + tabbedPane.addTab("Info", null, new PeerInfoPanel(convex), null); - PeerComponent pcom = new PeerComponent(peer); + PeerComponent pcom = new PeerComponent(convex); add(pcom, "dock north"); } diff --git a/convex-peer/src/main/java/convex/peer/Server.java b/convex-peer/src/main/java/convex/peer/Server.java index f87a76dcc..26aff38fe 100644 --- a/convex-peer/src/main/java/convex/peer/Server.java +++ b/convex-peer/src/main/java/convex/peer/Server.java @@ -481,7 +481,7 @@ public long getBeliefReceivedCount() { /** * Gets the Peer controller Address - * @return Peer controller Address + * @return Peer controller Address, or null if peer is not registered */ public Address getPeerController() { return getPeer().getController();