Skip to content

Commit

Permalink
<fix>(completer,precompiled): fix deploy liquid completer bug. (#680)
Browse files Browse the repository at this point in the history
* <fix>(precompiled): fix bfs list /sys/ contracts bugs.

* <fix>(completer): fix deploy liquid bug.
  • Loading branch information
kyonRay authored Sep 14, 2022
1 parent 817d4be commit 65efac8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/main/java/console/command/completer/ConsoleFilesCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,11 @@ public void complete(
current = getUserHome().getParent().resolve(curBuf.substring(1));
}
} else {
if (completeSol) {
current = contractPath.resolve(curBuf);
} else {
current = getUserDir().resolve(curBuf);
}
current = contractPath.resolve(curBuf);
}
} else {
curBuf = "";
if (completeSol) {
current = contractPath;
} else {
current = getUserDir();
}
current = contractPath;
}
try (DirectoryStream<Path> directoryStream =
Files.newDirectoryStream(current, this::accept)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/console/contract/utils/ContractCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ContractCompiler {
public static final String LIQUID_PATH = "contracts/liquid/";
public static final String COMPILED_PATH = "contracts/.compiled/";
public static final String BFS_APPS_PREFIX = "/apps";
public static final String BFS_SYS_PREFIX = "/sys";
public static final String BFS_APPS_FULL_PREFIX = "/apps/";
public static final String SOL_SUFFIX = ".sol";
public static final String SM_SUFFIX = ".sm";
Expand Down
42 changes: 41 additions & 1 deletion src/main/java/console/precompiled/PrecompiledImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package console.precompiled;

import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.BFS_PRECOMPILED_ADDRESS;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.BFS_PRECOMPILED_NAME;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.COMMITTEE_MANAGER_ADDRESS;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.CONSENSUS_PRECOMPILED_ADDRESS;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.CONSENSUS_PRECOMPILED_NAME;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.SYS_CONFIG_PRECOMPILED_ADDRESS;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.SYS_CONFIG_PRECOMPILED_NAME;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.TABLE_MANAGER_PRECOMPILED_ADDRESS;
import static org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress.TABLE_MANAGER_PRECOMPILED_NAME;

import console.common.Common;
import console.common.ConsoleUtils;
import console.contract.model.AbiAndBin;
Expand All @@ -12,6 +22,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -50,6 +61,16 @@ public class PrecompiledImpl implements PrecompiledFace {
private TableCRUDService tableCRUDService;
private BFSService bfsService;
private String pwd = "/apps";
public static Map<String, String> bfsSysAddress = new HashMap<>();

static {
bfsSysAddress.put(BFS_PRECOMPILED_NAME, BFS_PRECOMPILED_ADDRESS);
bfsSysAddress.put(CONSENSUS_PRECOMPILED_NAME, CONSENSUS_PRECOMPILED_ADDRESS);
bfsSysAddress.put(SYS_CONFIG_PRECOMPILED_NAME, SYS_CONFIG_PRECOMPILED_ADDRESS);
bfsSysAddress.put(TABLE_MANAGER_PRECOMPILED_NAME, TABLE_MANAGER_PRECOMPILED_ADDRESS);
bfsSysAddress.put("/sys/auth", COMMITTEE_MANAGER_ADDRESS);
bfsSysAddress.put("/sys/crypto_tools", "000000000000000000000000000000000000100a");
}

public PrecompiledImpl(Client client) {
this.client = client;
Expand Down Expand Up @@ -426,7 +447,26 @@ public void listDir(String[] params) throws Exception {
String[] fixedBfsParams = ConsoleUtils.fixedBfsParams(params, pwd);

String listPath = fixedBfsParams.length == 1 ? pwd : fixedBfsParams[1];
List<BfsInfo> fileInfoList = bfsService.list(listPath);
if (listPath.startsWith(ContractCompiler.BFS_SYS_PREFIX)
&& bfsSysAddress.containsKey(listPath)) {
// /sys/ bfsInfo
System.out.println(
listPath
+ ": built-in contract, you can use it's address in contract to call interfaces.");
if (!client.isWASM()) {
System.out.println(listPath + " -> " + bfsSysAddress.get(listPath));
}
return;
}
List<BfsInfo> fileInfoList;
try {
fileInfoList = bfsService.list(listPath);
} catch (ContractException e) {
RetCode precompiledResponse =
PrecompiledRetCode.getPrecompiledResponse(e.getErrorCode(), e.getMessage());
throw new ContractException(
precompiledResponse.getMessage(), precompiledResponse.getCode());
}
String baseName = FilenameUtils.getBaseName(listPath);
int newLineCount = 0;
for (BfsInfo fileInfo : fileInfoList) {
Expand Down

0 comments on commit 65efac8

Please sign in to comment.