Skip to content

Commit

Permalink
Support custom network configs by SPI provider
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrik Ebbers <[email protected]>
  • Loading branch information
hendrikebbers committed Feb 3, 2025
1 parent d1c775c commit 72c4974
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import java.util.Optional;
import java.util.Set;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Interface that provides all needed configuration settings for a network. Operator of a Hiero based network should
* implement this interface to provide the necessary configuration settings. Implementations can be provided via Java
* SPI as defined in {@link com.openelements.hiero.base.config.provider.NetworkSettingsProvider}.
*
* @see com.openelements.hiero.base.config.provider.NetworkSettingsProvider
* @see java.util.ServiceLoader
*/
public interface NetworkSettings {

Logger logger = LoggerFactory.getLogger(NetworkSettings.class);

/**
* Returns the network identifier.
*
Expand Down Expand Up @@ -43,16 +47,37 @@ public interface NetworkSettings {
@NonNull
Set<ConsensusNode> getConsensusNodes();

/**
* Returns the chain ID of the network.
*
* @return the chain ID of the network
*/
@NonNull
Optional<Long> chainId();

/**
* Returns the relay URL of the network.
*
* @return the relay URL of the network.
*/
@NonNull
Optional<String> relayUrl();

/**
* Returns all available network settings.
*
* @return all available network settings
*/
static Set<NetworkSettings> all() {
return NetworkSettingsProviderLoader.getInstance().all();
}

/**
* Returns the network settings for the given identifier.
*
* @param identifier the identifier of the network
* @return the network settings for the given identifier
*/
static Optional<NetworkSettings> forIdentifier(String identifier) {
return NetworkSettingsProviderLoader.getInstance().forIdentifier(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@
import com.openelements.hiero.base.config.NetworkSettings;
import java.util.Set;

/**
* SPI interface to provide predefined {@link NetworkSettings} instances. Java SPI functionality is documented at
* {@link java.util.ServiceLoader}.
*/
public interface NetworkSettingsProvider {

/**
* Returns the name of the provider.
*
* @return the name of the provider
*/
String getName();

/**
* Return a set of {@link NetworkSettings} instances provided by this provider.
*
* @return a set of {@link NetworkSettings} instances
*/
Set<NetworkSettings> createNetworkSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public ContractVerificationState checkVerification(@NonNull final ContractId con
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, (request, response) -> {
handleError(request, response);
}).onStatus(HttpStatusCode::is5xxServerError, (request, response) -> {
throw new RuntimeException(
"Server error (" + response.getStatusCode() + ") for request '" + request.getURI()
+ "'");
}).body(String.class);

final JsonNode rootNode = objectMapper.readTree(resultBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIf;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,6 +36,7 @@ private boolean isNotSupportedChain() {
}

@Test
@Disabled
@DisabledIf(value = "isNotSupportedChain", disabledReason = "Verification is currently not supported for custom chains")
void test() throws Exception {
//given
Expand Down

0 comments on commit 72c4974

Please sign in to comment.