Skip to content

Commit 3f8cc00

Browse files
author
Ebenezer Ackon
committed
redefine Const class and remove excessive nullables
1 parent b2190aa commit 3f8cc00

File tree

13 files changed

+125
-106
lines changed

13 files changed

+125
-106
lines changed

etherscanapi/src/main/java/jfyg/data/account/Accounts.kt

+48-35
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ import jfyg.data.ERC20Token
77
import jfyg.data.Tx
88
import jfyg.data.TxsInternal
99
import jfyg.network.queries.ApiQuery
10-
import jfyg.utils.Const
1110
import jfyg.utils.QueryUtils
11+
import jfyg.utils.ACCOUNT
12+
import jfyg.utils.ASC
13+
import jfyg.utils.BALANCE
14+
import jfyg.utils.BALANCE_MULTI
15+
import jfyg.utils.BLOCKS
16+
import jfyg.utils.END_BLOCK
17+
import jfyg.utils.GENERIC_PUBLIC_ADDRESS
18+
import jfyg.utils.GET_MINED_BLOCKS
19+
import jfyg.utils.LATEST
20+
import jfyg.utils.START_BLOCK
21+
import jfyg.utils.TOKEN_TX
22+
import jfyg.utils.TX_LIST
23+
import jfyg.utils.TX_LIST_INTERNAL
1224

1325
/**
1426
* https://etherscan.io/apis#accounts
@@ -17,76 +29,77 @@ class Accounts : AccountsContract {
1729

1830
private val query = ApiQuery()
1931
private val genericNetworkQuery = query.accountBalance(
20-
Const.ACCOUNT,
21-
Const.BALANCE,
22-
Const.GENERIC_PUBLIC_ADDRESS,
23-
Const.LATEST)
32+
ACCOUNT,
33+
BALANCE,
34+
GENERIC_PUBLIC_ADDRESS,
35+
LATEST)
2436

2537
/**
2638
* Get Ether Balance for a single Address
2739
*/
28-
override fun getBalance(address: String?):
40+
override fun getBalance(address: String):
2941
Single<Double> = query.accountBalance(
30-
Const.ACCOUNT,
31-
Const.BALANCE,
42+
ACCOUNT,
43+
BALANCE,
3244
address,
33-
Const.LATEST).map { it.result?.toDouble() }
45+
LATEST).map { it.result?.toDouble() }
3446

3547
/**
3648
* Get Ether Balance for multiple Addresses in a single call
3749
*/
38-
override fun getMultiBalance(addresses: List<String>?):
50+
override fun getMultiBalance(addresses: List<String>):
3951
Single<List<Balance>> = query.accountMultiBalance(
40-
Const.ACCOUNT,
41-
Const.BALANCE_MULTI,
52+
ACCOUNT,
53+
BALANCE_MULTI,
4254
QueryUtils.retrieveList(addresses),
43-
Const.LATEST).map { it.result }
55+
LATEST).map { it.result }
4456

4557
/**
4658
* Get list of blocks mined by address
4759
*/
48-
override fun getBlocks(address: String?):
60+
override fun getBlocks(address: String):
4961
Single<List<BlockAccount>> = query.accountBlock(
50-
Const.ACCOUNT,
51-
Const.GET_MINED_BLOCKS,
62+
ACCOUNT,
63+
GET_MINED_BLOCKS,
5264
address,
53-
Const.BLOCKS).map { it.result }
65+
BLOCKS).map { it.result }
5466

5567
/**
5668
* Get a list of 'Normal' Transactions By Address
5769
*/
58-
override fun getTransactions(address: String?):
59-
Single<List<Tx>> = query.accountTxs(Const.ACCOUNT,
60-
Const.TX_LIST,
70+
override fun getTransactions(address: String):
71+
Single<List<Tx>> = query.accountTxs(
72+
ACCOUNT,
73+
TX_LIST,
6174
address,
62-
Const.START_BLOCK,
63-
Const.END_BLOCK,
64-
Const.ASC).map { it.result }
75+
START_BLOCK,
76+
END_BLOCK,
77+
ASC).map { it.result }
6578

6679
/**
6780
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
6881
*/
69-
override fun getERC20Tokens(address: String?):
82+
override fun getERC20Tokens(address: String):
7083
Single<List<ERC20Token>> = query.accountERC20Txs(
71-
Const.ACCOUNT,
72-
Const.TOKEN_TX,
84+
ACCOUNT,
85+
TOKEN_TX,
7386
address,
74-
Const.START_BLOCK,
75-
Const.END_BLOCK,
76-
Const.ASC).map { it.result }
87+
START_BLOCK,
88+
END_BLOCK,
89+
ASC).map { it.result }
7790

7891

