Skip to content

Commit 1b7bac5

Browse files
committed
refactoring, added transactions from new proposals, tests, added RxJava3
1 parent 45e24d3 commit 1b7bac5

File tree

99 files changed

+4503
-2073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4503
-2073
lines changed

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+
## 1.0.0
4+
- **BREAKING CHANGES**
5+
- Now communication with node api works with RxJava3
6+
- Base API response now in root of json, so BcResult<T> is just NodeResult and each response object inherits this class
7+
8+
39
## 0.13.1
410
- Ability to reset transaction data and payload in external transaction builder
511

build.gradle

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ buildscript {
3232
}
3333
dependencies {
3434
classpath 'com.android.tools.build:gradle:4.0.1'
35-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
35+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
3636
}
3737
}
3838

@@ -57,14 +57,14 @@ apply plugin: 'com.jfrog.bintray'
5757

5858

5959
group = 'network.minter.android'
60-
version = '0.13.1'
60+
version = '1.0.0'
6161

6262
ext {
6363
minterMinSdk = 16
6464
minterMaxSdk = 29
6565
minterBuildTools = "29.0.3"
6666
minterLibSupport = "28.0.0"
67-
minterCoreVers = "0.7.1"
67+
minterCoreVers = "1.0.0"
6868

6969

7070
buildArtifactName = project.name
@@ -187,25 +187,28 @@ dependencies {
187187

188188
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
189189

190-
// network
191-
implementation 'com.squareup.okhttp3:okhttp:4.5.0'
192-
implementation 'com.squareup.okhttp3:logging-interceptor:4.5.0'
193-
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
194-
implementation 'com.squareup.retrofit2:converter-gson:2.8.1'
190+
// network and rxjava
191+
implementation 'com.squareup.okhttp3:okhttp:4.8.1'
192+
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.1'
193+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
194+
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
195+
implementation 'io.reactivex.rxjava3:rxjava:3.0.5'
196+
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
195197

196-
implementation 'org.parceler:parceler-api:1.1.12'
197-
annotationProcessor 'org.parceler:parceler:1.1.12'
198+
implementation 'org.parceler:parceler-api:1.1.13'
199+
annotationProcessor 'org.parceler:parceler:1.1.13'
198200

199201
// stuff
200202
implementation 'com.jakewharton.timber:timber:4.7.1'
201203
implementation 'com.google.guava:guava:26.0-android'
204+
implementation 'com.annimon:stream:1.2.1'
202205

203206
// testing
204207
testImplementation 'junit:junit:4.13'
205208
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
206209
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
207210
androidTestImplementation 'androidx.test:rules:1.2.0'
208-
androidTestImplementation 'com.squareup.retrofit2:converter-gson:2.8.1'
211+
androidTestImplementation 'com.squareup.retrofit2:converter-gson:2.9.0'
209212
androidTestImplementation 'com.google.code.gson:gson:2.8.6'
210213
}
211214

proguard-rules.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-keep public class network.minter.blockchain.** { *; }
44
-keep public enum network.minter.blockchain.** { *; }
55
-keepclassmembers enum * { *; }
6-
-keep public class network.minter.blockchain.MinterBlockChainApi { *; }
6+
-keep public class network.minter.blockchain.MinterBlockChainSDK { *; }
77

88

99
# Parceler library

src/main/java/network/minter/blockchain/MinterBlockChainApi.java renamed to src/main/java/network/minter/blockchain/MinterBlockChainSDK.java

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) by MinterTeam. 2019
2+
* Copyright (C) by MinterTeam. 2020
33
* @link <a href="https://github.com/MinterTeam">Org Github</a>
44
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
55
*
@@ -32,13 +32,14 @@
3232

3333
import javax.annotation.Nonnull;
3434

