Skip to content

Commit

Permalink
fix: The 0.8.11 solc return abi and doc as json object but 0.6.10 0.5…
Browse files Browse the repository at this point in the history
….2 0.4.25 solc return abi and doc as string, so the parse logic should handle it。
  • Loading branch information
dwzhan committed Apr 28, 2024
1 parent 875fe20 commit 0dac6cf
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/java/org/fisco/solc/compiler/CompilationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public static CompilationResult parse(String rawJson) throws IOException {
JsonObject contractJsonObject =
asJsonObject.get(contract.toString()).getAsJsonObject();
JsonObject abiObject = new JsonObject();
abiObject.addProperty("abi", contractJsonObject.get("abi").toString());
abiObject.addProperty("bin", contractJsonObject.get("bin").getAsString());
abiObject.addProperty("metadata", contractJsonObject.get("metadata").getAsString());
abiObject.addProperty("abi", getJsonValueAsString(contractJsonObject, "abi"));
abiObject.addProperty("bin", getJsonValueAsString(contractJsonObject, "bin"));
abiObject.addProperty("metadata", getJsonValueAsString(contractJsonObject, "metadata"));

if (contractJsonObject.get("userdoc") != null) {
abiObject.addProperty("userdoc", contractJsonObject.get("userdoc").toString());
abiObject.addProperty("userdoc", getJsonValueAsString(contractJsonObject, "userdoc"));
}

if (contractJsonObject.get("devdoc") != null) {
abiObject.addProperty("devdoc", contractJsonObject.get("devdoc").toString());
abiObject.addProperty("devdoc", getJsonValueAsString(contractJsonObject, "devdoc"));
}
contractObject.add(contract.toString(), abiObject);
}
Expand All @@ -65,6 +65,18 @@ public static CompilationResult parse(String rawJson) throws IOException {
}
}

private static String getJsonValueAsString(JsonObject jsonObject, String key) {
if (jsonObject == null || jsonObject.get(key) == null || jsonObject.get(key).isJsonNull()) {
return null;
}

if (jsonObject.get(key).isJsonPrimitive()) {
return jsonObject.get(key).getAsString();
}

return jsonObject.get(key).toString();
}

/**
* @param contractName The contract name
* @return the first contract found for a given contract name; use {@link #getContract(Path,
Expand Down

0 comments on commit 0dac6cf

Please sign in to comment.