Skip to content

Commit

Permalink
Merge pull request #52 from skynetcap/feature/srm-66-add-docker-varia…
Browse files Browse the repository at this point in the history
…ble-for-rpc-url

[SRM-66] Add optional environment variable OPENSERUM_ENDPOINT for set…
  • Loading branch information
skynetcap authored Jul 3, 2022
2 parents 9d47297 + f651eac commit f9fc503
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ RUN mvn -f /home/app/pom.xml clean package -DskipTests
FROM openjdk:11-jre-slim
COPY --from=build /home/app/target/serumdata-0.0.1-SNAPSHOT.jar /usr/local/lib/serumdata.jar
ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n
ENV OPENSERUM_ENDPOINT=GENESYSGO
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/serumdata.jar"]
20 changes: 19 additions & 1 deletion src/main/java/com/mmorrell/serumdata/util/RpcUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.mmorrell.serumdata.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RpcUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(RpcUtil.class);
private static final PublicCluster DEFAULT_CLUSTER = PublicCluster.GENESYSGO;
private static final String CUSTOM_ENDPOINT = System.getenv("OPENSERUM_ENDPOINT");

private enum PublicCluster {
GENESYSGO ("https://ssc-dao.genesysgo.net/");
GENESYSGO ("https://ssc-dao.genesysgo.net/"),
PROJECT_SERUM("https://solana-api.projectserum.com/");

private final String endpoint;

Expand All @@ -19,6 +25,18 @@ String getEndpoint() {
}

public static String getPublicEndpoint() {
if (CUSTOM_ENDPOINT != null) {
try {
PublicCluster cluster = PublicCluster.valueOf(CUSTOM_ENDPOINT);
LOGGER.info("Using known endpoint: " + cluster.name() + " (" + cluster.getEndpoint() + ")");
return cluster.getEndpoint();
} catch (IllegalArgumentException ex) {
LOGGER.info("Using custom endpoint: " + CUSTOM_ENDPOINT);
return CUSTOM_ENDPOINT;
}
}

LOGGER.info("Using fallback endpoint: " + DEFAULT_CLUSTER.getEndpoint());
return DEFAULT_CLUSTER.getEndpoint();
}
}

0 comments on commit f9fc503

Please sign in to comment.