35-
import network.minter.blockchain.repo.BlockChainAccountRepository;
36-
import network.minter.blockchain.repo.BlockChainBlockRepository;
37-
import network.minter.blockchain.repo.BlockChainCandidateRepository;
38-
import network.minter.blockchain.repo.BlockChainCoinRepository;
39-
import network.minter.blockchain.repo.BlockChainEventRepository;
40-
import network.minter.blockchain.repo.BlockChainStatusRepository;
41-
import network.minter.blockchain.repo.BlockChainTransactionRepository;
35+
import io.reactivex.rxjava3.schedulers.Schedulers;
36+
import network.minter.blockchain.repo.NodeAddressRepository;
37+
import network.minter.blockchain.repo.NodeBlockRepository;
38+
import network.minter.blockchain.repo.NodeCoinRepository;
39+
import network.minter.blockchain.repo.NodeEventRepository;
40+
import network.minter.blockchain.repo.NodeStatusRepository;
41+
import network.minter.blockchain.repo.NodeTransactionRepository;
42+
import network.minter.blockchain.repo.NodeValidatorRepository;
4243
import network.minter.core.crypto.BytesData;
4344
import network.minter.core.crypto.MinterAddress;
4445
import network.minter.core.crypto.MinterHash;
@@ -49,35 +50,57 @@
4950
import network.minter.core.internal.api.converters.MinterAddressJsonConverter;
5051
import network.minter.core.internal.api.converters.MinterHashJsonConverter;
5152
import network.minter.core.internal.api.converters.MinterPublicKeyJsonConverter;
53+
import network.minter.core.internal.common.Acceptor;
5254
import network.minter.core.internal.log.Mint;
5355
import network.minter.core.internal.log.TimberLogger;
56+
import okhttp3.Request;
57+
import okhttp3.Response;
5458
import okhttp3.logging.HttpLoggingInterceptor;
59+
import retrofit2.Retrofit;
60+
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
5561

