diff --git a/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java b/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java index 29a185363..4dbc3a5cf 100644 --- a/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java +++ b/convex-gui/src/main/java/convex/gui/components/account/AccountsPanel.java @@ -23,13 +23,16 @@ import convex.core.cvm.State; import convex.core.data.AccountStatus; import convex.core.data.Address; +import convex.core.lang.RT; import convex.gui.actor.AccountWindow; import convex.gui.components.ActionButton; import convex.gui.components.ActionPanel; import convex.gui.components.ConvexTable; import convex.gui.components.renderer.AccountKeyRenderer; +import convex.gui.components.renderer.AddressRenderer; import convex.gui.components.renderer.BalanceRenderer; import convex.gui.components.renderer.CellRenderer; +import convex.gui.components.renderer.StringRenderer; import convex.gui.models.AccountsTableModel; import convex.gui.models.StateModel; import convex.gui.utils.Toolkit; @@ -55,7 +58,7 @@ public AccountsPanel(ConvexLocal convex,StateModel model) { }); { - CellRenderer cr=new CellRenderer(JLabel.LEFT); + AddressRenderer cr=new AddressRenderer(); cr.setToolTipText("Address of the Convex account. This is the unique ID for the account"); cr.setForeground(Color.WHITE); table.getColumnModel().getColumn(0).setCellRenderer(cr); @@ -63,14 +66,18 @@ public AccountsPanel(ConvexLocal convex,StateModel model) { } { - CellRenderer actorRenderer = new CellRenderer(JLabel.LEFT); + CellRenderer actorRenderer = new CellRenderer(JLabel.LEFT) { + @Override public void setValue(Object o) { + super.setValue( RT.bool(o)?"Actor":"User"); + } + }; actorRenderer.setToolTipText("An Actor account is an autonomous agent or code library on the CVM. A User account can be controlled by a user with the correct key pair."); table.getColumnModel().getColumn(1).setPreferredWidth(70); table.getColumnModel().getColumn(1).setCellRenderer(actorRenderer); } { - CellRenderer cr=new CellRenderer(JLabel.RIGHT); + StringRenderer cr=new StringRenderer(JLabel.RIGHT); cr.setToolTipText("Sequence number of the account. This is the total number of user transactions executed."); table.getColumnModel().getColumn(2).setCellRenderer(cr); table.getColumnModel().getColumn(2).setPreferredWidth(60); @@ -84,35 +91,33 @@ public AccountsPanel(ConvexLocal convex,StateModel model) { } { - CellRenderer cr=new CellRenderer(JLabel.LEFT); + StringRenderer cr=new StringRenderer(JLabel.LEFT); cr.setToolTipText("Name of the account in the Convex Registry"); table.getColumnModel().getColumn(4).setPreferredWidth(200); table.getColumnModel().getColumn(4).setCellRenderer(cr); } { - CellRenderer cr=new CellRenderer(JLabel.RIGHT); + StringRenderer cr=new StringRenderer(JLabel.RIGHT); cr.setToolTipText("Size of the account environment"); table.getColumnModel().getColumn(5).setPreferredWidth(100); table.getColumnModel().getColumn(5).setCellRenderer(cr); } { // Memory allowance - CellRenderer cr=new CellRenderer(JLabel.RIGHT); + StringRenderer cr=new StringRenderer(JLabel.RIGHT); cr.setToolTipText("Unused memory allowance of the account"); table.getColumnModel().getColumn(6).setPreferredWidth(100); table.getColumnModel().getColumn(6).setCellRenderer(cr); } { // Account Controller - CellRenderer cr=new CellRenderer(JLabel.LEFT); + AddressRenderer cr=new AddressRenderer(); cr.setToolTipText("Account Controller. May recover, modify or update the controlled account."); cr.setForeground(Color.WHITE); table.getColumnModel().getColumn(7).setPreferredWidth(80); table.getColumnModel().getColumn(7).setCellRenderer(cr); } - - { // Account public key AccountKeyRenderer cr=new AccountKeyRenderer(); cr.setToolTipText("Public key of the account. Used to validate transactions from users."); diff --git a/convex-gui/src/main/java/convex/gui/components/renderer/AddressRenderer.java b/convex-gui/src/main/java/convex/gui/components/renderer/AddressRenderer.java new file mode 100644 index 000000000..615cfda61 --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/components/renderer/AddressRenderer.java @@ -0,0 +1,24 @@ +package convex.gui.components.renderer; + +import javax.swing.JLabel; + +import convex.core.data.Address; +import convex.core.util.Utils; + +@SuppressWarnings("serial") +public class AddressRenderer extends CellRenderer { + + public AddressRenderer(int alignment) { + super(alignment); + } + + public AddressRenderer() { + super(JLabel.LEFT); + } + + @Override + public void setValue(Object o) { + String s=Utils.toString(Address.parse(o)); + super.setValue(s); + } +} diff --git a/convex-gui/src/main/java/convex/gui/components/renderer/CellRenderer.java b/convex-gui/src/main/java/convex/gui/components/renderer/CellRenderer.java index f8ca1e93a..f496f5367 100644 --- a/convex-gui/src/main/java/convex/gui/components/renderer/CellRenderer.java +++ b/convex-gui/src/main/java/convex/gui/components/renderer/CellRenderer.java @@ -14,4 +14,5 @@ public CellRenderer(int alignment) { public void setValue(Object value) { setText(Utils.toString(value)); } + } \ No newline at end of file diff --git a/convex-gui/src/main/java/convex/gui/components/renderer/StringRenderer.java b/convex-gui/src/main/java/convex/gui/components/renderer/StringRenderer.java new file mode 100644 index 000000000..2222d208d --- /dev/null +++ b/convex-gui/src/main/java/convex/gui/components/renderer/StringRenderer.java @@ -0,0 +1,15 @@ +package convex.gui.components.renderer; + +import javax.swing.JLabel; + +@SuppressWarnings("serial") +public class StringRenderer extends CellRenderer { + public StringRenderer(int alignment) { + super(alignment); + } + + public StringRenderer() { + super(JLabel.RIGHT); + } + +} diff --git a/convex-gui/src/main/java/convex/gui/models/AccountsTableModel.java b/convex-gui/src/main/java/convex/gui/models/AccountsTableModel.java index 43e9a810c..633f6aa49 100644 --- a/convex-gui/src/main/java/convex/gui/models/AccountsTableModel.java +++ b/convex-gui/src/main/java/convex/gui/models/AccountsTableModel.java @@ -52,7 +52,7 @@ public Object getValueAt(int rowIndex, int columnIndex) { case 0: return address.toString(); case 1: - return as.isActor()?"Actor":"User"; + return as.isActor(); case 2: { long seq=as.getSequence(); return (seq>=0)?seq:""; diff --git a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java index 2c40846ed..c947f57c0 100644 --- a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java +++ b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakePanel.java @@ -6,6 +6,8 @@ import javax.swing.JScrollPane; import convex.api.Convex; +import convex.gui.components.ActionButton; +import convex.gui.components.ActionPanel; @SuppressWarnings("serial") public class PeerStakePanel extends JPanel { @@ -19,6 +21,10 @@ public PeerStakePanel(Convex convex) { PeerStakeTable peerTable=new PeerStakeTable(convex); add(new JScrollPane(peerTable),BorderLayout.CENTER); + ActionPanel ap=new ActionPanel(); + add(ap,BorderLayout.SOUTH); + + ap.add(new ActionButton("Refresh", 0xe5d5, e->peerTable.refresh()) ); } } diff --git a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakeTable.java b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakeTable.java index f060739a8..0e9df3e59 100644 --- a/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakeTable.java +++ b/convex-gui/src/main/java/convex/gui/peer/stake/PeerStakeTable.java @@ -19,8 +19,8 @@ import convex.core.lang.Reader; import convex.gui.components.ConvexTable; import convex.gui.components.renderer.AccountKeyRenderer; +import convex.gui.components.renderer.AddressRenderer; import convex.gui.components.renderer.BalanceRenderer; -import convex.gui.components.renderer.CellRenderer; @SuppressWarnings("serial") public class PeerStakeTable extends ConvexTable { @@ -47,13 +47,13 @@ public PeerStakeTable(Convex convex) { { // URL String colName="Controller"; tm.addColumn(colName); - TableColumn col=new TableColumn(1,150,new CellRenderer(JLabel.LEFT),null); + TableColumn col=new TableColumn(1,150,new AddressRenderer(JLabel.LEFT),null); col.setHeaderValue(colName); this.getColumnModel().addColumn(col); } { // Stake - String colName="Total Stake"; + String colName="Staked Coins"; tm.addColumn(colName); TableColumn col=new TableColumn(2,300,new BalanceRenderer(),null); col.setHeaderValue(colName); @@ -78,11 +78,13 @@ public boolean isCellEditable(int row, int column) { return false; } - private void refresh() { + void refresh() { + tm.setRowCount(0); String cs=("(mapv (fn [[pk p]] " +"[pk " +" (:controller p)" +" (:balance p) " + +" (:timestamp p) " +" :FOO" +"])" +"(:peers *state*))"); diff --git a/convex-restapi/src/main/java/convex/restapi/RESTServer.java b/convex-restapi/src/main/java/convex/restapi/RESTServer.java index d3ffa1f09..e458fdf86 100644 --- a/convex-restapi/src/main/java/convex/restapi/RESTServer.java +++ b/convex-restapi/src/main/java/convex/restapi/RESTServer.java @@ -34,7 +34,7 @@ import io.javalin.openapi.plugin.OpenApiPlugin; import io.javalin.openapi.plugin.redoc.ReDocPlugin; import io.javalin.openapi.plugin.swagger.SwaggerPlugin; -import io.javalin.util.JavalinBindException; +import io.javalin.util.JavalinException; public class RESTServer implements Closeable { protected static final Logger log = LoggerFactory.getLogger(RESTServer.class.getName()); @@ -48,7 +48,7 @@ private RESTServer(Server server) { this.convex = ConvexLocal.create(server, server.getPeerController(), server.getKeyPair()); } - private Javalin buildApp() { + private Javalin buildApp(boolean useSSL) { SslPlugin sslPlugin = getSSLPlugin(server.getConfig()); Javalin app = Javalin.create(config -> { config.staticFiles.enableWebjars(); @@ -59,7 +59,7 @@ private Javalin buildApp() { }); }); - if (sslPlugin!=null) { + if (useSSL&&(sslPlugin!=null)) { config.registerPlugin(sslPlugin); } @@ -214,15 +214,15 @@ public void start() { public synchronized void start(Integer port) { close(); try { - javalin=buildApp(); + javalin=buildApp(true); start(javalin,port); - } catch (JavalinBindException e) { + } catch (JavalinException e) { if (port!=null) throw e; // only try again if port unspecified log.warn("Specified port "+port+"already in use, chosing another at random"); close(); port=0; // use random port - javalin=buildApp(); + javalin=buildApp(false); start(javalin,port); } }