Skip to content

Commit

Permalink
GUI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 21, 2024
1 parent d99ed3f commit 628656e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import javax.swing.JPanel;
import javax.swing.JPopupMenu;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import convex.api.Convex;
import convex.core.crypto.AKeyPair;
import convex.core.crypto.wallet.AWalletEntry;
import convex.core.cvm.ops.Special;
import convex.core.data.AccountKey;
import convex.core.cvm.Address;
import convex.core.cvm.Symbols;
import convex.core.cvm.ops.Special;
import convex.core.data.AccountKey;
import convex.core.exceptions.ResultException;
import convex.gui.components.BalanceLabel;
import convex.gui.components.DropdownMenu;
Expand All @@ -29,6 +32,9 @@
*/
@SuppressWarnings("serial")
public class AccountChooserPanel extends JPanel {

private static final Logger log = LoggerFactory.getLogger(AccountChooserPanel.class.getName());


private JComboBox<String> modeCombo;
public final AddressCombo addressCombo;
Expand Down Expand Up @@ -119,6 +125,17 @@ public AccountChooserPanel(Convex convex) {
convex.clearSequence();
});
popupMenu.add(setSeqButton);

JMenuItem reconnectButton = new JMenuItem("Reconnect",Toolkit.menuIcon(0xe9d5));
reconnectButton.addActionListener(e -> {
try {
convex.reconnect();
} catch (Exception ex) {
log.info("Reconnect failed",ex);
}
});
popupMenu.add(reconnectButton);



DropdownMenu dm = new DropdownMenu(popupMenu,Toolkit.SMALL_ICON_SIZE);
Expand Down Expand Up @@ -169,6 +186,7 @@ public void updateAddress(Address a) {
}

public void setKeyPair(AWalletEntry we) {
System.err.println("Setting wallet entry:" +we);
if (we==null) {
convex.setKeyPair(null);
} else {
Expand Down
2 changes: 1 addition & 1 deletion convex-gui/src/main/java/convex/gui/repl/REPLPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private void sendMessage(String s) {
output.append(" TIMEOUT waiting for result\n",Color.RED);
} catch (IllegalStateException t) {
// General errors we understand
output.append(" ERROR: ",Color.RED);
output.append(" EXCEPTION: ",Color.RED);
output.append(t.getMessage() + "\n");
} catch (Exception t) {
// Something bad.....
Expand Down
7 changes: 7 additions & 0 deletions convex-java/src/main/java/convex/java/ConvexHTTP.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package convex.java;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;

import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
Expand Down Expand Up @@ -182,4 +184,9 @@ public InetSocketAddress getHostAddress() {
return new InetSocketAddress(uri.getHost(),port);
}

@Override
public void reconnect() throws IOException, TimeoutException, InterruptedException {
// Nothing to do?
}

}
2 changes: 2 additions & 0 deletions convex-peer/src/main/java/convex/api/Convex.java
Original file line number Diff line number Diff line change
Expand Up @@ -1027,4 +1027,6 @@ public void clearSequence() {
this.sequence=null;
}

public abstract void reconnect() throws IOException, TimeoutException, InterruptedException;

}
6 changes: 6 additions & 0 deletions convex-peer/src/main/java/convex/api/ConvexLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;

import convex.core.ErrorCodes;
Expand Down Expand Up @@ -210,6 +211,11 @@ public Long getBalance() {
return server.getPeer().getConsensusState().getBalance(address);
}

@Override
public void reconnect() {
// Always connected, basically
}



}
5 changes: 3 additions & 2 deletions convex-peer/src/main/java/convex/peer/TransactionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ void maybeGetOwnTransactions(Peer p) {

// If we already posted own transaction recently, don't try again
if (ts<(lastOwnTransactionTimestamp+OWN_BLOCK_DELAY)) return;
lastOwnTransactionTimestamp=ts; // mark this timestamp

// NOTE: beyond this point we only execute stuff when AUTO_MANAGE is set
if (!Utils.bool(server.getConfig().get(Keywords.AUTO_MANAGE))) return;
Expand All @@ -410,7 +409,8 @@ void maybeGetOwnTransactions(Peer p) {
AccountKey peerKey=p.getPeerKey();
PeerStatus ps=s.getPeer(peerKey);
if (ps==null) return; // No peer record in consensus state?



AString chn=ps.getHostname();
String currentHostname=(chn==null)?null:chn.toString();
String desiredHostname=server.getHostname(); // Intended hostname
Expand All @@ -432,6 +432,7 @@ void maybeGetOwnTransactions(Peer p) {
ACell message = Reader.read(code);
ATransaction transaction = Invoke.create(address, as.getSequence()+1, message);
newTransactions.add(p.getKeyPair().signData(transaction));
lastOwnTransactionTimestamp=ts; // mark this timestamp
}
}

Expand Down

0 comments on commit 628656e

Please sign in to comment.