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 a50ecc6e0..d2d2b6152 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 @@ -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; @@ -29,6 +32,9 @@ */ @SuppressWarnings("serial") public class AccountChooserPanel extends JPanel { + + private static final Logger log = LoggerFactory.getLogger(AccountChooserPanel.class.getName()); + private JComboBox modeCombo; public final AddressCombo addressCombo; @@ -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); @@ -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 { 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 fc50c5109..e3e867d20 100644 --- a/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java +++ b/convex-gui/src/main/java/convex/gui/repl/REPLPanel.java @@ -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..... diff --git a/convex-java/src/main/java/convex/java/ConvexHTTP.java b/convex-java/src/main/java/convex/java/ConvexHTTP.java index 687f1757f..3c8201f2b 100644 --- a/convex-java/src/main/java/convex/java/ConvexHTTP.java +++ b/convex-java/src/main/java/convex/java/ConvexHTTP.java @@ -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; @@ -182,4 +184,9 @@ public InetSocketAddress getHostAddress() { return new InetSocketAddress(uri.getHost(),port); } + @Override + public void reconnect() throws IOException, TimeoutException, InterruptedException { + // Nothing to do? + } + } diff --git a/convex-peer/src/main/java/convex/api/Convex.java b/convex-peer/src/main/java/convex/api/Convex.java index fc9f473e7..c4af48b11 100644 --- a/convex-peer/src/main/java/convex/api/Convex.java +++ b/convex-peer/src/main/java/convex/api/Convex.java @@ -1027,4 +1027,6 @@ public void clearSequence() { this.sequence=null; } + public abstract void reconnect() throws IOException, TimeoutException, InterruptedException; + } diff --git a/convex-peer/src/main/java/convex/api/ConvexLocal.java b/convex-peer/src/main/java/convex/api/ConvexLocal.java index f64244a8d..a5d441d5c 100644 --- a/convex-peer/src/main/java/convex/api/ConvexLocal.java +++ b/convex-peer/src/main/java/convex/api/ConvexLocal.java @@ -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; @@ -210,6 +211,11 @@ public Long getBalance() { return server.getPeer().getConsensusState().getBalance(address); } + @Override + public void reconnect() { + // Always connected, basically + } + } diff --git a/convex-peer/src/main/java/convex/peer/TransactionHandler.java b/convex-peer/src/main/java/convex/peer/TransactionHandler.java index 3e4f54333..d8d0e2334 100644 --- a/convex-peer/src/main/java/convex/peer/TransactionHandler.java +++ b/convex-peer/src/main/java/convex/peer/TransactionHandler.java @@ -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; @@ -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 @@ -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 } }