Skip to content

Commit a28b39d

Browse files
committed
Merge branch 'dev'
2 parents 412f6d0 + 942ad91 commit a28b39d

File tree

9 files changed

+199
-4
lines changed

9 files changed

+199
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ project build.gradle
2424
```groovy
2525
2626
ext {
27-
minterBlockchainSDK = "0.5.0"
27+
minterBlockchainSDK = "0.5.1"
2828
}
2929
3030
dependencies {

RELEASE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release notes
22

3+
## 0.5.1
4+
- Added gas price methods, see BlockChainBlockRepository
5+
- Opened gas price field and setter for transaction, it uses in new api
6+
- Added ability to create non-singleton instances, for using in cases when need to connect to multiple nodes
7+
8+
39
## 0.5.0
410
- BREAKING:
511
- New api methods, some fields are removed/partly moved to another place due blockchain api has been changed.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ apply plugin: 'com.jfrog.bintray'
5858

5959

6060
group = 'network.minter.android'
61-
version = '0.5.0'
61+
version = '0.5.1'
6262

6363
ext {
6464
minterMinSdk = 16
@@ -72,7 +72,7 @@ ext {
7272
buildArtifactVersion = version
7373
buildArtifactGroup = group
7474

75-
pomName = "Minter Core"
75+
pomName = "Minter Blockhain"
7676
pomUrl = "https://github.com/MinterTeam/minter-android-blockchain"
7777
pomScm = {
7878
connection = "scm:git:git://github.com/MinterTeam/minter-android-blockchain.git"

src/main/java/network/minter/blockchain/MinterBlockChainApi.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) by MinterTeam. 2018
2+
* Copyright (C) by MinterTeam. 2019
33
* @link <a href="https://github.com/MinterTeam">Org Github</a>
44
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
55
*
@@ -84,6 +84,26 @@ public static void initialize() {
8484
initialize(BASE_NODE_URL, false, new TimberLogger());
8585
}
8686

87+
/**
88+
* Use this if no need to use singleton, for example, for accessing multiple instances simultaneously
89+
* @param baseNodeApiUrl
90+
* @param debug
91+
* @param logger
92+
* @return
93+
*/
94+
public static MinterBlockChainApi createInstance(String baseNodeApiUrl, boolean debug, Mint.Leaf logger) {
95+
if (debug) {
96+
Mint.brew(logger);
97+
}
98+
MinterBlockChainApi api = new MinterBlockChainApi(baseNodeApiUrl);
99+
api.mApiService.setDebug(debug);
100+
if (debug) {
101+
api.mApiService.setDebugRequestLevel(HttpLoggingInterceptor.Level.BODY);
102+
}
103+
104+
return api;
105+
}
106+
87107
public static void initialize(String baseNodeApiUrl, boolean debug, Mint.Leaf logger) {
88108
if (INSTANCE != null) {
89109
return;

src/main/java/network/minter/blockchain/api/BlockChainBlockEndpoint.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
/*
2+
* Copyright (C) by MinterTeam. 2019
3+
* @link <a href="https://github.com/MinterTeam">Org Github</a>
4+
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
5+
*
6+
* The MIT License
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127
package network.minter.blockchain.api;
228

29+
import java.math.BigInteger;
30+
331
import network.minter.blockchain.models.BCResult;
432
import network.minter.blockchain.models.BlockInfo;
533
import retrofit2.Call;
@@ -14,4 +42,13 @@ public interface BlockChainBlockEndpoint {
1442

1543
@GET("/block")
1644
Call<BCResult<BlockInfo>> getByHeight(@Query("height") long height);
45+
46+
@GET("/max_gas")
47+
Call<BCResult<BigInteger>> getMaxGas();
48+
49+
@GET("/max_gas")
50+
Call<BCResult<BigInteger>> getMaxGasByHeight(@Query("height") long height);
51+
52+
@GET("/min_gas_price")
53+
Call<BCResult<BigInteger>> getMinGas();
1754
}

src/main/java/network/minter/blockchain/models/BCResult.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public enum ResultCode {
7373
CoinSupplyOverflow(112),
7474
@SerializedName("113")
7575
TxFromSenderAlreadyInMempool(113),
76+
@SerializedName("114")
77+
TooLowGasPrice(114),
7678

7779
// coin creation
7880
@SerializedName("201")

src/main/java/network/minter/blockchain/models/operational/Transaction.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@ public Builder setGasCoin(String coin) {
442442
return this;
443443
}
444444

445+
/**
446+
* Set transaction gas, it useful for highly loaded network, by default, value is 1
447+
* @param gasPrice
448+
* @return
449+
* @see
450+
*/
451+
public Builder setGasPrice(BigInteger gasPrice) {
452+
mTx.mGasPrice = gasPrice;
453+
return this;
454+
}
455+
445456
/**
446457
* Set arbitrary user-defined bytes
447458
* @param data max size: 1024 bytes

src/main/java/network/minter/blockchain/repo/BlockChainBlockRepository.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
/*
2+
* Copyright (C) by MinterTeam. 2019
3+
* @link <a href="https://github.com/MinterTeam">Org Github</a>
4+
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
5+
*
6+
* The MIT License
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127
package network.minter.blockchain.repo;
228

29+
import java.math.BigInteger;
30+
331
import javax.annotation.Nonnull;
432

533
import network.minter.blockchain.api.BlockChainBlockEndpoint;
@@ -27,6 +55,31 @@ public Call<BCResult<BlockInfo>> getByHeight(long height) {
2755
return getInstantService().getByHeight(height);
2856
}
2957

58+
/**
59+
* Get current minimum gas price to send transaction
60+
* @return
61+
*/
62+
public Call<BCResult<BigInteger>> getMinGasPrice() {
63+
return getInstantService().getMinGas();
64+
}
65+
66+
/**
67+
* Get current maximum gas price to send transaction
68+
* @return
69+
*/
70+
public Call<BCResult<BigInteger>> getMaxGasPrice() {
71+
return getInstantService().getMaxGas();
72+
}
73+
74+
/**
75+
* Get block maximum gas price
76+
* @param blockHeight
77+
* @return
78+
*/
79+
public Call<BCResult<BigInteger>> getMaxGasPrice(long blockHeight) {
80+
return getInstantService().getMaxGasByHeight(blockHeight);
81+
}
82+
3083
@Nonnull
3184
@Override
3285
protected Class<BlockChainBlockEndpoint> getServiceClass() {

src/test/java/network/minter/blockchain/repos/BlockRepositoryTest.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
/*
2+
* Copyright (C) by MinterTeam. 2019
3+
* @link <a href="https://github.com/MinterTeam">Org Github</a>
4+
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
5+
*
6+
* The MIT License
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
127
package network.minter.blockchain.repos;
228

329
import org.junit.Test;
430

531
import java.io.IOException;
32+
import java.math.BigInteger;
633

734
import network.minter.blockchain.MinterBlockChainApi;
835
import network.minter.blockchain.models.BCResult;
@@ -31,4 +58,43 @@ public void testGetBlockInfo() throws IOException {
3158

3259
assertNotNull(response.body().result);
3360
}
61+
62+
@Test
63+
public void testGetMinGas() throws IOException {
64+
MinterBlockChainApi api = MinterBlockChainApi.createInstance("http://159.89.107.246:8841", true, null);
65+
66+
BlockChainBlockRepository repository = api.block();
67+
Response<BCResult<BigInteger>> response = repository.getMinGasPrice().execute();
68+
69+
assertTrue(response.isSuccessful());
70+
assertTrue(response.body().isOk());
71+
72+
assertNotNull(response.body().result);
73+
}
74+
75+
@Test
76+
public void testGetMaxGas() throws IOException {
77+
MinterBlockChainApi api = MinterBlockChainApi.createInstance("http://159.89.107.246:8841", true, null);
78+
79+
BlockChainBlockRepository repository = api.block();
80+
Response<BCResult<BigInteger>> response = repository.getMaxGasPrice().execute();
81+
82+
assertTrue(response.isSuccessful());
83+
assertTrue(response.body().isOk());
84+
85+
assertNotNull(response.body().result);
86+
}
87+
88+
@Test
89+
public void testGetMaxGasByHeight() throws IOException {
90+
MinterBlockChainApi api = MinterBlockChainApi.createInstance("http://159.89.107.246:8841", true, null);
91+
92+
BlockChainBlockRepository repository = api.block();
93+
Response<BCResult<BigInteger>> response = repository.getMaxGasPrice(10).execute();
94+
95+
assertTrue(response.isSuccessful());
96+
assertTrue(response.body().isOk());
97+
98+
assertNotNull(response.body().result);
99+
}
34100
}

0 commit comments

Comments
 (0)