Skip to content

Commit f0f845f

Browse files
author
Ebenezer Ackon
committed
handle issue #14, blocks
1 parent cae67e2 commit f0f845f

File tree

11 files changed

+204
-26
lines changed

11 files changed

+204
-26
lines changed

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,37 @@ Create an Instance of one of the reactive Singles and access values by specifyin
2828
``[accounts, contracts, transactions, blocks, eventLogs, geth, websockets, tokens, stat]``
2929

3030
```
31-
val stat = Stat()
32-
val account = Account()
33-
34-
//stat test
35-
stat.getLastPriceInBtc()?.observeOn(AndroidSchedulers.mainThread())
36-
?.subscribeBy {
37-
Log.d(TAG, "The current price of Ether in Btc: $it")
38-
}
31+
val stat = Stat()
32+
val account = Account()
33+
val contract = ContractABI()
34+
val tx = TxStatus()
35+
val blocks = BlocksMined()
3936
4037
//account test
41-
account.getTransactions("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3")?.observeOn(AndroidSchedulers.mainThread())
42-
?.subscribeBy {
43-
Log.d(TAG, "The Account Size of Transactions is: ${it.size}")
44-
}
38+
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
39+
.observeOn(AndroidSchedulers.mainThread())
40+
?.subscribeBy(
41+
onSuccess = { Log.d(TAG, "The Account Size of Transactions is: ${it.size}") },
42+
onError = { Log.d(TAG, "error receiving ERC20") })
43+
44+
//contracts test
45+
contract.getContractABI("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
46+
.observeOn(AndroidSchedulers.mainThread())
47+
?.subscribeBy(
48+
onSuccess = { Log.d(TAG, "The ABI has returned: $it") },
49+
onError = { Log.d(TAG, "error receiving abi contract") })
50+
51+
52+
53+
//blocks test
54+
blocks.getBlocksMined("2165403")
55+
.observeOn(AndroidSchedulers.mainThread())
56+
?.subscribeBy(
57+
onSuccess = {
58+
Log.d(TAG, "The block miner is: ${it.blockMiner} and " +
59+
"the first miner : ${it.uncles?.get(0)?.miner}")
60+
},
61+
onError = { Log.d(TAG, "error receiving blocks mined") })
4562
```
4663
## Authors
4764

