Skip to content

Commit

Permalink
Fix issues with incorrect json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Nov 17, 2022
1 parent b30a32f commit 1921c26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/torusresearch/torusutils/TorusUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
Gson gson = new Gson();
JsonRPCResponse nodeSigResponse = gson.fromJson(respons, JsonRPCResponse.class);
if (nodeSigResponse != null && nodeSigResponse.getResult() != null) {
nodeSigs.add(gson.toJson(nodeSigResponse.getResult()));
nodeSigs.add(Utils.convertToJsonObject(nodeSigResponse.getResult()));
}
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
if (shareResponse != null && !shareResponse.equals("")) {
JsonRPCResponse shareResponseJson = gson.fromJson(shareResponse, JsonRPCResponse.class);
if (shareResponseJson != null && shareResponseJson.getResult() != null) {
completedResponses.add(gson.toJson(shareResponseJson.getResult()));
completedResponses.add(Utils.convertToJsonObject(shareResponseJson.getResult()));
}
}
}
Expand All @@ -176,7 +176,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
return null;
}
KeyAssignment keyAssignResultFirstKey = keyAssignResult.getKeys()[0];
completedResponsesPubKeys.add(gson.toJson(keyAssignResultFirstKey.getPublicKey()));
completedResponsesPubKeys.add(Utils.convertToJsonObject(keyAssignResultFirstKey.getPublicKey()));
}
String thresholdPublicKeyString = Utils.thresholdSame(completedResponsesPubKeys, k);
PubKey thresholdPubKey = null;
Expand All @@ -189,7 +189,7 @@ public CompletableFuture<RetrieveSharesResponse> retrieveShares(String[] endpoin
if (shareResponses[i] != null && !shareResponses[i].equals("")) {
JsonRPCResponse currentJsonRPCResponse = gson.fromJson(shareResponses[i], JsonRPCResponse.class);
if (currentJsonRPCResponse != null && currentJsonRPCResponse.getResult() != null && !currentJsonRPCResponse.getResult().equals("")) {
KeyAssignResult currentShareResponse = gson.fromJson(gson.toJson(currentJsonRPCResponse.getResult()), KeyAssignResult.class);
KeyAssignResult currentShareResponse = gson.fromJson(Utils.convertToJsonObject(currentJsonRPCResponse.getResult()), KeyAssignResult.class);
if (currentShareResponse != null && currentShareResponse.getKeys() != null && currentShareResponse.getKeys().length > 0) {
KeyAssignment firstKey = currentShareResponse.getKeys()[0];
if (firstKey.getMetadata() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static CompletableFuture<KeyLookupResult> keyLookup(String[] endpoints, S
if (x != null && !x.equals("")) {
try {
JsonRPCResponse response = gson.fromJson(x, JsonRPCResponse.class);
keyResults.add(gson.toJson(response.getResult()));
keyResults.add(Utils.convertToJsonObject(response.getResult()));
} catch (Exception e) {
keyResults.add("");
}
Expand Down Expand Up @@ -220,4 +220,9 @@ public static String padLeft(String inputString, Character padChar, int length)
sb.append(inputString);
return sb.toString();
}

public static String convertToJsonObject(Object obj) {
Gson gson = new Gson();
return obj == null ? "" : gson.toJson(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class OneKeyTest {
@BeforeAll
static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException {
System.out.println("Setup Starting");
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.TESTNET, FetchNodeDetails.PROXY_ADDRESS_TESTNET);
fetchNodeDetails = new FetchNodeDetails("https://small-long-brook.ropsten.quiknode.pro/e2fd2eb01412e80623787d1c40094465aa67624a", FetchNodeDetails.PROXY_ADDRESS_TESTNET);
TorusCtorOptions opts = new TorusCtorOptions("Custom");
opts.setNetwork("testnet");
opts.setEnableOneKey(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class TorusUtilsTest {
@BeforeAll
static void setup() throws ExecutionException, InterruptedException, IOException, NoSuchAlgorithmException, InvalidKeySpecException {
System.out.println("Setup Starting");
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.TESTNET, FetchNodeDetails.PROXY_ADDRESS_TESTNET);
fetchNodeDetails = new FetchNodeDetails("https://small-long-brook.ropsten.quiknode.pro/e2fd2eb01412e80623787d1c40094465aa67624a", FetchNodeDetails.PROXY_ADDRESS_TESTNET);
TorusCtorOptions opts = new TorusCtorOptions("Custom");
opts.setNetwork("testnet");
torusUtils = new TorusUtils(opts);
Expand Down

0 comments on commit 1921c26

Please sign in to comment.