Skip to content

Commit 9d812a5

Browse files
committed
enh: Upgrade to duniter4j 1.6 that enable Duniter 1.8.6 enhancement (add ?pubkey=true on BMA /wot queries)
1 parent d3f3870 commit 9d812a5

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/rest/wot/RestWotRequirementsGetAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected void handleRequest(RestRequest request, RestChannel channel, Client cl
6969
String pubkey = request.param("pubkey");
7070

7171
try {
72-
List<WotRequirements> requirements = wotService.getRequirements(currency, pubkey);
72+
List<WotRequirements> requirements = wotService.getRequirementsByPubkey(currency, pubkey);
7373
if (requirements == null) {
7474
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request).startObject()
7575
.field("ucode", 2021)

cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/PendingMembershipService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ protected XContentBuilder getMembershipWithRequirements(Peer peer,
272272
do {
273273

274274
try {
275-
identities = wotRemoteService.getRequirements(peer, membership.getPubkey());
275+
identities = wotRemoteService.getRequirementsByPubkey(peer, membership.getPubkey());
276276
requestCounter.increment();
277277
}
278278
// Error can occur because of quota on BMA api

cesium-plus-pod-core/src/main/java/org/duniter/elasticsearch/service/WotService.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,16 @@ public boolean isMember(String currency, String pubkey) {
263263
return response.getHits() != null && response.getHits().getTotalHits() > 0;
264264
}
265265

266-
public List<WotRequirements> getRequirements(String currency, String pubkey) {
266+
public List<WotRequirements> getRequirements(String currency, String uidOrPubkey) {
267267
waitReady();
268268
final String currencyId = safeGetCurrency(currency);
269-
return this.wotRemoteService.getRequirements(currencyId, pubkey);
269+
return this.wotRemoteService.getRequirements(currencyId, uidOrPubkey);
270+
}
271+
272+
public List<WotRequirements> getRequirementsByPubkey(String currency, String pubkey) {
273+
waitReady();
274+
final String currencyId = safeGetCurrency(currency);
275+
return this.wotRemoteService.getRequirementsByPubkey(currencyId, pubkey);
270276
}
271277

272278
public Optional<Member> getMemberByPubkey(String currency, String pubkey) {
@@ -277,19 +283,25 @@ public Optional<Member> getMemberByPubkey(String currency, String pubkey) {
277283
}
278284
// Fallback to remote duniter node (e.g. Blockchain not yet indexed)
279285
else {
280-
Identity source = this.wotRemoteService.getIdentity(currencyId, pubkey);
281-
if (source == null
282-
|| !currencyId.equals(source.getCurrency())
283-
|| (!source.getIsMember() && source.getWasMember())) return Optional.empty(); // Not a member
284-
285-
Member target = new Member();
286-
target.setPubkey(pubkey);
287-
target.setCurrency(currencyId);
288-
target.setUid(source.getUid());
289-
target.setIsMember(source.getIsMember());
290-
target.setWasMember(source.getWasMember());
291-
target.setTimestamp(source.getTimestamp());
292-
return Optional.of(target);
286+
return this.wotRemoteService.getRequirementsByPubkey(currencyId, pubkey)
287+
.stream()
288+
.map(source -> {
289+
Member target = new Member();
290+
target.setPubkey(pubkey);
291+
target.setCurrency(currencyId);
292+
target.setUid(source.getUid());
293+
target.setWasMember(source.getWasMember());
294+
Boolean isMember = Boolean.FALSE.equals(source.getRevoked())
295+
&& source.getMembershipExpiresIn() != null
296+
&& source.getMembershipExpiresIn() > 0;
297+
target.setIsMember(isMember);
298+
if (source.getMeta() != null) {
299+
target.setTimestamp(source.getMeta().getTimestamp());
300+
}
301+
return target;
302+
})
303+
.filter(source -> Boolean.TRUE.equals(source.getWasMember()) || source.getIsMember())
304+
.findFirst();
293305
}
294306
}
295307

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<javaVersion>11</javaVersion>
2929

3030
<!-- Commons versions -->
31-
<duniter4j.version>1.5.10</duniter4j.version>
31+
<duniter4j.version>1.6.1</duniter4j.version>
3232
<log4j.version>1.2.17</log4j.version>
3333
<slf4j.version>1.7.6</slf4j.version>
3434
<guava.version>22.0</guava.version>

0 commit comments

Comments
 (0)