5662
/**
5763
* minter-android-blockchain. 2018
5864
* @author Eduard Maximovich <edward.vstock@gmail.com>
5965
*/
60-
public class MinterBlockChainApi {
66+
public class MinterBlockChainSDK {
6167
private final static String BASE_NODE_URL = BuildConfig.BASE_NODE_URL;
62-
private static MinterBlockChainApi INSTANCE;
68+
private static MinterBlockChainSDK INSTANCE;
6369
private final ApiService.Builder mApiService;
64-
private BlockChainAccountRepository mAccountRepository;
65-
private BlockChainCoinRepository mCoinRepository;
66-
private BlockChainTransactionRepository mTransactionRepository;
67-
private BlockChainBlockRepository mBlockRepository;
68-
private BlockChainCandidateRepository mBlockChainCandidateRepository;
69-
private BlockChainStatusRepository mStatusRepository;
70-
private BlockChainEventRepository mEventRepository;
71-
72-
private MinterBlockChainApi() {
70+
private NodeAddressRepository mAccountRepository;
71+
private NodeCoinRepository mCoinRepository;
72+
private NodeTransactionRepository mTransactionRepository;
73+
private NodeBlockRepository mBlockRepository;
74+
private NodeValidatorRepository mCandidateRepository;
75+
private NodeStatusRepository mStatusRepository;
76+
private NodeEventRepository mEventRepository;
77+
78+
private MinterBlockChainSDK() {
7379
this(BASE_NODE_URL);
7480
}
7581

76-
private MinterBlockChainApi(@Nonnull String baseNodeApiUrl) {
82+
private MinterBlockChainSDK(@Nonnull String baseNodeApiUrl) {
7783
mApiService = new ApiService.Builder(baseNodeApiUrl, getGsonBuilder());
84+
mApiService.setRetrofitClientConfig(new Acceptor<Retrofit.Builder>() {
85+
@Override
86+
public void accept(Retrofit.Builder builder) {
87+
builder.addCallAdapterFactory(RxJava3CallAdapterFactory.createWithScheduler(Schedulers.io()));
88+
}
89+
});
7890
mApiService.addHeader("Content-Type", "application/json");
7991
mApiService.addHeader("X-Minter-Client-Name", "MinterAndroid");
8092
mApiService.addHeader("X-Minter-Client-Version", BuildConfig.VERSION_NAME);
93+
mApiService.addHttpInterceptor(chain -> {
94+
Request request = chain.request();
95+
Response response = chain.proceed(request);
96+
if (response.body() != null && response.body().contentType() != null && response.body().contentType().toString().toLowerCase().equals("application/json")) {
97+
Response.Builder b = response.newBuilder();
98+
b.code(200);
99+
100+
return b.build();
101+
}
102+
return response;
103+
});
81104
}
82105

83106
public static void initialize() {
@@ -91,11 +114,11 @@ public static void initialize() {
91114
* @param logger
92115
* @return
93116
*/
94-
public static MinterBlockChainApi createInstance(String baseNodeApiUrl, boolean debug, Mint.Leaf logger) {
117+
public static MinterBlockChainSDK createInstance(String baseNodeApiUrl, boolean debug, Mint.Leaf logger) {
95118
if (debug) {
96119
Mint.brew(logger);
97120
}
98-
MinterBlockChainApi api = new MinterBlockChainApi(baseNodeApiUrl);
121+
MinterBlockChainSDK api = new MinterBlockChainSDK(baseNodeApiUrl);
99122
api.mApiService.setDebug(debug);
100123
if (debug) {
101124
api.mApiService.setDebugRequestLevel(HttpLoggingInterceptor.Level.BODY);
@@ -112,7 +135,7 @@ public static void initialize(String baseNodeApiUrl, boolean debug, Mint.Leaf lo
112135
if (debug) {
113136
Mint.brew(logger);
114137
}
115-
INSTANCE = new MinterBlockChainApi(baseNodeApiUrl);
138+
INSTANCE = new MinterBlockChainSDK(baseNodeApiUrl);
116139
INSTANCE.mApiService.setDebug(debug);
117140
if (debug) {
118141
INSTANCE.mApiService.setDebugRequestLevel(HttpLoggingInterceptor.Level.BODY);
@@ -127,7 +150,7 @@ public static void initialize(String baseNodeApiUrl) {
127150
initialize(baseNodeApiUrl, false, new TimberLogger());
128151
}
129152

130-
public static MinterBlockChainApi getInstance() {
153+
public static MinterBlockChainSDK getInstance() {
131154
if (INSTANCE == null) {
132155
throw new IllegalStateException("You forget to call MinterBlockchainApi.initialize");
133156
}
@@ -149,57 +172,57 @@ public GsonBuilder getGsonBuilder() {
149172
return out;
150173
}
151174

152-
public BlockChainEventRepository event() {
175+
public NodeEventRepository event() {
153176
if (mEventRepository == null) {
154-
mEventRepository = new BlockChainEventRepository(mApiService);
177+
mEventRepository = new NodeEventRepository(mApiService);
155178
}
156179

157180
return mEventRepository;
158181
}
159182

160-
public BlockChainStatusRepository status() {
183+
public NodeStatusRepository status() {
161184
if (mStatusRepository == null) {
162-
mStatusRepository = new BlockChainStatusRepository(mApiService);
185+
mStatusRepository = new NodeStatusRepository(mApiService);
163186
}
164187

165188
return mStatusRepository;
166189
}
167190

168-
public BlockChainCandidateRepository candidate() {
169-
if (mBlockChainCandidateRepository == null) {
170-
mBlockChainCandidateRepository = new BlockChainCandidateRepository(mApiService);
191+
public NodeValidatorRepository validator() {
192+
if (mCandidateRepository == null) {
193+
mCandidateRepository = new NodeValidatorRepository(mApiService);
171194
}
172195

173-
return mBlockChainCandidateRepository;
196+
return mCandidateRepository;
174197
}
175198

176-
public BlockChainBlockRepository block() {
199+
public NodeBlockRepository block() {
177200
if (mBlockRepository == null) {
178-
mBlockRepository = new BlockChainBlockRepository(mApiService);
201+
mBlockRepository = new NodeBlockRepository(mApiService);
179202
}
180203

181204
return mBlockRepository;
182205
}
183206

184-
public BlockChainAccountRepository account() {
207+
public NodeAddressRepository account() {
185208
if (mAccountRepository == null) {
186-
mAccountRepository = new BlockChainAccountRepository(mApiService);
209+
mAccountRepository = new NodeAddressRepository(mApiService);
187210
}
188211

189212
return mAccountRepository;
190213
}
191214

192-
public BlockChainTransactionRepository transactions() {
215+
public NodeTransactionRepository transactions() {
193216
if (mTransactionRepository == null) {
194-
mTransactionRepository = new BlockChainTransactionRepository(mApiService);
217+
mTransactionRepository = new NodeTransactionRepository(mApiService);
195218
}
196219

197220
return mTransactionRepository;
198221
}
199222

200-
public BlockChainCoinRepository coin() {
223+
public NodeCoinRepository coin() {
201224
if (mCoinRepository == null) {
202-
mCoinRepository = new BlockChainCoinRepository(mApiService);
225+
mCoinRepository = new NodeCoinRepository(mApiService);
203226
}
204227

205228
return mCoinRepository;

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

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/java/network/minter/blockchain/api/BlockChainAccountEndpoint.java renamed to src/main/java/network/minter/blockchain/api/NodeAddressEndpoint.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) by MinterTeam. 2019
2+
* Copyright (C) by MinterTeam. 2020
33
* @link <a href="https://github.com/MinterTeam">Org Github</a>
44
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
55
*
@@ -26,34 +26,50 @@
2626

2727
package network.minter.blockchain.api;
2828

29-
import network.minter.blockchain.models.BCResult;
30-
import network.minter.blockchain.models.Balance;
31-
import network.minter.blockchain.models.TransactionSendResult;
32-
import retrofit2.Call;
29+
import java.util.List;
30+
31+
import io.reactivex.rxjava3.core.Observable;
32+
import network.minter.blockchain.models.AddressInfo;
33+
import network.minter.blockchain.models.AddressInfoList;
3334
import retrofit2.http.GET;
35+
import retrofit2.http.Path;
3436
import retrofit2.http.Query;
3537

3638
/**
3739
* minter-android-blockchain. 2018
3840
* @author Eduard Maximovich <edward.vstock@gmail.com>
3941
*/
40-
public interface BlockChainAccountEndpoint {
42+
public interface NodeAddressEndpoint {
4143

4244
/**
4345
* Returns current balance of an account
4446
* @param address Address of an account
4547
* @return
4648
*/
47-
@GET("/address")
48-
Call<BCResult<Balance>> getBalance(@Query("address") String address);
49+
@GET("/address/{address}")
50+
Observable<AddressInfo> getAddressInfo(@Path("address") String address);
4951

5052
/**
51-
* Broadcasts transaction onto Minter network
52-
* @param data
53+
* Returns current balance of an account
54+
* @param address Address of an account
5355
* @return
5456
*/
55-
@GET("/send_transaction")
56-
Call<BCResult<TransactionSendResult>> sendTransaction(@Query("tx") String signedTxHash);
57+
@GET("/address/{address}")
58+
Observable<AddressInfo> getAddressInfo(
59+
@Path("address") String address,
60+
@Query("height") String blockNumber,
61+
@Query("delegated") String includeDelegatedStakes
62+
);
63+
64+
@GET("/addresses")
65+
Observable<AddressInfoList> getAddressesInfo(@Query("addresses") List<String> addresses);
66+
67+
@GET("/addresses")
68+
Observable<AddressInfoList> getAddressesInfo(
69+
@Query("addresses") List<String> addresses,
70+
@Query("height") String blockNumber,
71+
@Query("delegated") String includeDelegatedStakes
72+
);
5773

5874

5975
}

0 commit comments

Comments
 (0)