Skip to content

Commit 72c9298

Browse files
committed
sample added
1 parent 9f84040 commit 72c9298

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

hedera-spring-sample/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.open-elements.hedera</groupId>
9+
<artifactId>hedera-enterprise</artifactId>
10+
<version>0.3.0-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>hedera-spring-sample</artifactId>
15+
16+
<name>Hedera Enterprise Spring Sample</name>
17+
<description>Sample for Hedera in Spring</description>
18+
<url>https://github.com/OpenElements/hedera-enterprise</url>
19+
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
<version>3.3.0</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-web</artifactId>
30+
<version>3.3.0</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>${project.groupId}</groupId>
34+
<artifactId>hedera-spring</artifactId>
35+
<version>${project.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.grpc</groupId>
39+
<artifactId>grpc-okhttp</artifactId>
40+
<version>1.64.0</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.grpc</groupId>
44+
<artifactId>grpc-inprocess</artifactId>
45+
<version>1.64.0</version>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-deploy-plugin</artifactId>
54+
<configuration>
55+
<skip>true</skip>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.jreleaser</groupId>
60+
<artifactId>jreleaser-maven-plugin</artifactId>
61+
<configuration>
62+
<skip>true</skip>
63+
</configuration>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
68+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.openelements.hedera.spring.sample;
2+
3+
import com.openelements.hedera.spring.EnableHedera;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
@EnableHedera
9+
public class Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Application.class, args);
13+
}
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.openelements.hedera.spring.sample;
2+
3+
import com.openelements.hedera.base.protocol.AccountBalanceRequest;
4+
import com.openelements.hedera.base.protocol.AccountBalanceResponse;
5+
import com.openelements.hedera.base.protocol.ProtocolLayerClient;
6+
import java.util.Objects;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
public class HederaEndpoint {
12+
13+
private final ProtocolLayerClient client;
14+
15+
public HederaEndpoint(final ProtocolLayerClient client) {
16+
this.client = Objects.requireNonNull(client);
17+
}
18+
19+
@GetMapping("/balance")
20+
public String getBalance() {
21+
try {
22+
final AccountBalanceRequest request = AccountBalanceRequest.of("0.0.100");
23+
final AccountBalanceResponse response = client.executeAccountBalanceQuery(request);
24+
return response.hbars().toString();
25+
} catch (final Exception e) {
26+
throw new RuntimeException("Error in Hedera call", e);
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring.config.import=optional:file:.env[.properties]
2+
3+
spring.hedera.accountId=${HEDERA_ACCOUNT_ID:0.0.123}
4+
spring.hedera.privateKey=${HEDERA_PRIVATE_KEY}
5+
spring.hedera.network.name=${HEDERA_NETWORK:testnet}
6+
7+
logging.level.com.openelements=DEBUG
8+
logging.pattern.console=%d{HH:mm:ss.SSS} %logger{36} - %msg%n

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<module>hedera-base</module>
4444
<module>hedera-spring</module>
4545
<module>hedera-microprofile</module>
46+
<module>hedera-spring-sample</module>
4647
</modules>
4748

4849
<build>

0 commit comments

Comments
 (0)