1
1
/*
2
- * Copyright (C) by MinterTeam. 2019
2
+ * Copyright (C) by MinterTeam. 2020
3
3
* @link <a href="https://github.com/MinterTeam">Org Github</a>
4
4
* @link <a href="https://github.com/edwardstock">Maintainer Github</a>
5
5
*
32
32
33
33
import javax .annotation .Nonnull ;
34
34
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 ;
42
43
import network .minter .core .crypto .BytesData ;
43
44
import network .minter .core .crypto .MinterAddress ;
44
45
import network .minter .core .crypto .MinterHash ;
49
50
import network .minter .core .internal .api .converters .MinterAddressJsonConverter ;
50
51
import network .minter .core .internal .api .converters .MinterHashJsonConverter ;
51
52
import network .minter .core .internal .api .converters .MinterPublicKeyJsonConverter ;
53
+ import network .minter .core .internal .common .Acceptor ;
52
54
import network .minter .core .internal .log .Mint ;
53
55
import network .minter .core .internal .log .TimberLogger ;
56
+ import okhttp3 .Request ;
57
+ import okhttp3 .Response ;
54
58
import okhttp3 .logging .HttpLoggingInterceptor ;
59
+ import retrofit2 .Retrofit ;
60
+ import retrofit2 .adapter .rxjava3 .RxJava3CallAdapterFactory ;
55
61
56
62
/**
57
63
* minter-android-blockchain. 2018
58
64
* @author Eduard Maximovich <edward.vstock@gmail.com>
59
65
*/
60
- public class MinterBlockChainApi {
66
+ public class MinterBlockChainSDK {
61
67
private final static String BASE_NODE_URL = BuildConfig .BASE_NODE_URL ;
62
- private static MinterBlockChainApi INSTANCE ;
68
+ private static MinterBlockChainSDK INSTANCE ;
63
69
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 () {
73
79
this (BASE_NODE_URL );
74
80
}
75
81
76
- private MinterBlockChainApi (@ Nonnull String baseNodeApiUrl ) {
82
+ private MinterBlockChainSDK (@ Nonnull String baseNodeApiUrl ) {
77
83
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
+ });
78
90
mApiService .addHeader ("Content-Type" , "application/json" );
79
91
mApiService .addHeader ("X-Minter-Client-Name" , "MinterAndroid" );
80
92
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
+ });
81
104
}
82
105
83
106
public static void initialize () {
@@ -91,11 +114,11 @@ public static void initialize() {
91
114
* @param logger
92
115
* @return
93
116
*/
94
- public static MinterBlockChainApi createInstance (String baseNodeApiUrl , boolean debug , Mint .Leaf logger ) {
117
+ public static MinterBlockChainSDK createInstance (String baseNodeApiUrl , boolean debug , Mint .Leaf logger ) {
95
118
if (debug ) {
96
119
Mint .brew (logger );
97
120
}
98
- MinterBlockChainApi api = new MinterBlockChainApi (baseNodeApiUrl );
121
+ MinterBlockChainSDK api = new MinterBlockChainSDK (baseNodeApiUrl );
99
122
api .mApiService .setDebug (debug );
100
123
if (debug ) {
101
124
api .mApiService .setDebugRequestLevel (HttpLoggingInterceptor .Level .BODY );
@@ -112,7 +135,7 @@ public static void initialize(String baseNodeApiUrl, boolean debug, Mint.Leaf lo
112
135
if (debug ) {
113
136
Mint .brew (logger );
114
137
}
115
- INSTANCE = new MinterBlockChainApi (baseNodeApiUrl );
138
+ INSTANCE = new MinterBlockChainSDK (baseNodeApiUrl );
116
139
INSTANCE .mApiService .setDebug (debug );
117
140
if (debug ) {
118
141
INSTANCE .mApiService .setDebugRequestLevel (HttpLoggingInterceptor .Level .BODY );
@@ -127,7 +150,7 @@ public static void initialize(String baseNodeApiUrl) {
127
150
initialize (baseNodeApiUrl , false , new TimberLogger ());
128
151
}
129
152
130
- public static MinterBlockChainApi getInstance () {
153
+ public static MinterBlockChainSDK getInstance () {
131
154
if (INSTANCE == null ) {
132
155
throw new IllegalStateException ("You forget to call MinterBlockchainApi.initialize" );
133
156
}
@@ -149,57 +172,57 @@ public GsonBuilder getGsonBuilder() {
149
172
return out ;
150
173
}
151
174
152
- public BlockChainEventRepository event () {
175
+ public NodeEventRepository event () {
153
176
if (mEventRepository == null ) {
154
- mEventRepository = new BlockChainEventRepository (mApiService );
177
+ mEventRepository = new NodeEventRepository (mApiService );
155
178
}
156
179
157
180
return mEventRepository ;
158
181
}
159
182
160
- public BlockChainStatusRepository status () {
183
+ public NodeStatusRepository status () {
161
184
if (mStatusRepository == null ) {
162
- mStatusRepository = new BlockChainStatusRepository (mApiService );
185
+ mStatusRepository = new NodeStatusRepository (mApiService );
163
186
}
164
187
165
188
return mStatusRepository ;
166
189
}
167
190
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 );
171
194
}
172
195
173
- return mBlockChainCandidateRepository ;
196
+ return mCandidateRepository ;
174
197
}
175
198
176
- public BlockChainBlockRepository block () {
199
+ public NodeBlockRepository block () {
177
200
if (mBlockRepository == null ) {
178
- mBlockRepository = new BlockChainBlockRepository (mApiService );
201
+ mBlockRepository = new NodeBlockRepository (mApiService );
179
202
}
180
203
181
204
return mBlockRepository ;
182
205
}
183
206
184
- public BlockChainAccountRepository account () {
207
+ public NodeAddressRepository account () {
185
208
if (mAccountRepository == null ) {
186
- mAccountRepository = new BlockChainAccountRepository (mApiService );
209
+ mAccountRepository = new NodeAddressRepository (mApiService );
187
210
}
188
211
189
212
return mAccountRepository ;
190
213
}
191
214
192
- public BlockChainTransactionRepository transactions () {
215
+ public NodeTransactionRepository transactions () {
193
216
if (mTransactionRepository == null ) {
194
- mTransactionRepository = new BlockChainTransactionRepository (mApiService );
217
+ mTransactionRepository = new NodeTransactionRepository (mApiService );
195
218
}
196
219
197
220
return mTransactionRepository ;
198
221
}
199
222
200
- public BlockChainCoinRepository coin () {
223
+ public NodeCoinRepository coin () {
201
224
if (mCoinRepository == null ) {
202
- mCoinRepository = new BlockChainCoinRepository (mApiService );
225
+ mCoinRepository = new NodeCoinRepository (mApiService );
203
226
}
204
227
205
228
return mCoinRepository ;
0 commit comments