Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.torusresearch.fetchnodedetails.types.APIUtils;
import org.torusresearch.fetchnodedetails.types.FNDResponse;
import org.torusresearch.fetchnodedetails.types.NodeDetails;
import org.torusresearch.fetchnodedetails.types.TorusNetwork;
import org.torusresearch.fetchnodedetails.types.Utils;
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork;

import java.util.Arrays;
import java.util.List;
Expand All @@ -17,25 +17,25 @@ public class FetchNodeDetails {
private List<String> multi_cluster_networks = Arrays.asList("celeste");

private final NodeDetails nodeDetails = new NodeDetails();
private TorusNetwork torusNetwork = TorusNetwork.SAPPHIRE_MAINNET;
private Web3AuthNetwork web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET;

public FetchNodeDetails() {
this(TorusNetwork.SAPPHIRE_MAINNET);
this(Web3AuthNetwork.SAPPHIRE_MAINNET);
}

public FetchNodeDetails(TorusNetwork network) {
this.torusNetwork = network;
public FetchNodeDetails(Web3AuthNetwork network) {
this.web3AuthNetwork = network;
}

public CompletableFuture<NodeDetails> getNodeDetails(String verifier, String verifierId) {
// For mainnet & ropsten, verifierId combination doesn't change the network details
if (this.nodeDetails.getUpdated() && !(multi_cluster_networks.contains(this.torusNetwork.name())))
if (this.nodeDetails.getUpdated() && !(multi_cluster_networks.contains(this.web3AuthNetwork.name())))
return CompletableFuture.supplyAsync(() -> this.nodeDetails);

CompletableFuture<NodeDetails> cf = new CompletableFuture<>();
try {
String fndServerEndpoint = Utils.FND_SERVER + "/node-details";
String url = fndServerEndpoint + "?network=" + this.torusNetwork + "&verifier=" + verifier + "&verifierId=" + verifierId;
String url = fndServerEndpoint + "?network=" + this.web3AuthNetwork + "&verifier=" + verifier + "&verifierId=" + verifierId;
CompletableFuture<String> response = APIUtils.get(url);
FNDResponse fndResponse =
new GsonBuilder().disableHtmlEscaping().create().fromJson(response.get(), FNDResponse.class);
Expand All @@ -45,7 +45,7 @@ public CompletableFuture<NodeDetails> getNodeDetails(String verifier, String ver
} catch (Exception ex) {
ex.printStackTrace();
}
NodeDetails nodeDetails = Utils.fetchLocalConfig(this.torusNetwork);
NodeDetails nodeDetails = Utils.fetchLocalConfig(this.web3AuthNetwork);
if (nodeDetails == null) cf.completeExceptionally(new Exception("Failed to fetch node details"));
else {
this.setNodeDetails(nodeDetails, false);
Expand All @@ -55,9 +55,9 @@ public CompletableFuture<NodeDetails> getNodeDetails(String verifier, String ver
}

public CompletableFuture<String> getMetadataUrl() {
List<TorusNetwork> legacyNetworks = Arrays.asList(TorusNetwork.AQUA, TorusNetwork.CYAN, TorusNetwork.CELESTE, TorusNetwork.MAINNET, TorusNetwork.TESTNET);
if (legacyNetworks.contains(this.torusNetwork))
return CompletableFuture.supplyAsync(() -> Utils.METADATA_MAP.get(this.torusNetwork));
List<Web3AuthNetwork> legacyNetworks = Arrays.asList(Web3AuthNetwork.AQUA, Web3AuthNetwork.CYAN, Web3AuthNetwork.CELESTE, Web3AuthNetwork.MAINNET, Web3AuthNetwork.TESTNET);
if (legacyNetworks.contains(this.web3AuthNetwork))
return CompletableFuture.supplyAsync(() -> Utils.METADATA_MAP.get(this.web3AuthNetwork));

return this.getNodeDetails("test-verifier", "test-verifier-id").thenCompose((nodeDetails) -> CompletableFuture.supplyAsync(() -> nodeDetails.getTorusNodeEndpoints()[0].replace("/sss/jrpc", "/metadata")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public class LegacyNetworkMigrationInfo {

private Boolean migrationCompleted = false;
private String networkIdentifier;
private TorusNetwork networkMigratedTo;
private Web3AuthNetwork networkMigratedTo;


public LegacyNetworkMigrationInfo(Boolean migrationCompleted, String networkIdentifier, TorusNetwork networkMigratedTo) {
public LegacyNetworkMigrationInfo(Boolean migrationCompleted, String networkIdentifier, Web3AuthNetwork networkMigratedTo) {
this.migrationCompleted = migrationCompleted;
this.networkIdentifier = networkIdentifier;
this.networkMigratedTo = networkMigratedTo;
Expand All @@ -21,7 +21,7 @@ public String getNetworkIdentifier() {
return networkIdentifier;
}

public TorusNetwork getNetworkMigratedTo() {
public Web3AuthNetwork getNetworkMigratedTo() {
return networkMigratedTo;
}
}
77 changes: 37 additions & 40 deletions src/main/java/org/torusresearch/fetchnodedetails/types/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

public class Utils {

public static HashMap<String, LegacyNetworkMigrationInfo> LEGACY_NETWORKS_ROUTE_MAP = new HashMap<String, LegacyNetworkMigrationInfo>() {
public static final Map<Web3AuthNetwork, String> NETWORK_MAP = new HashMap<Web3AuthNetwork, String>() {
{
put(TorusNetwork.AQUA.toString(), new LegacyNetworkMigrationInfo(true, "aqua", TorusNetwork.SAPPHIRE_MAINNET));
put(TorusNetwork.CELESTE.toString(), new LegacyNetworkMigrationInfo(false, "celeste", TorusNetwork.SAPPHIRE_MAINNET));
put(TorusNetwork.CYAN.toString(), new LegacyNetworkMigrationInfo(true, "cyan", TorusNetwork.SAPPHIRE_MAINNET));
put(TorusNetwork.MAINNET.toString(), new LegacyNetworkMigrationInfo(true, "mainnet", TorusNetwork.SAPPHIRE_MAINNET));
put(TorusNetwork.TESTNET.toString(), new LegacyNetworkMigrationInfo(true, "teal", TorusNetwork.SAPPHIRE_DEVNET));
put(Web3AuthNetwork.MAINNET, "mainnet");
put(Web3AuthNetwork.TESTNET, "goerli");
put(Web3AuthNetwork.CYAN, "polygon-mainnet");
put(Web3AuthNetwork.AQUA, "polygon-mainnet");
put(Web3AuthNetwork.CELESTE, "polygon-mainnet");

}
};

Expand Down Expand Up @@ -88,8 +89,37 @@ public class Utils {
new TorusNodePub("7bcb058d4c6ffc6ba4bfdfd93d141af35a66338a62c7c27cdad2ae3f8289b767", "336ab1935e41ed4719e162587f0ab55518db4207a1eb36cc72303f1b86689d2b"),
new TorusNodePub("bf12a136ef94399ea098f926f04e26a4ec4ac70f69cce274e8893704c4951773", "bdd44828020f52ce510e026338216ada184a6867eb4e19fb4c2d495d4a7e15e4")},
false);
public static final Map<Web3AuthNetwork, String> SIGNER_MAP = new HashMap<Web3AuthNetwork, String>() {
{
put(Web3AuthNetwork.MAINNET, "https://signer.web3auth.io");
put(Web3AuthNetwork.TESTNET, "https://signer.web3auth.io");
put(Web3AuthNetwork.CYAN, "https://signer-polygon.web3auth.io");
put(Web3AuthNetwork.AQUA, "https://signer-polygon.web3auth.io");
put(Web3AuthNetwork.CELESTE, "https://signer-polygon.web3auth.io");
put(Web3AuthNetwork.SAPPHIRE_MAINNET, "https://signer.web3auth.io");
put(Web3AuthNetwork.SAPPHIRE_DEVNET, "https://signer.web3auth.io");
}
};
public static final Map<Web3AuthNetwork, String> METADATA_MAP = new HashMap<Web3AuthNetwork, String>() {
{
put(Web3AuthNetwork.MAINNET, "https://metadata.web3auth.io");
put(Web3AuthNetwork.TESTNET, "https://metadata.web3auth.io");
put(Web3AuthNetwork.CYAN, "https://metadata.web3auth.io");
put(Web3AuthNetwork.AQUA, "https://metadata.web3auth.io");
put(Web3AuthNetwork.CELESTE, "https://metadata.web3auth.io");
}
};
public static HashMap<String, LegacyNetworkMigrationInfo> LEGACY_NETWORKS_ROUTE_MAP = new HashMap<String, LegacyNetworkMigrationInfo>() {
{
put(Web3AuthNetwork.AQUA.toString(), new LegacyNetworkMigrationInfo(true, "aqua", Web3AuthNetwork.SAPPHIRE_MAINNET));
put(Web3AuthNetwork.CELESTE.toString(), new LegacyNetworkMigrationInfo(false, "celeste", Web3AuthNetwork.SAPPHIRE_MAINNET));
put(Web3AuthNetwork.CYAN.toString(), new LegacyNetworkMigrationInfo(true, "cyan", Web3AuthNetwork.SAPPHIRE_MAINNET));
put(Web3AuthNetwork.MAINNET.toString(), new LegacyNetworkMigrationInfo(true, "mainnet", Web3AuthNetwork.SAPPHIRE_MAINNET));
put(Web3AuthNetwork.TESTNET.toString(), new LegacyNetworkMigrationInfo(true, "teal", Web3AuthNetwork.SAPPHIRE_DEVNET));
}
};

public static NodeDetails fetchLocalConfig(TorusNetwork network) {
public static NodeDetails fetchLocalConfig(Web3AuthNetwork network) {
NodeDetails nodeDetails = null;
switch (network) {
case SAPPHIRE_DEVNET:
Expand All @@ -108,39 +138,6 @@ public static NodeDetails fetchLocalConfig(TorusNetwork network) {
return nodeDetails;
}

public static final Map<TorusNetwork, String> NETWORK_MAP = new HashMap<TorusNetwork, String>() {
{
put(TorusNetwork.MAINNET, "mainnet");
put(TorusNetwork.TESTNET, "goerli");
put(TorusNetwork.CYAN, "polygon-mainnet");
put(TorusNetwork.AQUA, "polygon-mainnet");
put(TorusNetwork.CELESTE, "polygon-mainnet");

}
};

public static final Map<TorusNetwork, String> SIGNER_MAP = new HashMap<TorusNetwork, String>() {
{
put(TorusNetwork.MAINNET, "https://signer.web3auth.io");
put(TorusNetwork.TESTNET, "https://signer.web3auth.io");
put(TorusNetwork.CYAN, "https://signer-polygon.web3auth.io");
put(TorusNetwork.AQUA, "https://signer-polygon.web3auth.io");
put(TorusNetwork.CELESTE, "https://signer-polygon.web3auth.io");
put(TorusNetwork.SAPPHIRE_MAINNET, "https://signer.web3auth.io");
put(TorusNetwork.SAPPHIRE_DEVNET, "https://signer.web3auth.io");
}
};

public static final Map<TorusNetwork, String> METADATA_MAP = new HashMap<TorusNetwork, String>() {
{
put(TorusNetwork.MAINNET, "https://metadata.web3auth.io");
put(TorusNetwork.TESTNET, "https://metadata.web3auth.io");
put(TorusNetwork.CYAN, "https://metadata.web3auth.io");
put(TorusNetwork.AQUA, "https://metadata.web3auth.io");
put(TorusNetwork.CELESTE, "https://metadata.web3auth.io");
}
};

public static final String FND_SERVER = "https://fnd.web3auth.io";

public static final String SESSION_SERVER = "https://session.web3auth.io";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.torusresearch.fetchnodedetails.types;

public enum TorusNetwork {
public enum Web3AuthNetwork {
MAINNET("mainnet"),
TESTNET("testnet"),
CYAN("cyan"),
Expand All @@ -11,7 +11,7 @@ public enum TorusNetwork {

private final String val;

TorusNetwork(String s) {
Web3AuthNetwork(String s) {
this.val = s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.junit.jupiter.api.Test;
import org.torusresearch.fetchnodedetails.FetchNodeDetails;
import org.torusresearch.fetchnodedetails.types.NodeDetails;
import org.torusresearch.fetchnodedetails.types.TorusNetwork;
import org.torusresearch.fetchnodedetails.types.Utils;
import org.torusresearch.fetchnodedetails.types.Web3AuthNetwork;
import org.torusresearch.fetchnodedetailstest.config.Config;

import java.util.concurrent.ExecutionException;
Expand All @@ -18,47 +18,47 @@ class FetchNodeDetailsTest {
@DisplayName("Gets the Node details for Mainnet")
@Test
public void shouldGetNodeDetailsMainnet() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.MAINNET);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.MAINNET);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.MAINNET, nodeDetails);
}

@DisplayName("Gets the Node details for Testnet")
@Test
public void shouldGetNodeDetailsTestnet() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.TESTNET);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.TESTNET);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.TESTNET, nodeDetails);
}

@DisplayName("Gets the Node details for Cyan")
@Test
public void shouldGetNodeDetailsCyan() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.CYAN);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.CYAN);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.CYAN, nodeDetails);
}

@DisplayName("Gets the Node details for Aqua")
@Test
public void shouldGetNodeDetailsAqua() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.AQUA);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.AQUA);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.AQUA, nodeDetails);
}

@DisplayName("Gets the Node details for Celeste")
@Test
public void shouldGetNodeDetailsCeleste() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.CELESTE);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.CELESTE);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.CELESTE, nodeDetails);
}

@DisplayName("Gets the Node details for SapphireDevnet")
@Test
public void shouldGetNodeDetailsSapphireDevnet() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.SAPPHIRE_DEVNET);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.SAPPHIRE_DEVNET);
NodeDetails nodeDetails = this.fetchNodeDetails.getNodeDetails("google", "hello@tor.us").get();
assertEquals(Config.SAPPHIRE_DEVNET, nodeDetails);
}
Expand All @@ -82,8 +82,8 @@ public void shouldGetMetadataUrlSapphireMainnet() throws ExecutionException, Int
@DisplayName("Gets the Metadata url for Legacy Mainnet")
@Test
public void shouldGetMetadataUrlLegacyMainnet() throws ExecutionException, InterruptedException {
fetchNodeDetails = new FetchNodeDetails(TorusNetwork.MAINNET);
fetchNodeDetails = new FetchNodeDetails(Web3AuthNetwork.MAINNET);
String metadataUrl = this.fetchNodeDetails.getMetadataUrl().get();
assertEquals(Utils.METADATA_MAP.get(TorusNetwork.MAINNET), metadataUrl);
assertEquals(Utils.METADATA_MAP.get(Web3AuthNetwork.MAINNET), metadataUrl);
}
}