Skip to content

Commit fb98fd7

Browse files
authored
Merge pull request #1 from vsbogd/generate-grpc-connect
Connect to daemon via gRPC channel created via SDK
2 parents 9cef487 + a26a9c7 commit fb98fd7

25 files changed

Lines changed: 1191 additions & 0 deletions

.circleci/config.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Java Maven CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
- image: circleci/openjdk:8-jdk
11+
12+
working_directory: ~/repo
13+
14+
environment:
15+
# Customize the JVM maximum heap limit
16+
MAVEN_OPTS: -Xmx3200m
17+
18+
steps:
19+
- checkout
20+
21+
# Download and cache dependencies
22+
- restore_cache:
23+
keys:
24+
- v1-dependencies-{{ checksum "pom.xml" }}
25+
# fallback to using the latest cache if no exact match is found
26+
- v1-dependencies-
27+
28+
- run: mvn dependency:go-offline
29+
30+
- save_cache:
31+
paths:
32+
- ~/.m2
33+
key: v1-dependencies-{{ checksum "pom.xml" }}
34+
35+
# get dependencies
36+
- run:
37+
name: Get dependencies
38+
command: |
39+
curl -L https://get.web3j.io | bash
40+
source $HOME/.web3j/source.sh
41+
./get_contracts.sh
42+
# run tests!
43+
- run:
44+
name: Run tests
45+
command: mvn test
46+
- run:
47+
name: Upload coverage
48+
command: bash <(curl -s https://codecov.io/bash)

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
# maven build files
26+
target
27+
*.swp
28+
.vim-project

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SingularityNet Java SDK
2+
3+
[![CircleCI](https://circleci.com/gh/vsbogd/snet-sdk-java.svg?style=svg)](https://circleci.com/gh/vsbogd/snet-sdk-java)
4+
[![codecov](https://codecov.io/gh/vsbogd/snet-sdk-java/branch/master/graph/badge.svg)](https://codecov.io/gh/vsbogd/snet-sdk-java)
5+
6+
## Class diagram
7+
8+
![Class diagram](https://www.plantuml.com/plantuml/svg/VP9HJy8m58NV-olkupJ07v0G0aOpZMWOFXaVBkrbDAajQMz75lM_kusH30O-zlRqdFkTT1eOFSSl8mHhDWIPjdaqw3MN2s9umW8XktyMGbiclq59y4AC2XapTXvpWcy1i2wPFZuX9qxUbob4hs_knA-G1aE0TBS9Pu_4kSduPpIwA6mzbfJhmBwSEyiU9JUfhplMpg8PP-GBBQaLOJsTrCjScC_AL2KP-ueJdCzJDO3s50xYL3MhNm1-ywxGYdoJtLeVxpffnr7IgU2u_hcLw7atHLoLzseO3c-lgg7Nyd_gBd5BCZUQxA7gLGtuw7SouxXE7gALTPdZ-HQj9JE0rGIaivLlb5LMHGvGEAqWR2ChjxSBj-_sCSD09o7YDB9feI_g4TP0VPcOabNLf_u3)
9+
[Source code](https://www.planttext.com/?text=VP9HJy8m58NV-olkupJ07v0G0aOpZMWOFXaVBkrbDAajQMz75lM_kusH30O-zlRqdFkTT1eOFSSl8mHhDWIPjdaqw3MN2s9umW8XktyMGbiclq59y4AC2XapTXvpWcy1i2wPFZuX9qxUbob4hs_knA-G1aE0TBS9Pu_4kSduPpIwA6mzbfJhmBwSEyiU9JUfhplMpg8PP-GBBQaLOJsTrCjScC_AL2KP-ueJdCzJDO3s50xYL3MhNm1-ywxGYdoJtLeVxpffnr7IgU2u_hcLw7atHLoLzseO3c-lgg7Nyd_gBd5BCZUQxA7gLGtuw7SouxXE7gALTPdZ-HQj9JE0rGIaivLlb5LMHGvGEAqWR2ChjxSBj-_sCSD09o7YDB9feI_g4TP0VPcOabNLf_u3)
10+
11+
## How to build
12+
13+
Install dependencies for the first time:
14+
```
15+
curl -L https://get.web3j.io | bash
16+
source $HOME/.web3j/source.sh
17+
./get_contracts.sh
18+
```
19+
20+
Build and test:
21+
```
22+
mvn test
23+
```
24+

get_contracts.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
# use npm view singularinet-platform-contracts to get url
4+
platform_contracts_version=0.3.4
5+
platform_contracts_tgz=https://registry.npmjs.org/singularitynet-platform-contracts/-/singularitynet-platform-contracts-$platform_contracts_version.tgz
6+
7+
mkdir -p target
8+
9+
cd target
10+
wget $platform_contracts_tgz -O singularitynet-platform-contracts.tgz
11+
tar -xzf ./singularitynet-platform-contracts.tgz
12+
mv package singularitynet-platform-contracts
13+
14+
cd singularitynet-platform-contracts
15+
mkdir ../generated-sources/sol/java
16+
output=../generated-sources/sol/java
17+
package=io.singularitynet.sdk.contracts
18+
web3j solidity generate -a ./abi/MultiPartyEscrow.json --outputDir $output --package $package #--solidityTypes
19+
web3j solidity generate -a ./abi/Registry.json --outputDir $output --package $package
20+
21+
cd ..
22+
snet_daemon_version=2.0.2
23+
snet_daemon_tgz=https://github.com/singnet/snet-daemon/releases/download/v$snet_daemon_version/snet-daemon-v$snet_daemon_version-linux-amd64.tar.gz
24+
wget $snet_daemon_tgz -O snet-daemon.tar.gz
25+
tar xzf snet-daemon.tar.gz
26+
rm -rf snet-daemon
27+
mv ./snet-daemon-v$snet_daemon_version-linux-amd64 snet-daemon
28+
sed -i '8s/^/option java_package = "io.singularitynet.daemon.escrow";\n/' snet-daemon/proto/state_service.proto
29+
sed -i '2s/^/option java_package = "io.singularitynet.daemon.escrow";\n/' snet-daemon/proto/control_service.proto
30+
sed -i '2s/^/option java_package = "io.singularitynet.daemon.configuration";\n/' snet-daemon/proto/configuration_service.proto

pom.xml

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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+
<groupId>io.singularitynet</groupId>
8+
<artifactId>snet-sdk-java</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>snet-sdk-java</name>
12+
<description>SingularityNet Java SDK</description>
13+
<url>http://dev.singularitynet.io</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
<protobuf.version>3.5.1</protobuf.version>
20+
<grpc.version>1.20.0</grpc.version>
21+
</properties>
22+
23+
<repositories>
24+
<repository>
25+
<id>jitpack.io</id>
26+
<url>https://jitpack.io</url>
27+
</repository>
28+
</repositories>
29+
30+
<dependencies>
31+
32+
<!-- compile scope -->
33+
<!-- protobuf + grpc begin -->
34+
<dependency>
35+
<groupId>com.google.protobuf</groupId>
36+
<artifactId>protobuf-java</artifactId>
37+
<version>${protobuf.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.grpc</groupId>
41+
<artifactId>grpc-netty-shaded</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.grpc</groupId>
45+
<artifactId>grpc-protobuf</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.grpc</groupId>
49+
<artifactId>grpc-stub</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>javax.annotation</groupId>
53+
<artifactId>javax.annotation-api</artifactId>
54+
<version>1.3.2</version>
55+
</dependency>
56+
<!-- protobuf + grpc end -->
57+
<dependency>
58+
<groupId>org.projectlombok</groupId>
59+
<artifactId>lombok</artifactId>
60+
<version>1.18.10</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
<!-- ethereum -->
64+
<dependency>
65+
<groupId>org.web3j</groupId>
66+
<artifactId>core</artifactId>
67+
<version>4.5.5</version>
68+
</dependency>
69+
<!-- json -->
70+
<dependency>
71+
<groupId>com.google.code.gson</groupId>
72+
<artifactId>gson</artifactId>
73+
<version>2.8.5</version>
74+
</dependency>
75+
<!-- IPFS begin -->
76+
<dependency>
77+
<groupId>com.github.ipfs</groupId>
78+
<artifactId>java-ipfs-http-client</artifactId>
79+
<version>1.2.3</version>
80+
</dependency>
81+
<dependency>
82+
<groupId>com.github.multiformats</groupId>
83+
<artifactId>java-multihash</artifactId>
84+
<version>1.2.1</version>
85+
</dependency>
86+
<!-- IPFS end -->
87+
88+
<!-- test scope -->
89+
<dependency>
90+
<groupId>junit</groupId>
91+
<artifactId>junit</artifactId>
92+
<version>4.12</version>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.mockito</groupId>
97+
<artifactId>mockito-core</artifactId>
98+
<version>3.1.0</version>
99+
<scope>test</scope>
100+
</dependency>
101+
<!-- json start -->
102+
<dependency>
103+
<groupId>javax.json</groupId>
104+
<artifactId>javax.json-api</artifactId>
105+
<version>1.1.4</version>
106+
<scope>test</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.glassfish</groupId>
110+
<artifactId>javax.json</artifactId>
111+
<version>1.1.4</version>
112+
<scope>test</scope>
113+
</dependency>
114+
<!-- json end -->
115+
116+
</dependencies>
117+
118+
<dependencyManagement>
119+
<dependencies>
120+
<dependency>
121+
<groupId>io.grpc</groupId>
122+
<artifactId>grpc-bom</artifactId>
123+
<version>${grpc.version}</version>
124+
<type>pom</type>
125+
<scope>import</scope>
126+
</dependency>
127+
</dependencies>
128+
</dependencyManagement>
129+
130+
<build>
131+
<extensions>
132+
<extension>
133+
<groupId>kr.motd.maven</groupId>
134+
<artifactId>os-maven-plugin</artifactId>
135+
<version>1.6.2</version>
136+
</extension>
137+
</extensions>
138+
139+
<plugins>
140+
<plugin>
141+
<groupId>org.xolstice.maven.plugins</groupId>
142+
<artifactId>protobuf-maven-plugin</artifactId>
143+
<version>0.6.1</version>
144+
<configuration>
145+
<!-- artifact to download binary protobuf compiler -->
146+
<protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
147+
<!-- make maven using GRPC plugin for compile-custom and
148+
test-compile-custom goals -->
149+
<pluginId>grpc-java</pluginId>
150+
<!-- artifact to download GRPC protobuf compiler plugin -->
151+
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
152+
</configuration>
153+
<executions>
154+
<execution>
155+
<goals>
156+
<!-- compile .proto files located under main directory -->
157+
<goal>compile</goal>
158+
<goal>compile-custom</goal>
159+
<!-- compile .proto files located under test directory -->
160+
<goal>test-compile</goal>
161+
<goal>test-compile-custom</goal>
162+
</goals>
163+
</execution>
164+
</executions>
165+
</plugin>
166+
167+
<plugin>
168+
<groupId>org.codehaus.mojo</groupId>
169+
<artifactId>build-helper-maven-plugin</artifactId>
170+
<version>3.0.0</version>
171+
<executions>
172+
<execution>
173+
<id>add-source</id>
174+
<phase>generate-sources</phase>
175+
<goals>
176+
<goal>add-source</goal>
177+
</goals>
178+
<configuration>
179+
<sources>
180+
<source>${project.build.directory}/generated-sources/sol/java</source>
181+
</sources>
182+
</configuration>
183+
</execution>
184+
</executions>
185+
</plugin>
186+
187+
<plugin>
188+
<groupId>org.jacoco</groupId>
189+
<artifactId>jacoco-maven-plugin</artifactId>
190+
<version>0.8.2</version>
191+
<executions>
192+
<execution>
193+
<goals>
194+
<goal>prepare-agent</goal>
195+
</goals>
196+
</execution>
197+
<!-- attached to Maven test phase -->
198+
<execution>
199+
<id>report</id>
200+
<phase>test</phase>
201+
<goals>
202+
<goal>report</goal>
203+
</goals>
204+
</execution>
205+
</executions>
206+
</plugin>
207+
208+
</plugins>
209+
210+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
211+
<plugins>
212+
<plugin>
213+
<artifactId>maven-clean-plugin</artifactId>
214+
<version>3.1.0</version>
215+
</plugin>
216+
<plugin>
217+
<artifactId>maven-site-plugin</artifactId>
218+
<version>3.7.1</version>
219+
</plugin>
220+
<plugin>
221+
<artifactId>maven-project-info-reports-plugin</artifactId>
222+
<version>3.0.0</version>
223+
</plugin>
224+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
225+
<plugin>
226+
<artifactId>maven-resources-plugin</artifactId>
227+
<version>3.0.2</version>
228+
</plugin>
229+
<plugin>
230+
<artifactId>maven-compiler-plugin</artifactId>
231+
<version>3.8.0</version>
232+
</plugin>
233+
<plugin>
234+
<artifactId>maven-surefire-plugin</artifactId>
235+
<version>2.22.1</version>
236+
</plugin>
237+
<plugin>
238+
<artifactId>maven-jar-plugin</artifactId>
239+
<version>3.0.2</version>
240+
</plugin>
241+
<plugin>
242+
<artifactId>maven-install-plugin</artifactId>
243+
<version>2.5.2</version>
244+
</plugin>
245+
<plugin>
246+
<artifactId>maven-deploy-plugin</artifactId>
247+
<version>2.8.2</version>
248+
</plugin>
249+
</plugins>
250+
</pluginManagement>
251+
</build>
252+
253+
<reporting>
254+
<plugins>
255+
<plugin>
256+
<artifactId>maven-project-info-reports-plugin</artifactId>
257+
</plugin>
258+
</plugins>
259+
</reporting>
260+
</project>

0 commit comments

Comments
 (0)