Skip to content

Commit

Permalink
More updates to staking GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Oct 10, 2024
1 parent a87dda0 commit eb1d26f
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,22 +58,26 @@ public AccountsPanel(ConvexLocal convex,StateModel<State> 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);
table.getColumnModel().getColumn(0).setPreferredWidth(80);
}

{
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);
Expand All @@ -84,35 +91,33 @@ public AccountsPanel(ConvexLocal convex,StateModel<State> 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.");
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public CellRenderer(int alignment) {
public void setValue(Object value) {
setText(Utils.toString(value));
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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:"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()) );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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*))");
Expand Down
12 changes: 6 additions & 6 deletions convex-restapi/src/main/java/convex/restapi/RESTServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand All @@ -59,7 +59,7 @@ private Javalin buildApp() {
});
});

if (sslPlugin!=null) {
if (useSSL&&(sslPlugin!=null)) {
config.registerPlugin(sslPlugin);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit eb1d26f

Please sign in to comment.