Skip to content

Commit ae754cd

Browse files
authored
Merge pull request #29 from vechain/dev
Fix issue #28
2 parents 64753fc + 2484803 commit ae754cd

File tree

8 files changed

+429
-368
lines changed

8 files changed

+429
-368
lines changed

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
thor-client-sdk4j is licensed under the MIT LICENSE, also included in LICENSE file in the repository.
4+
Copyright (c) 2019 VeChain
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ A SDK toolkit for client to call VeChainThor Restful API.
77
Requires JDK8.
88

99
- - - -
10-
latest version 0.0.9
10+
latest version 0.0.10
1111

1212
- - - -
1313
default package jar without dependencies,use -Pall to build all in one jar
1414

1515
## License
16-
Thor Java Client SDK is licensed under the GNU Lesser General Public License v3.0, also included in LICENSE file in repository.
16+
Thor Java Client SDK is licensed under the MIT LICENSE, also included in LICENSE file in the repository.
1717
- - - -
1818

1919
## Set blockchain nodes provider
@@ -845,7 +845,7 @@ Package the jar with maven
845845
```
846846
mvn clean package -Dmaven.test.skip=true
847847
848-
The maven will generate the jar file in folder target: thor-client-sdk4j-0.0.9.jar
848+
The maven will generate the jar file in folder target: thor-client-sdk4j-0.0.10.jar
849849
850850
```
851851

@@ -857,9 +857,9 @@ There is a example transaction file in src/main/resources/exchange_example.xlsx,
857857

858858
```
859859
860-
java -jar thor-client-sdk4j-0.0.9.jar getChainTag {blockchain-server-url}
860+
java -jar thor-client-sdk4j-0.0.10.jar getChainTag {blockchain-server-url}
861861
862-
eg. java -jar thor-client-sdk4j-0.0.9.jar getChainTag http://localhost:8669
862+
eg. java -jar thor-client-sdk4j-0.0.10.jar getChainTag http://localhost:8669
863863
864864
ChainTag:
865865
0x27
@@ -870,9 +870,9 @@ ChainTag:
870870
#### Get blockRef:
871871

872872
```
873-
java -jar thor-client-sdk4j-0.0.9.jar getBlockRef {blockchain-server-url}
873+
java -jar thor-client-sdk4j-0.0.10.jar getBlockRef {blockchain-server-url}
874874
875-
eg. java -jar thor-client-sdk4j-0.0.9.jar getBlockRef http://localhost:8669
875+
eg. java -jar thor-client-sdk4j-0.0.10.jar getBlockRef http://localhost:8669
876876
877877
BlockRef:
878878
0x0000695540f491a5
@@ -882,9 +882,9 @@ BlockRef:
882882
#### Create wallet:
883883

