Skip to content

Commit 1f515ec

Browse files
Merge pull request #33 from torusresearch/bugFix-in-thresholdSame
Bugfix in thresholdSame function.
2 parents b5ead50 + 174af5e commit 1f515ec

5 files changed

Lines changed: 17 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repositories {
2828
maven { url "https://jitpack.io" }
2929
}
3030
dependencies {
31-
implementation 'org.torusresearch:torus-utils-java:4.0.0'
31+
implementation 'org.torusresearch:torus-utils-java:4.0.3'
3232
}
3333
```
3434

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
}
66

77
group 'org.torusresearch'
8-
version '4.0.0'
8+
version '4.0.3'
99

1010
sourceCompatibility = JavaVersion.VERSION_1_8
1111
targetCompatibility = JavaVersion.VERSION_1_8

src/main/java/org/torusresearch/torusutils/apis/responses/VerifierLookupResponse/VerifierKey.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,12 @@ public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNul
2020
this.nonce_data = nonce_data;
2121
this.created_at = created_at;
2222
}
23+
24+
public VerifierKey(@NotNull String pub_key_X, @NotNull String pub_key_Y, @NotNull String address) {
25+
this.pub_key_X = pub_key_X;
26+
this.pub_key_Y = pub_key_Y;
27+
this.address = address;
28+
this.nonce_data = null;
29+
this.created_at = null;
30+
}
2331
}

src/main/java/org/torusresearch/torusutils/helpers/Common.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static KeyResult normalizeKeyResult(@NotNull VerifierLookupResponse resul
2121
KeyResult finalResult = new KeyResult(isNewKey);
2222
if (result.keys.length > 0) {
2323
VerifierKey finalKey = result.keys[0];
24-
finalResult.keys = new VerifierKey[]{ finalKey };
24+
finalResult.keys = new VerifierKey[]{new VerifierKey(finalKey.pub_key_X, finalKey.pub_key_Y, finalKey.address)};
2525
}
2626
return finalResult;
2727
}

src/main/java/org/torusresearch/torusutils/helpers/NodeUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public static KeyLookupResult getPubKeyOrKeyAssign(@NotNull String[] endpoints,
9292
@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.
9393
JsonRPCResponse<VerifierLookupResponse> response = json.fromJson(result, JsonRPCResponse.class);
9494
collected.add(response);
95-
lookupPubKeys = collected.stream().filter(item -> item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList());
96-
errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item.getError() != null).toArray(), threshold);
95+
lookupPubKeys = collected.stream().filter(item -> item != null && item.getError() == null && item.getTypedResult(VerifierLookupResponse.class) != null).collect(Collectors.toList());
96+
errResult = (JsonRPCErrorInfo) NodeUtils.thresholdSame(collected.stream().filter(item -> item != null && item.getError() != null).toArray(), threshold);
9797
ArrayList<KeyResult> normalizedKeys = new ArrayList<>();
9898
for (JsonRPCResponse<VerifierLookupResponse> item : lookupPubKeys) {
9999
VerifierLookupResponse vlr = item.getTypedResult(VerifierLookupResponse.class);
@@ -550,11 +550,11 @@ public static <T> T thresholdSame(@NotNull T[] arr, int threshold) throws JsonPr
550550
ObjectMapper objectMapper = new ObjectMapper()
551551
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
552552
String value = objectMapper.writeValueAsString(s);
553-
Integer index = hashMap.get(value);
554-
if (index != null) {
555-
hashMap.put(value, index+1);
553+
Integer found = hashMap.get(value);
554+
if (found != null) {
555+
hashMap.put(value, found + 1);
556556
} else {
557-
hashMap.put(value, 0);
557+
hashMap.put(value, 1);
558558
}
559559
if (hashMap.get(value) != null && hashMap.get(value) == threshold) {
560560
return s;

0 commit comments

Comments
 (0)