Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<fix>(precompiled): add switch group after set system version config. #743

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/main/java/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static void main(String[] args) {
keymap.bind(new Reference("beginning-of-line"), "\033[1~");
keymap.bind(new Reference("end-of-line"), "\033[4~");
}
consoleInitializer.setLineReader(lineReader);
} catch (Exception e) {
System.out.println(e.getMessage());
logger.error(" message: {}, e: {}", e.getMessage(), e);
Expand All @@ -66,19 +67,21 @@ public static void main(String[] args) {

while (true) {
try {
if (lineReader == null) {
if (consoleInitializer.getLineReader() == null) {
System.out.println("Console can not read commands.");
break;
}
String request;
if (!consoleInitializer.isDisableAutoCompleter()) {
request =
lineReader.readLine(
"["
+ consoleInitializer.getGroupID()
+ "]: "
+ ConsoleUtils.prettyPwd(pwd)
+ "> ");
consoleInitializer
.getLineReader()
.readLine(
"["
+ consoleInitializer.getGroupID()
+ "]: "
+ ConsoleUtils.prettyPwd(pwd)
+ "> ");
} else {
System.out.print(
"[group:"
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/console/ConsoleInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.fisco.bcos.sdk.v3.crypto.exceptions.LoadKeyStoreException;
import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.v3.model.CryptoType;
import org.jline.reader.LineReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -42,6 +43,15 @@ public class ConsoleInitializer {
private AuthFace authFace;
private CollaborationFace collaborationFace;
private boolean disableAutoCompleter = false;
private LineReader lineReader;

public LineReader getLineReader() {
return lineReader;
}

public void setLineReader(LineReader lineReader) {
this.lineReader = lineReader;
}

public void init(String[] args) throws ConfigException {
AccountInfo accountInfo = null;
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/console/command/category/AuthOpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import console.command.model.CommandType;
import console.command.model.HelpInfo;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class AuthOpCommand extends BasicCategoryCommand {
protected static final Map<String, CommandInfo> commandToCommandInfo = new HashMap<>();
Expand All @@ -27,10 +27,15 @@ public CommandInfo getCommandInfo(String command) {

@Override
public List<String> getAllCommand(boolean isWasm, boolean isAuthOpen) {
if (!isWasm && isAuthOpen) {
return new ArrayList<>(commandToCommandInfo.keySet());
}
return new ArrayList<>();
return commandToCommandInfo
.keySet()
.stream()
.filter(
key ->
!(isWasm && !commandToCommandInfo.get(key).isWasmSupport()
|| (!isAuthOpen
&& commandToCommandInfo.get(key).isNeedAuthOpen())))
.collect(Collectors.toList());
}

@Override
Expand Down Expand Up @@ -496,7 +501,7 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
1,
false,
false,
true);
false);

static {
Field[] fields = AuthOpCommand.class.getDeclaredFields();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ public Map<String, CommandInfo> getAllCommandInfo(boolean isWasm) {
"Set a system config value by key",
HelpInfo::setSystemConfigByKeyHelp,
(consoleInitializer, params, pwd) ->
consoleInitializer.getPrecompiledFace().setSystemConfigByKey(params),
consoleInitializer
.getPrecompiledFace()
.setSystemConfigByKey(consoleInitializer, params),
2,
2);

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/console/precompiled/PrecompiledFace.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package console.precompiled;

import console.ConsoleInitializer;

public interface PrecompiledFace {
// ConsensusPrecompiled
void addSealer(String[] params) throws Exception;
Expand All @@ -8,7 +10,8 @@ public interface PrecompiledFace {

void removeNode(String[] params) throws Exception;

void setSystemConfigByKey(String[] params) throws Exception;
void setSystemConfigByKey(ConsoleInitializer consoleInitializer, String[] params)
throws Exception;

void createTable(String sql) throws Exception;

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/console/precompiled/PrecompiledImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package console.precompiled;

import static console.common.Common.compatibilityVersion;

import console.ConsoleInitializer;
import console.common.Common;
import console.common.ConsoleUtils;
import console.contract.model.AbiAndBin;
Expand Down Expand Up @@ -111,10 +114,18 @@ public void setConsensusNodeWeight(String[] params) throws Exception {
}

@Override
public void setSystemConfigByKey(String[] params) throws Exception {
public void setSystemConfigByKey(ConsoleInitializer consoleInitializer, String[] params)
throws Exception {
String key = params[1];
String value = params[2];
ConsoleUtils.printJson(this.systemConfigService.setValueByKey(key, value).toString());
RetCode retCode = this.systemConfigService.setValueByKey(key, value);
ConsoleUtils.printJson(retCode.toString());
if (key.equals(compatibilityVersion)
&& retCode.code == PrecompiledRetCode.CODE_SUCCESS.code) {
String[] param = new String[2];
param[1] = consoleInitializer.getGroupID();
consoleInitializer.switchGroup(param);
}
}

@Override
Expand Down