Skip to content

Commit cae67e2

Browse files
authored
Merge pull request #76 from EbenezerGH/handle-erc-20-tx
Handle erc 20 tx
2 parents c7526ee + 376e338 commit cae67e2

File tree

13 files changed

+191
-25
lines changed

13 files changed

+191
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
3737
}
3838

3939
//account test
40-
account.getTransactions("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3")
40+
account.getERC20Tokens("0x4e83362442b8d1bec281594cea3050c8eb01311c")
4141
.observeOn(AndroidSchedulers.mainThread())
4242
?.subscribeBy {
4343
Log.d(TAG, "The Account Size of Transactions is: ${it.size}")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package jfyg.data
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class ERC20Token(var blockNumber: String? = null,
6+
7+
var timeStamp: String? = null,
8+
9+
var hash: String? = null,
10+
11+
var nonce: String? = null,
12+
13+
var blockHash: String? = null,
14+
15+
@SerializedName("from")
16+
var transactionFrom: String? = null,
17+
18+
var contractAddress: String? = null,
19+
20+
@SerializedName("to")
21+
var transactionTo: String? = null,
22+
23+
var value: String? = null,
24+
25+
var tokenName: String? = null,
26+
27+
var tokenSymbol: String? = null,
28+
29+
var tokenDecimal: String? = null,
30+
31+
var transactionIndex: String? = null,
32+
33+
var gas: String? = null,
34+
35+
var gasPrice: String? = null,
36+
37+
var gasUsed: String? = null,
38+
39+
var cumulativeGasUsed: String? = null,
40+
41+
var input: String? = null,
42+
43+
var confirmations: String? = null)

etherscanapi/src/main/java/jfyg/data/Txs.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ data class Txs(var blockNumber: String? = null,
1515
var transactionIndex: String? = null,
1616

1717
@SerializedName("from")
18-
var transactionFrom: String? = null,
18+
var transactionFrom: String? = null,
1919

2020
@SerializedName("to")
21-
var transactionTo: String? = null,
21+
var transactionTo: String? = null,
2222

2323
var value: String? = null,
2424

@@ -29,7 +29,7 @@ data class Txs(var blockNumber: String? = null,
2929
var isError: String? = null,
3030

3131
@SerializedName("txreceipt_status")
32-
var receiptStatus: String? = null,
32+
var receiptStatus: String? = null,
3333

3434
var input: String? = null,
3535

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package jfyg.data.account
33
import io.reactivex.Single
44
import jfyg.data.Balances
55
import jfyg.data.Blocks
6+
import jfyg.data.ERC20Token
67
import jfyg.data.Txs
78
import jfyg.data.TxsInternal
89
import jfyg.network.queries.ApiQuery
10+
import jfyg.utils.Const
911
import jfyg.utils.QueryUtils
1012

1113
/**
@@ -16,7 +18,7 @@ class Account : AccountContract {
1618
private val query = ApiQuery()
1719
private val genericNetworkQuery = query.accountBalance("account",
1820
"balance",
19-
"0x82e4499D4b2A669831a3881d61BB24f7b620c61a",
21+
Const.GENERIC_PUBLIC_ADDRESS,
2022
"latest")
2123

2224
/**
@@ -50,18 +52,30 @@ class Account : AccountContract {
5052
* Get a list of 'Normal' Transactions By Address
5153
*/
5254
override fun getTransactions(address: String?): Single<ArrayList<Txs>> =
53-
query.accountTransactions("account",
55+
query.accountTxs("account",
5456
"txlist",
5557
address,
5658
"0",
5759
"99999999",
5860
"asc").map { it.result }
5961

6062
/**
61-
* Get a list of 'Internal' Transactions by Address
63+
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
64+
*/
65+
override fun getERC20Tokens(address: String?): Single<ArrayList<ERC20Token>> =
66+
query.accountERC20Txs("account",
67+
"tokentx",
68+
address,
69+
"0",
70+
"999999999",
71+
"asc").map { it.result }
72+
73+
74+
/**
75+
* [BETA] Get a list of 'Internal' Transactions by Address
6276
*/
6377
override fun getInternalTransactions(address: String?): Single<ArrayList<TxsInternal>> =
64-
query.accountInternalTransactions("account",
78+
query.accountInternalTxs("account",
6579
"txlistinternal",
6680
address,
6781
"0",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.data.account
33
import io.reactivex.Single
44
import jfyg.data.Balances
55
import jfyg.data.Blocks
6+
import jfyg.data.ERC20Token
67
import jfyg.data.Txs
78
import jfyg.data.TxsInternal
89

@@ -32,7 +33,12 @@ internal interface AccountContract {
3233
fun getTransactions(address: String?): Single<ArrayList<Txs>>
3334

3435
/**
35-
* Get a list of 'Internal' Transactions by Address
36+
* [BETA] Get a list of "ERC20 - Token Transfer Events" by Address
37+
*/
38+
fun getERC20Tokens(address: String?): Single<ArrayList<ERC20Token>>
39+
40+
/**
41+
* [BETA] Get a list of 'Internal' Transactions by Address
3642
*/
3743
fun getInternalTransactions(address: String?): Single<ArrayList<TxsInternal>>
3844

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package jfyg.data.contract
22

33
import io.reactivex.Single
44
import jfyg.network.queries.ApiQuery
5+
import jfyg.utils.Const
56

67
/**
78
* Newly verified Contracts are synced to the API servers within 5 minutes or less
@@ -12,7 +13,7 @@ class ContractABI : ContractABIContract {
1213
private val query = ApiQuery()
1314
private val abiQuery = query.contractABI("contract",
1415
"getabi",
15-
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
16+
Const.CONTRACT_PUBLIC_ADDRESS)
1617

1718
/**
1819
* Return contract ABI for Verified Contract Source Code

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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
78

89
/**
910
* https://etherscan.io/apis#transactions
@@ -13,7 +14,7 @@ class TxStatus : TxStatusContract {
1314
private val query = ApiQuery()
1415
private val genericNetworkQuery = query.txReceiptStatus("transaction",
1516
"getstatus",
16-
"0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a")
17+
Const.TRANSACTION_PUBLIC_ADDRESS)
1718

1819
/**
1920
* [BETA] Check Contract Execution Status (if there was an error during contract execution)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.network
33
import io.reactivex.Single
44
import jfyg.network.response.account.AccountBalanceResponse
55
import jfyg.network.response.account.AccountBlockResponse
6+
import jfyg.network.response.account.ERC20Response
67
import jfyg.network.response.account.AccountInternalTxResponse
78
import jfyg.network.response.account.AccountMultiBalanceResponse
89
import jfyg.network.response.account.AccountTxResponse
@@ -59,6 +60,15 @@ internal interface NetworkService {
5960
@Query("sort") sort: String?,
6061
@Query("apikey") apikey: String?): Single<AccountTxResponse>
6162

63+
@GET("api")
64+
fun getAccountERC20Transactions(@Query("module") module: String?,
65+
@Query("action") action: String?,
66+
@Query("address") address: String?,
67+
@Query("startblock") startblock: String?,
68+
@Query("endblock") endblock: String?,
69+
@Query("sort") sort: String?,
70+
@Query("apikey") apikey: String?): Single<ERC20Response>
71+
6272
@GET("api")
6373
fun getAccountInternalTransactions(@Query("module") module: String?,
6474
@Query("action") action: String?,

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.network.queries
33
import io.reactivex.Single
44
import jfyg.network.response.account.AccountBalanceResponse
55
import jfyg.network.response.account.AccountBlockResponse
6+
import jfyg.network.response.account.ERC20Response
67
import jfyg.network.response.account.AccountInternalTxResponse
78
import jfyg.network.response.account.AccountMultiBalanceResponse
89
import jfyg.network.response.account.AccountTxResponse
@@ -36,17 +37,27 @@ internal interface AccountApi {
3637
/**
3738
* Get a list of 'Normal' transactions by address
3839
*/
39-
fun accountTransactions(module: String?,
40+
fun accountTxs(module: String?,
4041
action: String?,
4142
address: String?,
4243
startblock: String?,
4344
endblock: String?,
4445
sort: String?): Single<AccountTxResponse>
4546

47+
/**
48+
* Get a list of ERC20 transactions by address
49+
*/
50+
fun accountERC20Txs(module: String?,
51+
action: String?,
52+
address: String?,
53+
startblock: String?,
54+
endblock: String?,
55+
sort: String?): Single<ERC20Response>
56+
4657
/**
4758
* Get a list of 'Internal' transactions by address
4859
*/
49-
fun accountInternalTransactions(module: String?,
60+
fun accountInternalTxs(module: String?,
5061
action: String?,
5162
address: String?,
5263
startblock: String?,

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import jfyg.ApiKey
55
import jfyg.network.RestClient
66
import jfyg.network.response.account.AccountBalanceResponse
77
import jfyg.network.response.account.AccountBlockResponse
8+
import jfyg.network.response.account.ERC20Response
89
import jfyg.network.response.account.AccountInternalTxResponse
910
import jfyg.network.response.account.AccountMultiBalanceResponse
1011
import jfyg.network.response.account.AccountTxResponse
@@ -38,20 +39,28 @@ internal class ApiQuery : AccountApi, StatApi, ContractABIApi, TxApi {
3839
blocktype: String?): Single<AccountBlockResponse> =
3940
RestClient().getQuery().getAccountBlock(module, action, address, blocktype, ApiKey.takeOff.callApiKey())
4041

41-
override fun accountTransactions(module: String?,
42-
action: String?,
43-
address: String?,
44-
startblock: String?,
45-
endblock: String?,
46-
sort: String?): Single<AccountTxResponse> =
42+
override fun accountTxs(module: String?,
43+
action: String?,
44+
address: String?,
45+
startblock: String?,
46+
endblock: String?,
47+
sort: String?): Single<AccountTxResponse> =
4748
RestClient().getQuery().getAccountTransactions(module, action, address, startblock, endblock, sort, ApiKey.takeOff.callApiKey())
4849

49-
override fun accountInternalTransactions(module: String?,
50-
action: String?,
51-
address: String?,
52-
startblock: String?,
53-
endblock: String?,
54-
sort: String?): Single<AccountInternalTxResponse> =
50+
override fun accountERC20Txs(module: String?,
51+
action: String?,
52+
address: String?,
53+
startblock: String?,
54+
endblock: String?,
55+
sort: String?): Single<ERC20Response> =
56+
RestClient().getQuery().getAccountERC20Transactions(module, action, address, startblock, endblock, sort, ApiKey.takeOff.callApiKey())
57+
58+
override fun accountInternalTxs(module: String?,
59+
action: String?,
60+
address: String?,
61+
startblock: String?,
62+
endblock: String?,
63+
sort: String?): Single<AccountInternalTxResponse> =
5564
RestClient().getQuery().getAccountInternalTransactions(module, action, address, startblock, endblock, sort, ApiKey.takeOff.callApiKey())
5665

5766
override fun contractABI(module: String?, action: String?, address: String?): Single<ContractABIResponse> =

0 commit comments

Comments
 (0)