7992
/**
8093
* [BETA] Get a list of 'Internal' Transactions by Address
8194
*/
82-
override fun getInternalTransactions(address: String?):
95+
override fun getInternalTransactions(address: String):
8396
Single<List<TxsInternal>> = query.accountInternalTxs(
84-
Const.ACCOUNT,
85-
Const.TX_LIST_INTERNAL,
97+
ACCOUNT,
98+
TX_LIST_INTERNAL,
8699
address,
87-
Const.START_BLOCK,
88-
Const.END_BLOCK,
89-
Const.ASC).map { it.result }
100+
START_BLOCK,
101+
END_BLOCK,
102+
ASC).map { it.result }
90103

91104
/**
92105
* Return network status

etherscanapi/src/main/java/jfyg/data/account/AccountsContract.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,32 @@ internal interface AccountsContract {
1515
/**
1616
* Get Ether Balance for a single Address
1717
*/
18-
fun getBalance(address: String?): Single<Double>
18+
fun getBalance(address: String): Single<Double>
1919

2020
/**
2121
* Get Ether Balance for multiple Addresses in a single call
2222
*/
23-
fun getMultiBalance(addresses: List<String>?): Single<List<Balance>>
23+
fun getMultiBalance(addresses: List<String>): Single<List<Balance>>
2424

2525
/**
2626
* Get list of blocks mined by address
2727
*/
28-
fun getBlocks(address: String?): Single<List<BlockAccount>>
28+
fun getBlocks(address: String): Single<List<BlockAccount>>
2929

3030
/**
3131
* Get a list of 'Normal' Transactions By Address
3232
*/
33-
fun getTransactions(address: String?): Single<List<Tx>>
33+
fun getTransactions(address: String): Single<List<Tx>>
3434

3535
/**
3636
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
3737
*/
38-
fun getERC20Tokens(address: String?): Single<List<ERC20Token>>
38+
fun getERC20Tokens(address: String): Single<List<ERC20Token>>
3939

4040
/**
4141
* [BETA] Get a list of 'Internal' Transactions by Address
4242
*/
43-
fun getInternalTransactions(address: String?): Single<List<TxsInternal>>
43+
fun getInternalTransactions(address: String): Single<List<TxsInternal>>
4444

4545
/**
4646
* Return network status

etherscanapi/src/main/java/jfyg/data/block/Blocks.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ package jfyg.data.block
33
import io.reactivex.Single
44
import jfyg.data.BlockMined
55
import jfyg.network.queries.ApiQuery
6-
import jfyg.utils.Const
6+
import jfyg.utils.BLOCK
7+
import jfyg.utils.BLOCK_NO
8+
import jfyg.utils.GET_BLOCK_REWARD
79

810
/**
911
* https://etherscan.io/apis#blocks
1012
*/
1113
class Blocks : BlocksContract {
1214
private val query = ApiQuery()
1315
private val genericNetworkQuery = query.blocksMined(
14-
Const.BLOCK,
15-
Const.GET_BLOCK_REWARD,
16-
Const.BLOCK_NO)
16+
BLOCK,
17+
GET_BLOCK_REWARD,
18+
BLOCK_NO)
1719

1820
/**
1921
* [BETA] Get Block And Uncle Rewards by BlockNo
2022
*/
21-
override fun getBlocksMined(blockNo: String?):
23+
override fun getBlocksMined(blockNo: String):
2224
Single<BlockMined> = query.blocksMined(
23-
Const.BLOCK,
24-
Const.GET_BLOCK_REWARD,
25+
BLOCK,
26+
GET_BLOCK_REWARD,
2527
blockNo).map { it.result }
2628

2729
/**

etherscanapi/src/main/java/jfyg/data/block/BlocksContract.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal interface BlocksContract {
1111
/**
1212
* [BETA] Get Block And Uncle Rewards by BlockNo
1313
*/
14-
fun getBlocksMined(blockNo: String?): Single<BlockMined>
14+
fun getBlocksMined(blockNo: String): Single<BlockMined>
1515

1616
/**
1717
* Return network status

etherscanapi/src/main/java/jfyg/data/contract/Contracts.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package jfyg.data.contract
22

33
import io.reactivex.Single
44
import jfyg.network.queries.ApiQuery
5-
import jfyg.utils.Const
5+
import jfyg.utils.CONTRACT
6+
import jfyg.utils.CONTRACT_PUBLIC_ADDRESS
7+
import jfyg.utils.GET_ABI
68

79
/**
810
* Newly verified Contracts are synced to the API servers within 5 minutes or less
@@ -12,18 +14,18 @@ class Contracts : ContractsContract {
1214

1315
private val query = ApiQuery()
1416
private val abiQuery = query.contractABI(
15-
Const.CONTRACT,
16-
Const.GET_ABI,
17-
Const.CONTRACT_PUBLIC_ADDRESS)
17+
CONTRACT,
18+
GET_ABI,
19+
CONTRACT_PUBLIC_ADDRESS)
1820

1921
/**
2022
* Get Contract ABI for Verified Contract Source Codes
2123
* https://etherscan.io/contractsVerified
2224
*/
23-
override fun getContractABI(address: String?):
25+
override fun getContractABI(address: String):
2426
Single<String> = query.contractABI(
25-
Const.CONTRACT,
26-
Const.GET_ABI,
27+
CONTRACT,
28+
GET_ABI,
2729
address).map { it.result }
2830

