Skip to content
Snippets Groups Projects
Commit a80caeba authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

enh: Allow to get requirements by pubkey (for performance reason - since Duniter 1.8.6)

parent a77442e6
Branches
Tags
No related merge requests found
Pipeline #33298 failed
......@@ -38,8 +38,26 @@ public interface WotRemoteService extends Service {
WotLookup.Uid find(Peer peer, String uidOrPubKey);
WotLookup.Uid find(String currencyId, String uidOrPubKey);
List<WotRequirements> getRequirements(Peer peer, String pubKey);
List<WotRequirements> getRequirements(String currencyId, String pubKey);
/**
* @deprecated Use getRequirementsByPubkey() intead
* @param peer
* @param uidOrPubkey
* @return
*/
@Deprecated
List<WotRequirements> getRequirements(Peer peer, String uidOrPubkey);
/**
* @deprecated Use getRequirementsByPubkey() intead
* @param peer
* @param uidOrPubkey
* @return
*/
@Deprecated
List<WotRequirements> getRequirements(String currencyId, String uidOrPubkey);
List<WotRequirements> getRequirementsByPubkey(Peer peer, String pubkey);
List<WotRequirements> getRequirementsByPubkey(String currencyId, String pubkey);
WotLookup.Uid findByUid(Peer peer, String uid);
WotLookup.Uid findByUid(String currencyId, String uid);
......@@ -57,7 +75,10 @@ public interface WotRemoteService extends Service {
Collection<Certification> getCertifications(String currencyId, String uid, String pubkey, boolean isMember);
WotCertification getCertifiedBy(Peer peer, String uid);
WotCertification getCertifiedBy(String currencyId, String uid);
WotCertification getCertifiedBy(String currencyId, String pubkeyOrUid);
WotCertification getCertifiedByPubkey(Peer peer, String pubkey);
WotCertification getCertifiedByPubkey(String currencyId, String pubkey);
long countValidCertifiers(Peer peer, String pubkey);
long countValidCertifiers(String currencyId, String pubkey);
......
......@@ -69,10 +69,16 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
public static final String URL_REQUIREMENT = URL_BASE + "/requirements/%s";
public static final String URL_REQUIREMENTBY_PUBKEY = URL_REQUIREMENT+ "?pubkey=true";
public static final String URL_CERTIFIED_BY = URL_BASE + "/certified-by/%s";
public static final String URL_CERTIFIED_BY_PUBKEY = URL_CERTIFIED_BY + "?pubkey=true";
public static final String URL_CERTIFIERS_OF = URL_BASE + "/certifiers-of/%s";
public static final String URL_CERTIFIERS_OF_BY_PUBKEY = URL_CERTIFIERS_OF + "?pubkey=true";
/**
* See https://github.com/ucoin-io/ucoin-cli/blob/master/bin/ucoin
* > var hash = res.current ? res.current.hash : 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709';
......@@ -190,19 +196,35 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
}
@Override
public List<WotRequirements> getRequirements(Peer peer, String pubKey) {
public List<WotRequirements> getRequirements(Peer peer, String uidOrPubkey) {
try {
WotRequirementsResponse response = httpService.executeRequest(peer, String.format(URL_REQUIREMENT, pubKey), WotRequirementsResponse.class);
WotRequirementsResponse response = httpService.executeRequest(peer, String.format(URL_REQUIREMENT, uidOrPubkey), WotRequirementsResponse.class);
return ImmutableList.copyOf(response.getIdentities());
} catch (HttpBadRequestException | HttpNotFoundException e) {
log.debug(String.format("Unable to get memberships for {%.8s}", pubKey));
log.debug(String.format("Unable to get memberships for {%.8s}", uidOrPubkey));
return null;
}
}
@Override
public List<WotRequirements> getRequirements(String currencyId, String pubKey) {
return getRequirements(peerService.getActivePeerByCurrency(currencyId), pubKey);
public List<WotRequirements> getRequirements(String currencyId, String uidOrPubkey) {
return getRequirements(peerService.getActivePeerByCurrency(currencyId), uidOrPubkey);
}
@Override
public List<WotRequirements> getRequirementsByPubkey(Peer peer, String pubkey) {
try {
WotRequirementsResponse response = httpService.executeRequest(peer, String.format(URL_REQUIREMENTBY_PUBKEY, pubkey), WotRequirementsResponse.class);
return ImmutableList.copyOf(response.getIdentities());
} catch (HttpBadRequestException | HttpNotFoundException e) {
log.debug(String.format("Unable to get memberships for {%.8s}", pubkey));
return null;
}
}
@Override
public List<WotRequirements> getRequirementsByPubkey(String currencyId, String pubKey) {
return getRequirementsByPubkey(peerService.getActivePeerByCurrency(currencyId), pubKey);
}
public WotLookup.Uid findByUid(Peer peer, String uid) {
......@@ -305,21 +327,36 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
return getCertifications(peerService.getActivePeerByCurrency(currencyId), uid, pubkey, isMember);
}
public WotCertification getCertifiedBy(Peer peer, String uid) {
public WotCertification getCertifiedBy(Peer peer, String uidOrPubkey) {
if (log.isDebugEnabled()) {
log.debug(String.format("Try to get certifications done by uid: %s", uid));
log.debug(String.format("Try to get certifications done by uid: %s", uidOrPubkey));
}
// call certified-by
String path = String.format(URL_CERTIFIED_BY, uid);
String path = String.format(URL_CERTIFIED_BY, uidOrPubkey);
WotCertification result = httpService.executeRequest(peer, path, WotCertification.class);
return result;
}
public WotCertification getCertifiedBy(String currencyId, String uid) {
return getCertifiedBy(peerService.getActivePeerByCurrency(currencyId), uid);
public WotCertification getCertifiedBy(String currencyId, String uidOrPubkey) {
return getCertifiedBy(peerService.getActivePeerByCurrency(currencyId), uidOrPubkey);
}
public WotCertification getCertifiedByPubkey(Peer peer, String pubkey) {
if (log.isDebugEnabled()) {
log.debug(String.format("Try to get certifications done by pubkey: %s", pubkey));
}
// call certified-by
String path = String.format(URL_CERTIFIED_BY_PUBKEY, pubkey);
WotCertification result = httpService.executeRequest(peer, path, WotCertification.class);
return result;
}
@Override
public WotCertification getCertifiedByPubkey(String currencyId, String pubkey) {
return getCertifiedByPubkey(peerService.getActivePeerByCurrency(currencyId), pubkey);
}
public long countValidCertifiers(Peer peer, String pubkey) {
......@@ -354,6 +391,21 @@ public class WotRemoteServiceImpl extends BaseRemoteServiceImpl implements WotRe
return getCertifiersOf(peerService.getActivePeerByCurrency(currencyId), uid);
}
public WotCertification getCertifiersOfByPubkey(Peer peer, String pubkey) {
if (log.isDebugEnabled()) {
log.debug(String.format("Try to get certifications done to pubkey: %s", pubkey));
}
// call certifiers-of
String path = String.format(URL_CERTIFIERS_OF_BY_PUBKEY, pubkey);
WotCertification result = httpService.executeRequest(peer, path, WotCertification.class);
return result;
}
public WotCertification getCertifiersOfByPubkey(String currencyId, String pubkey) {
return getCertifiersOf(peerService.getActivePeerByCurrency(currencyId), pubkey);
}
public void sendIdentity(Peer peer, String currency, byte[] pubKey, byte[] secKey, String uid, String blockUid) {
// http post /wot/add
HttpPost httpPost = new HttpPost(httpService.getPath(peer, URL_ADD));
......
......@@ -209,6 +209,26 @@ public class WotRemoteServiceTest {
});
}
@Test
public void getRequirementsByPubkey() {
List<WotPendingMembership> pendingMemberships = service.getPendingMemberships(peer);
Assume.assumeTrue(CollectionUtils.isNotEmpty(pendingMemberships));
MutableInt counter = new MutableInt(0);
pendingMemberships.stream()
// Get first 10
.filter(ms -> {
counter.increment();
return counter.getValue() < 10;
})
.forEach(ms -> {
List<WotRequirements> result = service.getRequirementsByPubkey(peer, ms.getPubkey());
Assert.assertNotNull(result);
Assert.assertNotNull(result.size() > 0);
});
}
/* -- internal methods */
protected Wallet createTestWallet() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment