Skip to content

Commit 8f781a4

Browse files
committed
Replace rxjava w/ Coroutines (closes #119)
1 parent 61dc248 commit 8f781a4

Some content is hidden

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

47 files changed

+520
-559
lines changed

README.md

+5-35
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
[![Generic badge](https://img.shields.io/badge/EtherscanApi-UP-brightgreen.svg)](https://api.etherscan.io/api?module=stats&action=ethprice&apikey=YourApiKeyToken)
2-
[![Generic badge](https://img.shields.io/badge/CircleCI-PASS-brightgreen.svg)](https://circleci.com/gh/EbenezerGH/hello_etherscan/tree/master)
3-
[![Generic badge](https://img.shields.io/badge/Version-v1.0.0-lightgrey.svg)](https://jitpack.io/#EbenezerGH/etherscan-android-api)
2+
[![Generic badge](https://img.shields.io/badge/Version-v2.0.0-lightgrey.svg)](https://jitpack.io/#EbenezerGH/etherscan-android-api)
43
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/EbenezerGH/hello_etherscan/blob/update-documentation/LICENSE)
54

65
# etherscan-android-api
76

87
etherscan android api is an android wrapper for the [etherscan api](https://etherscan.io/apis). This is just a module to handle networking calls.
98

10-
There are only a few [features](https://github.com/EbenezerGH/hello_etherscan/issues) left to add, however this version is completely safe to use.
9+
There are only a few [features](https://github.com/EbenezerGH/hello_etherscan/issues) left to add, however version 2.0.0+ is completely safe to use.
1110

1211
## Getting Started
1312

@@ -27,7 +26,7 @@ Add the dependency
2726

2827
```
2928
dependencies {
30-
implementation 'com.github.EbenezerGH:etherscan-android-api:v1.0.3'
29+
implementation 'com.github.EbenezerGH:etherscan-android-api:v2.0.0'
3130
}
3231
```
3332

@@ -37,41 +36,12 @@ Optional: Call `ApiKey.takeOff.setApiKey("[your api key here]")` in your module'
3736
ApiKey.takeOff.setApiKey("1I7CRNU2QIU253UBPFVB5UV2C2PBDURAIYZ")
3837
```
3938

40-
Create an Instance of one of the reactive singles and access values by specifying thread and subscribing. [see [example implementation](https://github.com/EbenezerGH/etherscan-android-api/blob/master/etherscan-sample/src/main/java/jfyg/etherscan/helloetherescan/SampleActivity.kt)]
39+
Instantiate an Api Instance and handle the response [see [example implementation](https://github.com/EbenezerGH/etherscan-android-api/blob/master/etherscan-sample/src/main/java/jfyg/etherscan/helloetherescan/SampleActivity.kt)]
4140

42-
Currently Available: ``[accounts, contracts, transactions, blocks, stat]``
41+
Currently Available: ``[accountsApi, contractsApi, transactionsApi, blocksApi, statApi]``
4342

4443
Coming Soon: ``[eventLogs, geth, websockets, tokens]``
4544

46-
```
47-
val account = Account()
48-
val contract = ContractABI()
49-
val blocks = BlocksMined()
50-
51-
//account
52-
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
53-
.observeOn(AndroidSchedulers.mainThread())
54-
.subscribeBy(
55-
onSuccess = { Log.d(TAG, "The Account Size of Transactions is: ${it.size}") },
56-
onError = { Log.d(TAG, "error receiving ERC20") })
57-
58-
//contracts
59-
contract.getContractABI("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
60-
.observeOn(AndroidSchedulers.mainThread())
61-
.subscribeBy(
62-
onSuccess = { Log.d(TAG, "The ABI has returned: $it") },
63-
onError = { Log.d(TAG, "error receiving abi contract") })
64-
65-
//blocks
66-
blocks.getBlocksMined("2165403")
67-
.observeOn(AndroidSchedulers.mainThread())
68-
.subscribeBy(
69-
onSuccess = {
70-
Log.d(TAG, "The block miner is: ${it.blockMiner} and " +
71-
"the first miner : ${it.uncles.get(0).miner}")
72-
},
73-
onError = { Log.d(TAG, "error receiving blocks mined") })
74-
```
7545
## Authors
7646

7747
* [**Ebenezer Ackon**](http://www.ebenezerackon.com/)

etherscan-sample/build.gradle

+2-10
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,13 @@ android {
2525
dependencies {
2626
implementation fileTree(dir: 'libs', include: ['*.jar'])
2727

28-
29-
/**
30-
Because RxAndroid releases are few and far between, it is recommended you also
31-
explicitly depend on RxJava's latest version for bug fixes and new features.
32-
*/
33-
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
34-
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
35-
3628
// kotlin
37-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
29+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.10'
3830

3931
// google
4032
implementation 'com.android.support:appcompat-v7:26.1.0'
4133
implementation 'com.android.support:design:26.1.0'
42-
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
34+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
4335

4436
implementation project(':etherscanapi')
4537
}

etherscan-sample/src/main/java/jfyg/etherscan/helloetherescan/SampleActivity.kt

+68-66
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package jfyg.etherscan.helloetherescan
33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
55
import android.util.Log
6-
import io.reactivex.android.schedulers.AndroidSchedulers
7-
import io.reactivex.rxkotlin.subscribeBy
8-
import jfyg.data.account.Accounts
9-
import jfyg.data.block.Blocks
10-
import jfyg.data.contract.Contracts
11-
import jfyg.data.stat.Stats
12-
import jfyg.data.transaction.Transactions
6+
import jfyg.data.account.AccountsApi
7+
import jfyg.data.block.BlocksApi
8+
import jfyg.data.contract.ContractsApi
9+
import jfyg.data.stat.StatsApi
10+
import jfyg.data.transaction.TransactionsApi
1311
import kotlinx.android.synthetic.main.activity_main.*
12+
import kotlinx.coroutines.GlobalScope
13+
import kotlinx.coroutines.launch
1414

1515

1616
class SampleActivity : AppCompatActivity() {
@@ -22,68 +22,70 @@ class SampleActivity : AppCompatActivity() {
2222
setSupportActionBar(toolbar)
2323

2424
//************************************************ Used To Test Singles returned from etherscanapi Module
25-
val stat = Stats()
26-
val account = Accounts()
27-
val contract = Contracts()
28-
val tx = Transactions()
29-
val blocks = Blocks()
30-
25+
val stat = StatsApi()
26+
val account = AccountsApi()
27+
val contract = ContractsApi()
28+
val tx = TransactionsApi()
29+
val blocks = BlocksApi()
3130

3231
fab.setOnClickListener {
33-
34-
//stat test
35-
stat.getEtherStatistics()
36-
.observeOn(AndroidSchedulers.mainThread())
37-
.subscribeBy(
38-
onSuccess = { Log.d(TAG, "The current price of Ether in Usd: ${it.ethUsd}") },
39-
onError = { Log.d(TAG, "error receiving stat") })
40-
41-
42-
//account MultiBalance test
43-
account.getMultiBalance(listOf(
44-
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
45-
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
46-
"0x4e83362442b8d1bec281594cea3050c8eb01311c"))
47-
.observeOn(AndroidSchedulers.mainThread())
48-
.subscribeBy(
49-
onSuccess = { Log.d(TAG, "The current balance in account 2 is: ${it[1].balance}") },
50-
onError = { Log.d(TAG, "error receiving stat") })
51-
52-
53-
//account test
54-
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
55-
.observeOn(AndroidSchedulers.mainThread())
56-
.subscribeBy(
57-
onSuccess = { Log.d(TAG, "The Account Size of Transactions is: ${it.size}") },
58-
onError = { Log.d(TAG, "error receiving ERC20") })
59-
60-
//contracts test
61-
contract.getContractABI("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
62-
.observeOn(AndroidSchedulers.mainThread())
63-
.subscribeBy(
64-
onSuccess = { Log.d(TAG, "The ABI has returned: $it") },
65-
onError = { Log.d(TAG, "error receiving abi contract") })
66-
67-
//transaction test
68-
tx.getTxExecutionStatus("0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a")
69-
.observeOn(AndroidSchedulers.mainThread())
70-
.subscribeBy(
71-
onSuccess = {
72-
Log.d(TAG, "The transaction's Error Status is: ${it.isError} and " +
73-
"transactions's error description is: ${it.errDescription}")
74-
},
75-
onError = { Log.d(TAG, "error receiving tx status") })
76-
77-
//blocks test
78-
blocks.getBlocksMined("2165403")
79-
.observeOn(AndroidSchedulers.mainThread())
80-
.subscribeBy(
81-
onSuccess = {
82-
Log.d(TAG, "The block miner is: ${it.blockMiner} and " +
83-
"the first miner : ${it.uncles[0].miner}")
84-
},
85-
onError = { Log.d(TAG, "error receiving blocks mined") })
32+
GlobalScope.launch {
33+
34+
stat.getEtherStatistics()
35+
.body()?.let { response ->
36+
Log.d(TAG, "The Ether object has the values of: ${response.result}")
37+
}
38+
39+
stat.getEtherTotalSupply()
40+
.body()?.let { response ->
41+
Log.d(TAG, "The total supply of Ether is: ${response.result}")
42+
}
43+
44+
account.getMultiBalance(listOf(
45+
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
46+
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413",
47+
"0x4e83362442b8d1bec281594cea3050c8eb01311c"))
48+
.body()?.let { response ->
49+
Log.d(TAG, "The current balance in account 0 is: ${response.result[0]}")
50+
Log.d(TAG, "The current balance in account 1 is: ${response.result[1]}")
51+
Log.d(TAG, "The current balance in account 2 is: ${response.result[2]}")
52+
}
53+
54+
55+
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
56+
.body()?.let { response ->
57+
Log.d(TAG, "ERC20 Token 1: ${response.result[0]}")
58+
Log.d(TAG, "ERC20 Token 2: ${response.result[1]}")
59+
}
60+
61+
contract.getContractABI("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
62+
.body()?.let { response ->
63+
Log.d(TAG, "ABI of given contract: ${response.result}")
64+
}
65+
66+
tx.getTxExecutionStatus("0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a")
67+
.body()?.let { response ->
68+
Log.d(TAG,
69+
"The transaction's Error Status is: ${response.result.isError} and " +
70+
"transactions's error description is: ${response.result.errDescription}")
71+
}
72+
73+
blocks.getBlocksMined("2165403")
74+
.body()?.let { response ->
75+
Log.d(TAG, "The block miner is: ${response.result.blockMiner} and " +
76+
"uncles from this block: ${response.result.uncles}")
77+
}
78+
}
8679
}
8780
}
8881

8982
}
83+
84+
85+
86+
87+
88+
89+
90+
91+

etherscanapi/build.gradle

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ android {
2727

2828

2929
dependencies {
30-
implementation fileTree(include: ['*.jar'], dir: 'libs')
3130

32-
// kotlin
33-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$project.kotlin_version"
31+
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:${project.coroutines_version}"
32+
api "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:${project.coroutine_adapter_version}"
3433

35-
// rx
36-
implementation "io.reactivex.rxjava2:rxkotlin:$project.reactivex_rxjava2_rxkotlin_version"
34+
implementation fileTree(include: ['*.jar'], dir: 'libs')
35+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$project.kotlin_version"
3736

38-
// gson
39-
implementation "com.google.code.gson:gson:$project.gson_version"
37+
api "com.squareup.retrofit2:retrofit:${project.retrofit2_core_version}"
38+
implementation "com.squareup.moshi:moshi:${project.moshi_version}"
39+
implementation "com.squareup.retrofit2:converter-moshi:${project.retrofit2_converter_moshi_version}"
4040

41-
// retrofit
42-
implementation "com.squareup.retrofit2:retrofit:$project.retrofit2_core_version"
43-
implementation "com.squareup.retrofit2:converter-gson:$project.retrofit2_converter_gson_version"
44-
implementation "com.squareup.retrofit2:adapter-rxjava2:$project.retrofit2_adapter_version"
41+
// todo #118
42+
testImplementation "com.google.code.gson:gson:$project.gson_version"
43+
testImplementation "com.squareup.retrofit2:converter-gson:$project.retrofit2_converter_gson_version"
44+
testImplementation "com.squareup.retrofit2:adapter-rxjava2:$project.retrofit2_adapter_version"
4545

46-
// tests
4746
testImplementation "junit:junit:$project.junit_version"
4847
testImplementation "org.mockito:mockito-core:$project.mockito_core_version"
48+
4949
testImplementation "com.squareup.okhttp3:mockwebserver:$project.mockwebserver_version"
5050
androidTestImplementation "com.android.support.test.espresso:espresso-core:$project.espresso_core_version"
5151

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package jfyg.data
22

3-
data class Balance(val account: String? = null,
3+
data class Balance(val account: String,
44

5-
val balance: String? = null)
5+
val balance: String
6+
)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package jfyg.data
22

3-
data class BlockAccount(val blockNumber: String? = null,
3+
data class BlockAccount(val blockNumber: String,
44

5-
val timeStamp: String? = null,
5+
val timeStamp: String,
66

7-
val blockReward: String? = null)
7+
val blockReward: String
8+
)
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package jfyg.data
22

3-
data class BlockMined(val blockNumber: String? = null,
3+
data class BlockMined(val blockNumber: String,
44

5-
val timeStamp: String? = null,
5+
val timeStamp: String,
66

7-
val blockMiner: String? = null,
7+
val blockMiner: String,
88

9-
val blockReward: String? = null,
9+
val blockReward: String,
1010

11-
val uncles: List<Uncle> = emptyList())
11+
val uncles: List<Uncle> = emptyList()
12+
)
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
package jfyg.data
22

3-
import com.google.gson.annotations.SerializedName
3+
import com.squareup.moshi.Json
44

5-
data class ERC20Token(val blockNumber: String? = null,
5+
data class ERC20Token(val blockNumber: String,
66

7-
val timeStamp: String? = null,
7+
val timeStamp: String,
88

9-
val hash: String? = null,
9+
val hash: String,
1010

11-
val nonce: String? = null,
11+
val nonce: String,
1212

13-
val blockHash: String? = null,
13+
val blockHash: String,
1414

15-
@SerializedName("from")
16-
val transactionFrom: String? = null,
15+
@field:Json(name = "from")
16+
val transactionFrom: String,
1717

18-
val contractAddress: String? = null,
18+
val contractAddress: String,
1919

20-
@SerializedName("to")
21-
val transactionTo: String? = null,
20+
@field:Json(name = "to")
21+
val transactionTo: String,
2222

23-
val value: String? = null,
23+
val value: String,
2424

25-
val tokenName: String? = null,
25+
val tokenName: String,
2626

27-
val tokenSymbol: String? = null,
27+
val tokenSymbol: String,
2828

29-
val tokenDecimal: String? = null,
29+
val tokenDecimal: String,
3030

31-
val transactionIndex: String? = null,
31+
val transactionIndex: String,
3232

33-
val gas: String? = null,
33+
val gas: String,
3434

35-
val gasPrice: String? = null,
35+
val gasPrice: String,
3636

37-
val gasUsed: String? = null,
37+
val gasUsed: String,
3838

39-
val cumulativeGasUsed: String? = null,
39+
val cumulativeGasUsed: String,
4040

41-
val input: String? = null,
41+
val input: String,
4242

43-
val confirmations: String? = null)
43+
val confirmations: String
44+
)

0 commit comments

Comments
 (0)