2931
/**

etherscanapi/src/main/java/jfyg/data/contract/ContractsContract.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal interface ContractsContract {
1212
* Get Contract ABI for Verified Contract Source Codes
1313
* https://etherscan.io/contractsVerified
1414
*/
15-
fun getContractABI(address: String?): Single<String>
15+
fun getContractABI(address: String): Single<String>
1616

1717
/**
1818
* Return network status

etherscanapi/src/main/java/jfyg/data/stat/Stats.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ package jfyg.data.stat
22

33
import io.reactivex.Single
44
import jfyg.network.queries.ApiQuery
5-
import jfyg.utils.Const
5+
import jfyg.utils.ETH_PRICE
6+
import jfyg.utils.ETH_SUPPLY
7+
import jfyg.utils.STATS
68

79
/**
810
* https://etherscan.io/apis#stats
911
*/
1012
class Stats : StatsContract {
1113

1214
private val query = ApiQuery()
13-
private val supplyQuery = query.statSupply(Const.STATS, Const.ETH_SUPPLY)
14-
private val priceQuery = query.statPrice(Const.STATS, Const.ETH_PRICE)
15+
private val supplyQuery = query.statSupply(STATS, ETH_SUPPLY)
16+
private val priceQuery = query.statPrice(STATS, ETH_PRICE)
1517

1618
private val wei = 1000000000000000000 // 1 Ether is 1000000000000000000 Wei
1719

etherscanapi/src/main/java/jfyg/data/transaction/Transactions.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import io.reactivex.Single
44
import jfyg.data.TxExecutionStatus
55
import jfyg.data.TxReceiptStatus
66
import jfyg.network.queries.ApiQuery
7-
import jfyg.utils.Const
7+
import jfyg.utils.GET_STATUS
8+
import jfyg.utils.GET_TX_RECEIPT_STATUS
9+
import jfyg.utils.TRANSACTION
10+
import jfyg.utils.TRANSACTION_PUBLIC_ADDRESS
811

912
/**
1013
* https://etherscan.io/apis#transactions
@@ -13,18 +16,18 @@ class Transactions : TransactionsContract {
1316

1417
private val query = ApiQuery()
1518
private val genericNetworkQuery = query.txReceiptStatus(
16-
Const.TRANSACTION,
17-
Const.GET_STATUS,
18-
Const.TRANSACTION_PUBLIC_ADDRESS)
19+
TRANSACTION,
20+
GET_STATUS,
21+
TRANSACTION_PUBLIC_ADDRESS)
1922

2023
/**
2124
* [BETA] Check Contract Execution Status (if there was an error during contract execution)
2225
* Note: isError":"0" = Pass , isError":"1" = Error during Contract Execution
2326
*/
2427
override fun getTxExecutionStatus(txHash: String):
2528
Single<TxExecutionStatus> = query.txExecutionStatus(
26-
Const.TRANSACTION,
27-
Const.GET_STATUS,
29+
TRANSACTION,
30+
GET_STATUS,
2831
txHash).map { it.result }
2932

3033
/**
@@ -33,8 +36,8 @@ class Transactions : TransactionsContract {
3336
*/
3437
override fun getTxReceiptStatus(txHash: String):
3538
Single<TxReceiptStatus> = query.txReceiptStatus(
36-
Const.TRANSACTION,
37-
Const.GET_TX_RECEIPT_STATUS,
39+
TRANSACTION,
40+
GET_TX_RECEIPT_STATUS,
3841
txHash).map { it.result }
3942

4043
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
55
import retrofit2.converter.gson.GsonConverterFactory
66
import com.google.gson.GsonBuilder
77
import io.reactivex.schedulers.Schedulers
8-
import jfyg.utils.Const
8+
import jfyg.utils.BASE_URL
99

1010
/**
1111
* Client used to create the network call
1212
*/
1313
internal class RestClient {
1414

15-
private var baseUrl: String = Const.BASE_URL
15+
private var baseUrl: String = BASE_URL
1616
private var networkService: NetworkService
1717

1818
init {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import jfyg.network.response.transaction.TxContractReceiptResponse
2020
* A mediator between the responses and errors that come from every query
2121
*/
2222
internal class ApiQuery : AccountsApi, StatsApi, ContractsApi, TransactionsApi, BlocksApi {
23-
23+
// retrofit allows the usage of null parameters when building queries and some parameters being passed in the
24+
// following classes are null, hence the usage of .?func()
2425

2526
override fun accountBalance(module: String?,
2627
action: String?,

0 commit comments

Comments
 (0)