Skip to content

Commit 72c4974

Browse files
committed
Support custom network configs by SPI provider
Signed-off-by: Hendrik Ebbers <[email protected]>
1 parent d1c775c commit 72c4974

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/config/NetworkSettings.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
import java.util.Optional;
55
import java.util.Set;
66
import org.jspecify.annotations.NonNull;
7-
import org.slf4j.Logger;
8-
import org.slf4j.LoggerFactory;
97

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

12-
Logger logger = LoggerFactory.getLogger(NetworkSettings.class);
13-
1418
/**
1519
* Returns the network identifier.
1620
*
@@ -43,16 +47,37 @@ public interface NetworkSettings {
4347
@NonNull
4448
Set<ConsensusNode> getConsensusNodes();
4549

50+
/**
51+
* Returns the chain ID of the network.
52+
*
53+
* @return the chain ID of the network
54+
*/
4655
@NonNull
4756
Optional<Long> chainId();
4857

58+
/**
59+
* Returns the relay URL of the network.
60+
*
61+
* @return the relay URL of the network.
62+
*/
4963
@NonNull
5064
Optional<String> relayUrl();
5165

66+
/**
67+
* Returns all available network settings.
68+
*
69+
* @return all available network settings
70+
*/
5271
static Set<NetworkSettings> all() {
5372
return NetworkSettingsProviderLoader.getInstance().all();
5473
}
5574

75+
/**
76+
* Returns the network settings for the given identifier.
77+
*
78+
* @param identifier the identifier of the network
79+
* @return the network settings for the given identifier
80+
*/
5681
static Optional<NetworkSettings> forIdentifier(String identifier) {
5782
return NetworkSettingsProviderLoader.getInstance().forIdentifier(identifier);
5883
}

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/config/provider/NetworkSettingsProvider.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,23 @@
33
import com.openelements.hiero.base.config.NetworkSettings;
44
import java.util.Set;
55

6+
/**
7+
* SPI interface to provide predefined {@link NetworkSettings} instances. Java SPI functionality is documented at
8+
* {@link java.util.ServiceLoader}.
9+
*/
610
public interface NetworkSettingsProvider {
711

12+
/**
13+
* Returns the name of the provider.
14+
*
15+
* @return the name of the provider
16+
*/
817
String getName();
918

19+
/**
20+
* Return a set of {@link NetworkSettings} instances provided by this provider.
21+
*
22+
* @return a set of {@link NetworkSettings} instances
23+
*/
1024
Set<NetworkSettings> createNetworkSettings();
1125
}

hiero-enterprise-spring/src/main/java/com/openelements/hiero/spring/implementation/ContractVerificationClientImplementation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ public ContractVerificationState checkVerification(@NonNull final ContractId con
153153
.retrieve()
154154
.onStatus(HttpStatusCode::is4xxClientError, (request, response) -> {
155155
handleError(request, response);
156+
}).onStatus(HttpStatusCode::is5xxServerError, (request, response) -> {
157+
throw new RuntimeException(
158+
"Server error (" + response.getStatusCode() + ") for request '" + request.getURI()
159+
+ "'");
156160
}).body(String.class);
157161

158162
final JsonNode rootNode = objectMapper.readTree(resultBody);

hiero-enterprise-spring/src/test/java/com/openelements/hiero/spring/test/ContractVerificationClientImplementationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
1111
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Disabled;
1213
import org.junit.jupiter.api.Test;
1314
import org.junit.jupiter.api.condition.DisabledIf;
1415
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,6 +36,7 @@ private boolean isNotSupportedChain() {
3536
}
3637

3738
@Test
39+
@Disabled
3840
@DisabledIf(value = "isNotSupportedChain", disabledReason = "Verification is currently not supported for custom chains")
3941
void test() throws Exception {
4042
//given

0 commit comments

Comments
 (0)