Skip to content

Commit

Permalink
Merge pull request #33 from torusresearch/bugFix-in-thresholdSame
Browse files Browse the repository at this point in the history
Bugfix in thresholdSame function.
  • Loading branch information
chaitanyapotti authored Oct 23, 2024
2 parents b5ead50 + 174af5e commit 1f515ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'org.torusresearch:torus-utils-java:4.0.0'
implementation 'org.torusresearch:torus-utils-java:4.0.3'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'org.torusresearch'
version '4.0.0'
version '4.0.3'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNul
this.nonce_data = nonce_data;
this.created_at = created_at;
}

public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNull String address) {
this.pub_key_X = pub_key_X;
this.pub_key_Y = pub_key_Y;
this.address = address;
this.nonce_data = null;
this.created_at = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static KeyResult normalizeKeyResult(@NotNull VerifierLookupResponse resul
KeyResult finalResult = new KeyResult(isNewKey);
if (result.keys.length > 0) {
VerifierKey finalKey = result.keys[0];
finalResult.keys = new VerifierKey[]{ finalKey };
finalResult.keys = new VerifierKey[]{new VerifierKey(finalKey.pub_key_X, finalKey.pub_key_Y, finalKey.address)};
}
return finalResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public static KeyLookupResult getPubKeyOrKeyAssign(@NotNull String[] endpoints,
@SuppressWarnings({"unchecked"}) // Due to Type Erasure of Generic Types at Runtime. Java does this to ensure code is compatible with pre-generic versions of Java.
JsonRPCResponse<VerifierLookupResponse> response = json.fromJson(result, JsonRPCResponse.class);
collected.add(response);
lookupPubKeys = collected.stream().filter(item -> item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList());
errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item.getError() != null).toArray(), threshold);
lookupPubKeys = collected.stream().filter(item -> item != null && item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList());
errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item != null && item.getError() != null).toArray(), threshold);
ArrayList<KeyResult> normalizedKeys = new ArrayList<>();
for (JsonRPCResponse<VerifierLookupResponse> item : lookupPubKeys) {
VerifierLookupResponse vlr = item.getTypedResult(VerifierLookupResponse.class);
Expand Down Expand Up @@ -550,11 +550,11 @@ public static <T> T thresholdSame(@NotNull T[] arr, int threshold) throws JsonPr
ObjectMapper objectMapper = new ObjectMapper()
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
String value = objectMapper.writeValueAsString(s);
Integer index = hashMap.get(value);
if (index != null) {
hashMap.put(value, index+1);
Integer found = hashMap.get(value);
if (found != null) {
hashMap.put(value, found + 1);
} else {
hashMap.put(value, 0);
hashMap.put(value, 1);
}
if (hashMap.get(value) != null && hashMap.get(value) == threshold) {
return s;
Expand Down

0 comments on commit 1f515ec

Please sign in to comment.