@@ -24,7 +24,7 @@ project build.gradle
24
24
``` groovy
25
25
26
26
ext {
27
- minterBlockchainSDK = "0.13.1 "
27
+ minterBlockchainSDK = "1.0.0 "
28
28
}
29
29
30
30
dependencies {
@@ -41,41 +41,48 @@ dependencies {
41
41
42
42
Use our nodes
43
43
``` java
44
- MinterBlockChainApi . initialize();
44
+ MinterBlockChainSDK . initialize();
45
45
```
46
46
47
47
Or it's HIGHLY RECOMMENDED to use you own node instead of Minter's.
48
48
``` java
49
- MinterBlockChainApi . initialize(" https://your-node.local" );
49
+ MinterBlockChainSDK . initialize(" https://your-node.local" );
50
50
```
51
51
52
52
### 2. Creating and signing transactions
53
53
54
54
Transactions API uses ** Builder** pattern, so it so easy to handle it.
55
55
56
- All transactions requires a valid ** nonce** value. Nonce - is a number of transaction. To get valid transaction number, you should get current number via ` BlockChainAccountRepository#getTransactionCount ` and increment it:
57
-
58
56
``` java
59
- // init object with your Minter address
60
- MinterAddress myAddress = new MinterAddress (" Mxccc3fc91a3d47dc1ee26d62611a09831f0214d62" );
61
-
62
- // get account repository from SDK singleton object
63
- BlockChainAccountRepository repo = MinterBlockChainApi . getInstance(). account();
64
-
65
- // send request
66
- repo. getTransactionCount(myAddress). enqueue(new Callback<BCResult<CountableData > > () {
67
- @Override
68
- public void onResponse (Call<BCResult<CountableData > > call , Response<BCResult<CountableData > > response ) {
69
- BigInteger txCount = response. body(). result. count;
70
-
71
- // use this incremented value as nonce to your transaction
72
- BigInteger nonce = txCount. add(new BigInteger (" 1" ));
57
+ import io.reactivex.Scheduler ;
58
+ import io.reactivex.schedulers.Schedulers ;
59
+ import network.minter.blockchain.MinterBlockChainSDK ;
60
+ import network.minter.blockchain.repo.NodeTransactionRepository ;
61
+ class MyClass {
62
+
63
+ void myMethod () {
64
+ Transaction tx = new Transaction .Builder (new BigInteger (" 1" ))
65
+ .setBlockchainId(BlockchainID . MainNet )
66
+ .setGasCoinId(DEFAULT_COIN_ID )
67
+ .sendCoin()
68
+ .setCoinId(DEFAULT_COIN_ID )
69
+ .setValue(" 0.012345" )
70
+ .setTo(toAddress)
71
+ .build();
72
+
73
+ TransactionSign sign = tx. signSingle(privateKey);
74
+
75
+ NodeTransactionRepository txRepo = MinterBlockChainSDK . getInstance(). transactions();
76
+ txRepo. sendTransaction(sign)
77
+ .observeOn(Schedulers . io())
78
+ .subscribeOn(Scheduler . io())
79
+ .subscribe(sendResult - > {
80
+ System . out. println(sendResult. txHash. toString());
81
+ }, throwable - > {
82
+ // handle error
83
+ });
73
84
}
74
-
75
- @Override
76
- public void onFailure (Call<BCResult<CountableData > > call , Throwable t ) {
77
- }
78
- })
85
+ }
79
86
```
80
87
81
88
#### 2.1 Create "Send" transaction
@@ -98,14 +105,16 @@ final PrivateKey privateKey = PrivateKey.fromMnemonic("your phrase must contains
98
105
Create transaction builder and build transaction:
99
106
``` java
100
107
Transaction tx = new Transaction .Builder (nonce)
108
+ // by default it depends on what sdk build type you used: with or without suffix "-testnet"
109
+ .setBlockchainId(BlockchainID . MainNet )
101
110
// optional: available for all transactions, but not useful for some transactions
102
- .setGasCoin( " MNT " )
111
+ .setGasCoinId( DEFAULT_COIN_ID )
103
112
// here you should select what transaction you are trying to create, builder will select exact type
104
113
.sendCoin()
105
- // required: coin to send
106
- .setCoin(coin )
107
- // required: value to send
108
- .setValue(" 10 " )
114
+ // required: coin to send represented by it's ID
115
+ .setCoinId( DEFAULT_COIN_ID )
116
+ // value to send
117
+ .setValue(" 0.012345 " )
109
118
// required: recipient address
110
119
.setTo(toAddress)
111
120
// finally, build object
@@ -115,40 +124,33 @@ Transaction tx = new Transaction.Builder(nonce)
115
124
Sign transaction using your private key
116
125
``` java
117
126
TransactionSign sign = tx. sign(privateKey);
118
-
119
- // get transaction hash - this hash you'll send to blockchain
120
- String signedTransaction = sign. getTxSign();
121
127
```
122
128
123
-
124
- So, it's easy, isn't? :)
125
-
126
129
For more transaction types see ` OperationType ` and class ` Transaction.Builder `
127
130
128
131
Now we'll send transaction to blockchain.
129
132
130
133
#### 2.2 Send "send" transaction to the Minter blockchain
131
134
132
- To send transaction to blockchain, we need to get ` BlockChainAccountRepository ` from ` MinterBlockChainApi `
135
+ To send transaction to blockchain, we need to get ` NodeTransactionRepository ` from ` MinterBlockChainSDK `
133
136
134
137
``` java
135
- BlockChainAccountRepository accountRepo = MinterBlockChainApi . getInstance(). account ();
138
+ NodeTransactionRepository accountRepo = MinterBlockChainSDK . getInstance(). transactions ();
136
139
```
137
140
138
141
To send transaction, you just need to call http request
139
142
``` java
140
143
TransactionSign sign = ...
141
- accountRepo. sendTransaction(sign). enqueue(new Callback<BCResult<TransactionSendResult > > () {
142
- @Override
143
- public void onResponse (Call<BCResult<TransactionSendResult > > call , Response<BCResult<TransactionSendResult > > response ) {
144
- // handle send result
145
- }
146
144
147
- @Override
148
- public void onFailure (Call<BCResult<TransactionSendResult > > call , Throwable t ) {
149
- // handle send error
150
- }
151
- })
145
+ NodeTransactionRepository txRepo = MinterBlockChainSDK . getInstance(). transactions();
146
+ txRepo. sendTransaction(sign)
147
+ .observeOn(Schedulers . io())
148
+ .subscribeOn(Scheduler . io())
149
+ .subscribe(sendResult - > {
150
+ System . out. println(sendResult. txHash. toString());
151
+ }, throwable - > {
152
+ // handle error
153
+ });
152
154
```
153
155
154
156
That's all!
@@ -159,10 +161,21 @@ That's all!
159
161
Javadoc available in code and in * .jar file at the bintray
160
162
161
163
## Build
162
- TODO
164
+ To create local artifacts that you can find in your home ` ~/.m2 ` directory, just run:
165
+ ``` bash
166
+ bash project_root/publish_local.sh
167
+ ```
163
168
164
169
## Tests
165
- TODO
170
+
171
+ To run unit tests, you must build bip39 and secp256k1 with host target
172
+ See: [ bip39] ( https://github.com/edwardstock/bip3x ) and [ secp256k1-java] ( https://github.com/edwardstock/native-secp256k1-java )
173
+
174
+ All these test can be runned only with testnet configuration, don't use ` gradlew test ` directly
175
+ ``` bash
176
+ cd project_root
177
+ ./gradlew testNetTestDebugUnitTest -PnativeLibPath=/path/to/native/libs
178
+ ```
166
179
167
180
## Changelog
168
181
0 commit comments