app/src/main/java/jfyg/etherscan/helloetherescan/MainActivity.kt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.util.Log
66
import io.reactivex.android.schedulers.AndroidSchedulers
77
import io.reactivex.rxkotlin.subscribeBy
88
import jfyg.data.account.Account
9+
import jfyg.data.block.BlocksMined
910
import jfyg.data.contract.ContractABI
1011
import jfyg.data.stat.Stat
1112
import jfyg.data.transaction.TxStatus
@@ -25,38 +26,52 @@ class MainActivity : AppCompatActivity() {
2526
val account = Account()
2627
val contract = ContractABI()
2728
val tx = TxStatus()
29+
val blocks = BlocksMined()
2830

2931

3032
fab.setOnClickListener {
3133

3234
//stat test
3335
stat.getLastPriceInBtc()
3436
.observeOn(AndroidSchedulers.mainThread())
35-
?.subscribeBy {
36-
Log.d(TAG, "The current price of Ether in Btc: $it")
37-
}
37+
?.subscribeBy(
38+
onSuccess = { Log.d(TAG, "The current price of Ether in Btc: $it") },
39+
onError = { Log.d(TAG, "error receiving stat") })
40+
3841

3942
//account test
4043
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
4144
.observeOn(AndroidSchedulers.mainThread())
42-
?.subscribeBy {
43-
Log.d(TAG, "The Account Size of Transactions is: ${it.size}")
44-
}
45+
?.subscribeBy(
46+
onSuccess = { Log.d(TAG, "The Account Size of Transactions is: ${it.size}") },
47+
onError = { Log.d(TAG, "error receiving ERC20") })
4548

4649
//contracts test
4750
contract.getContractABI("0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
4851
.observeOn(AndroidSchedulers.mainThread())
49-
?.subscribeBy {
50-
Log.d(TAG, "The ABI has returned: $it")
51-
}
52+
?.subscribeBy(
53+
onSuccess = { Log.d(TAG, "The ABI has returned: $it") },
54+
onError = { Log.d(TAG, "error receiving abi contract") })
5255

5356
//transaction test
5457
tx.getTxExecutionStatus("0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a")
5558
.observeOn(AndroidSchedulers.mainThread())
56-
?.subscribeBy {
57-
Log.d(TAG, "The transaction's Error Status is: ${it.isError} and " +
58-
"transactions's error description is: ${it.errDescription}")
59-
}
59+
?.subscribeBy(
60+
onSuccess = {
61+
Log.d(TAG, "The transaction's Error Status is: ${it.isError} and " +
62+
"transactions's error description is: ${it.errDescription}")
63+
},
64+
onError = { Log.d(TAG, "error receiving tx status") })
65+
66+
//blocks test
67+
blocks.getBlocksMined("2165403")
68+
.observeOn(AndroidSchedulers.mainThread())
69+
?.subscribeBy(
70+
onSuccess = {
71+
Log.d(TAG, "The block miner is: ${it.blockMiner} and " +
72+
"the first minor : ${it.uncles?.get(0)?.miner}")
73+
},
74+
onError = { Log.d(TAG, "error receiving blocks mined") })
6075
}
6176
}
6277

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package jfyg.data
2+
3+
/**
4+
* https://etherscan.io/apis#blocks
5+
*/
6+
data class BlocksMined(var blockNumber: String? = null,
7+
var timeStamp: String? = null,
8+
var blockMiner: String? = null,
9+
var blockReward: String? = null,
10+
var uncles: ArrayList<Uncles>? = null)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package jfyg.data
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class Uncles(var miner: String? = null,
6+
7+
var unclePosition: String? = null,
8+
9+
@SerializedName("blockreward")
10+
var blockReward: String? = null)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package jfyg.data.block
2+
3+
import io.reactivex.Single
4+
import jfyg.data.BlocksMined
5+
import jfyg.network.queries.ApiQuery
6+
7+
/**
8+
* https://etherscan.io/apis#blocks
9+
*/
10+
class BlocksMined : BlocksMinedContract {
11+
private val query = ApiQuery()
12+
13+
/**
14+
* [BETA] Get Block And Uncle Rewards by BlockNo
15+
*/
16+
override fun getBlocksMined(blockNo: String?): Single<BlocksMined> =
17+
query.blocksMined("block", "getblockreward", blockNo).map { it.result }
18+
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package jfyg.data.block
2+
3+
import io.reactivex.Single
4+
import jfyg.data.BlocksMined
5+
6+
/**
7+
* https://etherscan.io/apis#blocks
8+
*/
9+
internal interface BlocksMinedContract {
10+
11+
/**
12+
* [BETA] Get Block And Uncle Rewards by BlockNo
13+
*/
14+
fun getBlocksMined(blockNo: String?): Single<BlocksMined>
15+
16+
}

etherscanapi/src/main/java/jfyg/network/NetworkService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import jfyg.network.response.account.ERC20Response
77
import jfyg.network.response.account.AccountInternalTxResponse
88
import jfyg.network.response.account.AccountMultiBalanceResponse
99
import jfyg.network.response.account.AccountTxResponse
10+
import jfyg.network.response.block.BlockResponse
1011
import jfyg.network.response.contract.ContractABIResponse
1112
import jfyg.network.response.stat.StatPriceResponse
1213
import jfyg.network.response.stat.StatSupplyResponse
@@ -96,4 +97,10 @@ internal interface NetworkService {
9697
@Query("txhash") address: String?,
9798
@Query("apikey") apikey: String?): Single<TxContractReceiptResponse>
9899

100+
@GET("api")
101+
fun getBlocksMined(@Query("module") module: String?,
102+
@Query("action") action: String?,
103+
@Query("blockno") address: String?,
104+
@Query("apikey") apikey: String?): Single<BlockResponse>
105+
99106
}

etherscanapi/src/main/java/jfyg/network/queries/ApiQuery.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import jfyg.network.response.account.ERC20Response
99
import jfyg.network.response.account.AccountInternalTxResponse
1010
import jfyg.network.response.account.AccountMultiBalanceResponse
1111
import jfyg.network.response.account.AccountTxResponse
12+
import jfyg.network.response.block.BlockResponse
1213
import jfyg.network.response.contract.ContractABIResponse
1314
import jfyg.network.response.stat.StatPriceResponse
1415
import jfyg.network.response.stat.StatSupplyResponse
@@ -18,7 +19,7 @@ import jfyg.network.response.transaction.TxContractReceiptResponse
1819
/**
1920
* A mediator between the responses and errors that come from every query
2021
*/
21-
internal class ApiQuery : AccountApi, StatApi, ContractABIApi, TxApi {
22+
internal class ApiQuery : AccountApi, StatApi, ContractABIApi, TxApi, BlocksApi {
2223

2324

2425
override fun accountBalance(module: String?,
@@ -85,4 +86,9 @@ internal class ApiQuery : AccountApi, StatApi, ContractABIApi, TxApi {
8586
txHash: String?): Single<TxContractReceiptResponse> =
8687
RestClient().getQuery().getContractTransactionReceipt(module, action, txHash, ApiKey.takeOff.callApiKey())
8788

89+
override fun blocksMined(module: String?,
90+
action: String?,
91+
blockno: String?): Single<BlockResponse> =
92+
RestClient().getQuery().getBlocksMined(module, action, blockno, ApiKey.takeOff.callApiKey())
93+
8894
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package jfyg.network.queries
2+
3+
import io.reactivex.Single
4+
import jfyg.network.response.block.BlockResponse
5+
6+
internal interface BlocksApi {
7+
8+
/**
9+
* [BETA] Get Block And Uncle Rewards by BlockNo
10+
*/
11+
fun blocksMined(module: String?,
12+
action: String?,
13+
blockno: String?): Single<BlockResponse>
14+
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package jfyg.network.response.block
2+
3+
import jfyg.data.BlocksMined
4+
import jfyg.network.response.BaseResponse
5+
6+
/**
7+
* Check contract execution status
8+
*/
9+
internal data class BlockResponse(var result: BlocksMined) : BaseResponse()

0 commit comments

Comments
 (0)