Skip to content

Commit 0fff4c9

Browse files
committed
optional params
1 parent 65ad488 commit 0fff4c9

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

hedera-microprofile/src/main/java/com/openelements/hedera/microprofile/ClientProvider.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ private HederaNetwork getHederaNetwork() {
7272
if (networkConfiguration == null) {
7373
throw new IllegalStateException("network value is null");
7474
}
75-
final String networkName = networkConfiguration.getName();
76-
if (networkName == null) {
77-
throw new IllegalStateException("networkName is null");
78-
}
79-
return HederaNetwork.findByName(networkName)
75+
return networkConfiguration.getName()
76+
.map(n -> HederaNetwork.findByName(n).orElse(HederaNetwork.CUSTOM))
8077
.orElse(HederaNetwork.CUSTOM);
8178
}
8279

@@ -89,11 +86,15 @@ private Client createClient() {
8986
networkConfiguration.getNodes()
9087
.forEach(node -> nodes.put(node.ip() + ":" + node.port(), AccountId.fromString(node.account())));
9188
Client client = Client.forNetwork(nodes);
92-
try {
93-
client.setMirrorNetwork(List.of(networkConfiguration.getMirrornode()));
94-
} catch (InterruptedException e) {
95-
throw new RuntimeException("Error setting mirror network", e);
96-
}
89+
networkConfiguration.getMirrornode()
90+
.map(mirrorNode -> List.of(mirrorNode))
91+
.ifPresent(mirrorNodes -> {
92+
try {
93+
client.setMirrorNetwork(mirrorNodes);
94+
} catch (InterruptedException e) {
95+
throw new RuntimeException("Error setting mirror network", e);
96+
}
97+
});
9798
client.setOperator(accountId, privateKey);
9899
return client;
99100
} else {

hedera-microprofile/src/main/java/com/openelements/hedera/microprofile/HieroNetworkConfiguration.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import jakarta.enterprise.context.Dependent;
44
import jakarta.inject.Inject;
5+
import java.util.Optional;
56
import java.util.Set;
67
import java.util.stream.Collectors;
7-
import java.util.stream.Stream;
88
import org.eclipse.microprofile.config.inject.ConfigProperties;
99
import org.eclipse.microprofile.config.inject.ConfigProperty;
1010

@@ -15,28 +15,28 @@ public class HieroNetworkConfiguration {
1515
public record Node(String ip, String port, String account) {
1616
}
1717

18-
private String name;
18+
private Optional<String> name;
1919

2020
@Inject
21-
@ConfigProperty(name = "nodes", defaultValue = " ") //TODO: We need a better default value
22-
private String[] nodes;
21+
@ConfigProperty(name = "nodes")
22+
private Optional<Set<String>> nodes;
2323

24-
@ConfigProperty(name = "mirrornode", defaultValue = " ") //TODO: We need a better default value
25-
private String mirrornode;
24+
@ConfigProperty(name = "mirrornode")
25+
private Optional<String> mirrornode;
2626

27-
public String getName() {
27+
public Optional<String> getName() {
2828
return name;
2929
}
3030

31-
public String getMirrornode() {
31+
public Optional<String> getMirrornode() {
3232
return mirrornode;
3333
}
3434

3535
public Set<Node> getNodes() {
36-
if (nodes == null) {
36+
if (!nodes.isPresent()) {
3737
return Set.of();
3838
}
39-
return Stream.of(nodes)
39+
return nodes.get().stream()
4040
.map(n -> {
4141
// 172.234.134.4:8080:0.0.3
4242
final String[] split = n.split(":");

0 commit comments

Comments
 (0)