Skip to content

Commit

Permalink
<feat>(command,jline): add getCandidateList command, fix jline fresh …
Browse files Browse the repository at this point in the history
…bug. (#795)
  • Loading branch information
kyonRay authored Sep 18, 2023
1 parent e140992 commit 1b83f6c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/console/ConsoleInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import console.client.ConsoleClientImpl;
import console.collaboration.CollaborationFace;
import console.collaboration.CollaborationImpl;
import console.command.JlineUtils;
import console.common.ConsoleUtils;
import console.contract.ConsoleContractFace;
import console.contract.ConsoleContractImpl;
Expand Down Expand Up @@ -273,6 +274,8 @@ public void switchGroup(String[] params) {
this.consoleContractFace = new ConsoleContractImpl(client);
this.collaborationFace = new CollaborationImpl(client);
this.authFace = new AuthImpl(client);
JlineUtils.switchGroup(client);
this.lineReader = JlineUtils.getLineReader();
System.out.println("Switched to group " + group + ".");
System.out.println();
} catch (Exception e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/console/client/ConsoleClientFace.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface ConsoleClientFace {

void getSealerList(String[] params) throws IOException;

void getCandidateSealerList(String[] params) throws IOException;

void getSyncStatus(String[] params) throws IOException;

void getConsensusStatus(String[] params) throws IOException;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/console/client/ConsoleClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public void getSealerList(String[] params) throws IOException {
}
}

@Override
public void getCandidateSealerList(String[] params) throws IOException {
String sealers =
client.getNodeListByType(nodeName, "consensus_candidate_sealer")
.getSealerList()
.toString();
if ("[]".equals(sealers)) {
System.out.println("[]");
} else {
ConsoleUtils.printJson(sealers);
}
}

@Override
public void getSyncStatus(String[] params) throws IOException {
ConsoleUtils.printJson(client.getSyncStatus(nodeName).getSyncStatus().toString());
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/console/command/JlineUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jline.reader.Completer;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.impl.LineReaderImpl;
import org.jline.reader.impl.completer.AggregateCompleter;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.StringsCompleter;
Expand All @@ -43,11 +44,13 @@ public class JlineUtils {
private static AccountCompleter accountCompleter = null;
private static CurrentPathCompleter currentPathCompleter = null;

public static LineReader getLineReader() throws IOException {
return createLineReader(new ArrayList<Completer>());
private static LineReader lineReader = null;

public static LineReader getLineReader() {
return lineReader;
}

public static void switchGroup(Client client) {
public static void switchGroup(Client client) throws IOException {
if (contractAddressCompleter != null) {
contractAddressCompleter.setClient(client);
}
Expand All @@ -60,6 +63,8 @@ public static void switchGroup(Client client) {
if (currentPathCompleter != null) {
currentPathCompleter.setClient(client);
}
List<Completer> completers = generateComplters(client);
((LineReaderImpl) lineReader).setCompleter(new AggregateCompleter(completers));
}

public static void switchPwd(String pwd) {
Expand All @@ -68,6 +73,12 @@ public static void switchPwd(String pwd) {

public static LineReader getLineReader(Client client) throws IOException {

List<Completer> completers = generateComplters(client);
lineReader = createLineReader(completers);
return lineReader;
}

private static List<Completer> generateComplters(Client client) {
List<Completer> completers = new ArrayList<>();

List<String> commands =
Expand Down Expand Up @@ -233,7 +244,7 @@ public static LineReader getLineReader(Client client) throws IOException {
currentPathCompleter,
new StringsCompleterIgnoreCase()));
}
return createLineReader(completers);
return completers;
}

public static LineReader createLineReader(List<Completer> completers) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
(consoleInitializer, params, pwd) ->
consoleInitializer.getConsoleClientFace().getObserverList(params));

public static final CommandInfo GET_CANDIDATE_LIST =
new CommandInfo(
"getCandidateList",
"Query nodeId list for candidate sealer nodes.",
HelpInfo::getCandidateListHelp,
(consoleInitializer, params, pwd) ->
consoleInitializer
.getConsoleClientFace()
.getCandidateSealerList(params));
public static final CommandInfo GET_PBFT_VIEW =
new CommandInfo(
"getPbftView",
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/console/command/model/HelpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public static void getObserverListHelp() {
System.out.println("Usage: \ngetObserverList");
}

public static void getCandidateListHelp() {
System.out.println("Query nodeId list for candidate sealer nodes.");
System.out.println("NOTE: only for the consensus node of the rPBFT algorithm.");
System.out.println("Usage: \ngetCandidateList");
}

public static void getSealerListHelp() {
System.out.println("Query nodeId list for sealer nodes.");
System.out.println("Usage: \ngetSealerList");
Expand Down

0 comments on commit 1b83f6c

Please sign in to comment.