884884
```
885-
java -jar thor-client-sdk4j-0.0.9.jar createWallet {wallet-password} {keystore-file-path}(optional, defalut: ./keystore.json)
885+
java -jar thor-client-sdk4j-0.0.10.jar createWallet {wallet-password} {keystore-file-path}(optional, defalut: ./keystore.json)
886886
887-
eg. java -jar thor-client-sdk4j-0.0.9.jar createWallet <your password> <keystore-file-path>
887+
eg. java -jar thor-client-sdk4j-0.0.10.jar createWallet <your password> <keystore-file-path>
888888
889889
The keystore.json file will generate in current folder.
890890
@@ -922,9 +922,9 @@ The wallet created successfully and the key store is:
922922
#### Get block:
923923

924924
```
925-
java -jar thor-client-sdk4j-0.0.9.jar getBlock {blockchain-server-url}
925+
java -jar thor-client-sdk4j-0.0.10.jar getBlock {blockchain-server-url}
926926
927-
eg. java -jar thor-client-sdk4j-0.0.9.jar getBlock http://localhost:8669
927+
eg. java -jar thor-client-sdk4j-0.0.10.jar getBlock http://localhost:8669
928928
929929
Block:
930930
{
@@ -953,9 +953,9 @@ Block:
953953

954954
```
955955
956-
java -jar thor-client-sdk4j-0.0.9.jar getTransaction {transaction-id} {blockchain-server-url}
956+
java -jar thor-client-sdk4j-0.0.10.jar getTransaction {transaction-id} {blockchain-server-url}
957957
958-
eg. java -jar thor-client-sdk4j-0.0.9.jar getTransaction 0x19dd77d28ef70be8c924319a6c08b996dd456fa36f29f2427dbda90087a8a897 http://localhost:8669
958+
eg. java -jar thor-client-sdk4j-0.0.10.jar getTransaction 0x19dd77d28ef70be8c924319a6c08b996dd456fa36f29f2427dbda90087a8a897 http://localhost:8669
959959
960960
Transaction:
961961
{
@@ -978,9 +978,9 @@ Transaction:
978978

979979
```
980980
981-
java -jar thor-client-sdk4j-0.0.9.jar getTransactionReceipt {transaction-id} {blockchain-server-url}
981+
java -jar thor-client-sdk4j-0.0.10.jar getTransactionReceipt {transaction-id} {blockchain-server-url}
982982
983-
eg. java -jar thor-client-sdk4j-0.0.9.jar getTransactionReceipt 0x6b99c0f1ebfa3b9d93dcfc503f468104ac74271728841551aaa44115d080f5b5 http://localhost:8669
983+
eg. java -jar thor-client-sdk4j-0.0.10.jar getTransactionReceipt 0x6b99c0f1ebfa3b9d93dcfc503f468104ac74271728841551aaa44115d080f5b5 http://localhost:8669
984984
985985
Receipt:
986986
{
@@ -1017,9 +1017,9 @@ Receipt:
10171017
#### Sign transactions:
10181018

10191019
```
1020-
java -jar thor-client-sdk4j-0.0.9.jar sign {your-file-path} {privateKey}
1020+
java -jar thor-client-sdk4j-0.0.10.jar sign {your-file-path} {privateKey}
10211021
1022-
eg. java -jar thor-client-sdk4j-0.0.9.jar sign src/main/resources/exchange_example.xlsx 0xe0b80216ba7b880d85966b38fcd8f7253882bb1386b68b33a8e0b60775e947c0
1022+
eg. java -jar thor-client-sdk4j-0.0.10.jar sign src/main/resources/exchange_example.xlsx 0xe0b80216ba7b880d85966b38fcd8f7253882bb1386b68b33a8e0b60775e947c0
10231023
10241024
Raw Transaction:
10251025
0xf8a3819a8702819f5cfc12d38202d0f842e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f8000080e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f80000808082a4108088f06f91293e58610dc0b84173346fba62605d510895a0d240b89a38e0b87fd8a58df2ce17075cd493e8e316528b4ed0f049cef1710936bbd4bd3af23eb3ffb3740dc0fb59db585714dbeaa001
@@ -1028,9 +1028,9 @@ Raw Transaction:
10281028
#### Sign VTHO transactions:
10291029

10301030
```
1031-
java -jar thor-client-sdk4j-0.0.9.jar signVTHO {your-file-path} {privateKey}
1031+
java -jar thor-client-sdk4j-0.0.10.jar signVTHO {your-file-path} {privateKey}
10321032
1033-
eg. java -jar thor-client-sdk4j-0.0.9.jar signVTHO src/main/resources/exchange_example.xlsx 0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65
1033+
eg. java -jar thor-client-sdk4j-0.0.10.jar signVTHO src/main/resources/exchange_example.xlsx 0xdce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65
10341034
10351035
Raw Transaction:
10361036
0xf9011d81c787015e41be43bb958202d0f8bcf85c940000000000000000000000000000456e6572677980b844a9059cbb000000000000000000000000d3ef28df6b553ed2fc47259e8134319cb1121a2a0000000000000000000000000000000000000000000027cf801b9d4f7d800000f85c940000000000000000000000000000456e6572677980b844a9059cbb000000000000000000000000f881a94423f22ee9a0e3e1442f515f43c966b7ed0000000000000000000000000000000000000000000027cf801b9d4f7d8000008082a41080887650b326b78e0c57c0b841fe27b8866d8a658a66a2d8241a310d1ef72e2954d397fc52aa5b4295f9686d0f6705301acc9a0aac6e9e0f93e3aa6fe0a07ff48e4e3287d0db45905d8a0756eb01
@@ -1041,9 +1041,9 @@ Raw Transaction:
10411041

10421042
```
10431043
1044-
java -jar thor-client-sdk4j-0.0.9.jar signAndSend {blockchain-server-url} {privateKey} {your-file-path}
1044+
java -jar thor-client-sdk4j-0.0.10.jar signAndSend {blockchain-server-url} {privateKey} {your-file-path}
10451045
1046-
eg. java -jar thor-client-sdk4j-0.0.9.jar signAndSend http://localhost:8669 0xe0b80216ba7b880d85966b38fcd8f7253882bb1386b68b33a8e0b60775e947c0 src/main/resources/exchange_example.xlsx
1046+
eg. java -jar thor-client-sdk4j-0.0.10.jar signAndSend http://localhost:8669 0xe0b80216ba7b880d85966b38fcd8f7253882bb1386b68b33a8e0b60775e947c0 src/main/resources/exchange_example.xlsx
10471047
10481048
Send Result:
10491049
{"id":"0xd751c50b81c1f13ebd86f4fcd0028a501b6c792fa8b5bbf64028b924a6b2efc9"}
@@ -1056,9 +1056,9 @@ Send Result:
10561056

10571057
```
10581058
1059-
java -jar thor-client-sdk4j-0.0.9.jar sendRaw {blockchain-server-url} {raw}
1059+
java -jar thor-client-sdk4j-0.0.10.jar sendRaw {blockchain-server-url} {raw}
10601060
1061-
eg. java -jar thor-client-sdk4j-0.0.9.jar sendRaw http://localhost:8669 0xf8a3819a8702819f5cfc12d38202d0f842e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f8000080e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f80000808082a4108088f06f91293e58610dc0b84173346fba62605d510895a0d240b89a38e0b87fd8a58df2ce17075cd493e8e316528b4ed0f049cef1710936bbd4bd3af23eb3ffb3740dc0fb59db585714dbeaa001
1061+
eg. java -jar thor-client-sdk4j-0.0.10.jar sendRaw http://localhost:8669 0xf8a3819a8702819f5cfc12d38202d0f842e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f8000080e094d3ef28df6b553ed2fc47259e8134319cb1121a2a89364200111c48f80000808082a4108088f06f91293e58610dc0b84173346fba62605d510895a0d240b89a38e0b87fd8a58df2ce17075cd493e8e316528b4ed0f049cef1710936bbd4bd3af23eb3ffb3740dc0fb59db585714dbeaa001
10621062
10631063
Send Result:
10641064
{"id":"0xd751c50b81c1f13ebd86f4fcd0028a501b6c792fa8b5bbf64028b924a6b2efc9"}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.vechain.client</groupId>
77
<artifactId>thor-client-sdk4j</artifactId>
8-
<version>0.0.9</version>
8+
<version>0.0.10</version>
99
<packaging>jar</packaging>
1010

1111
<modelVersion>4.0.0</modelVersion>

src/main/java/com/vechain/thorclient/core/model/blockchain/NodeProvider.java

Lines changed: 99 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,92 +4,106 @@
44
import com.vechain.thorclient.utils.StringUtils;
55

66
/**
7-
* The blockchain node provider pojo object.
8-
* Set and get url and connecting timeout(in milliseconds).
7+
* The blockchain node provider pojo object. Set and get url and connecting
8+
* timeout(in milliseconds).
99
*/
1010
public class NodeProvider {
1111

12-
private static NodeProvider INSTANCE = new NodeProvider();
13-
14-
public static NodeProvider getNodeProvider() {
15-
return INSTANCE;
16-
}
17-
18-
private NodeProvider() {
19-
this.socketTimeout = 5000;
20-
this.connectTimeout = 5000;
21-
}
22-
23-
/**
24-
* get provider url
25-
* @return the url of the nodes.
26-
*/
27-
public String getProvider() {
28-
if (StringUtils.isBlank(this.provider) || !this.provider.startsWith("http")) {
29-
throw new RuntimeException("The blockchain provider url must be set.");
30-
}
31-
return provider;
32-
}
33-
34-
/**
35-
* Set provider url
36-
* @param provider the completed url of the nodes
37-
*/
38-
public void setProvider(String provider) {
39-
this.provider = provider;
40-
}
41-
42-
/**
43-
* set socket timeout
44-
* @return milliseconds
45-
*/
46-
public int getSocketTimeout() {
47-
return socketTimeout;
48-
}
49-
50-
/**
51-
* Set socket timeout
52-
* @param timeout milliseconds
53-
*/
54-
public void setSocketTimeout(int timeout) {
55-
this.socketTimeout = timeout;
56-
}
57-
58-
59-
/**
60-
* Set connect timeout, socket timeout
61-
* @param timeout milliseconds
62-
*/
63-
public void setTimeout(int timeout){
64-
AbstractClient.setTimeout(timeout);
65-
}
66-
67-
68-
public void setConnectTimeout(int connectTimeout) {
69-
this.connectTimeout = connectTimeout;
70-
}
71-
72-
public int getConnectTimeout(){
73-
return this.connectTimeout;
74-
}
75-
76-
77-
public String getWsProvider() {
78-
if (StringUtils.isBlank(this.wsProvider) || !this.wsProvider.startsWith("ws")) {
79-
throw new RuntimeException("The blockchain provider url must be set.");
80-
}
81-
return wsProvider;
82-
}
83-
84-
public void setWsProvider(String wsProvider) {
85-
this.wsProvider = wsProvider;
86-
}
87-
88-
private String provider;
89-
90-
91-
private String wsProvider;
92-
private int socketTimeout;
93-
private int connectTimeout;
94-
12+
private static NodeProvider INSTANCE = new NodeProvider();
13+
14+
public static NodeProvider getNodeProvider() {
15+
return INSTANCE;
16+
}
17+
18+
private NodeProvider() {
19+
this.socketTimeout = 5000;
20+
this.connectTimeout = 5000;
21+
}
22+
23+
/**
24+
* get provider url
25+
*
26+
* @return the url of the nodes.
27+
*/
28+
public String getProvider() {
29+
String url = StringUtils.isBlank(getProviderThreadLocal()) ? this.provider : getProviderThreadLocal();
30+
if (StringUtils.isBlank(url) || !url.startsWith("http")) {
31+
throw new RuntimeException("The blockchain provider url must be set.");
32+
}
33+
return url;
34+
}
35+
36+
/**
37+
* Set provider url
38+
*
39+
* @param provider the completed url of the nodes
40+
*/
41+
public void setProvider(String provider) {
42+
this.provider = provider;
43+
}
44+
45+
/**
46+
* set socket timeout
47+
*
48+
* @return milliseconds
49+
*/
50+
public int getSocketTimeout() {
51+
return socketTimeout;
52+
}
53+
54+
/**
55+
* Set socket timeout
56+
*
57+
* @param timeout milliseconds
58+
*/
59+
public void setSocketTimeout(int timeout) {
60+
this.socketTimeout = timeout;
61+
}
62+
63+
/**
64+
* Set connect timeout, socket timeout
65+
*
66+
* @param timeout milliseconds
67+
*/
68+
public void setTimeout(int timeout) {
69+
AbstractClient.setTimeout(timeout);
70+
}
71+
72+
public void setConnectTimeout(int connectTimeout) {
73+
this.connectTimeout = connectTimeout;
74+
}
75+
76+
public int getConnectTimeout() {
77+
return this.connectTimeout;
78+
}
79+
80+
public String getWsProvider() {
81+
if (StringUtils.isBlank(this.wsProvider) || !this.wsProvider.startsWith("ws")) {
82+
throw new RuntimeException("The blockchain provider url must be set.");
83+
}
84+
return wsProvider;
85+
}
86+
87+
public void setWsProvider(String wsProvider) {
88+
this.wsProvider = wsProvider;
89+
}
90+
91+
private String provider;
92+
93+
private String wsProvider;
94+
private int socketTimeout;
95+
private int connectTimeout;
96+
private static ThreadLocal<String> providerThreadLocal = new ThreadLocal<String>();
97+
98+
public void setProviderThreadLocal(String url) {
99+
providerThreadLocal.set(url);
100+
}
101+
102+
public String getProviderThreadLocal() {
103+
return providerThreadLocal.get();
104+
}
105+
106+
public void cleanProviderThreadLocal() {
107+
providerThreadLocal.remove();
108+
}
95109
}

0 commit comments

Comments
 (0)