Skip to content

Commit 98fe006

Browse files
author
Ebenezer Ackon
committed
handle fetching offchain/internal Transactions
1 parent 71ede18 commit 98fe006

File tree

9 files changed

+143
-2
lines changed

9 files changed

+143
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MainActivity : AppCompatActivity() {
3939
Log.d(TAG, "The Account(1) Balance is: ${account.getMultiBalance(threeAddresses())?.get(1)?.balance}")
4040
Log.d(TAG, "The Account Size of Blocks is: ${account.getBlocks("0x82e4499D4b2A669831a3881d61BB24f7b620c61a")?.size}")
4141
Log.d(TAG, "The Account Size of Transactions is: ${account.getTransactions("0x82e4499D4b2A669831a3881d61BB24f7b620c61a")?.size}")
42+
Log.d(TAG, "The Account Size of Internal Transactions is: ${account.getInternalTransactions("0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3")?.size}")
4243

4344
//transactions
4445
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.account
33
import jfyg.model.Balances
44
import jfyg.model.Blocks
55
import jfyg.model.Transactions
6+
import jfyg.model.TransactionsInternal
67
import jfyg.queries.QueryMediator
78
import jfyg.utils.QueryUtils
89

@@ -34,7 +35,10 @@ class Account : AccountContract {
3435
account, "0", "99999999",
3536
"asc").let { query.fetchAccountTransaction()?.result }
3637

37-
//todo #47
38+
override fun getInternalTransactions(account: String?): ArrayList<TransactionsInternal>? =
39+
query.accountInternalTransactions("account", "txlistinternal",
40+
account, "0", "99999999",
41+
"asc").let { query.fetchAccountInternalTransaction()?.result }
3842

3943
override fun getNetworkStatus(): String? = genericNetworkQuery.let { query.fetchAccountBalance()?.status }
4044

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.account
33
import jfyg.model.Balances
44
import jfyg.model.Blocks
55
import jfyg.model.Transactions
6+
import jfyg.model.TransactionsInternal
67

78
interface AccountContract {
89

@@ -36,4 +37,9 @@ interface AccountContract {
3637
*/
3738
fun getTransactions(account: String?): ArrayList<Transactions>?
3839

40+
/**
41+
* Get a list of 'Internal' Transactions by Address
42+
*/
43+
fun getInternalTransactions(account: String?): ArrayList<TransactionsInternal>?
44+
3945
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package jfyg.model
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class TransactionsInternal(var blockNumber: String? = null,
6+
7+
var timeStamp: String? = null,
8+
9+
var hash: String? = null,
10+
11+
@SerializedName("from")
12+
var transactionFrom: String? = null,
13+
14+
@SerializedName("to")
15+
var transactionTo: String? = null,
16+
17+
var value: String? = null,
18+
19+
var contactAddress: String? = null,
20+
21+
var input: String? = null,
22+
23+
var type: String? = null,
24+
25+
var gas: String? = null,
26+
27+
var gasUsed: String? = null,
28+
29+
var traceId: String? = null,
30+
31+
var isError: String? = null,
32+
33+
var errCode: String? = null)

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.response.account.AccountBalanceResponse
55
import jfyg.response.account.AccountBlockResponse
6+
import jfyg.response.account.AccountInternalTransactionResponse
67
import jfyg.response.account.AccountMultiBalanceResponse
78
import jfyg.response.account.AccountTransactionResponse
89
import jfyg.response.stat.StatPriceResponse
@@ -55,4 +56,13 @@ interface NetworkService {
5556
@Query("sort") sort: String?,
5657
@Query("apikey") apikey: String?): Single<AccountTransactionResponse>
5758

59+
@GET("api")
60+
fun getAccountInternalTransactions(@Query("module") module: String?,
61+
@Query("action") action: String?,
62+
@Query("address") address: String?,
63+
@Query("startblock") startblock: String?,
64+
@Query("endblock") endblock: String?,
65+
@Query("sort") sort: String?,
66+
@Query("apikey") apikey: String?): Single<AccountInternalTransactionResponse>
67+
5868
}

etherscanapi/src/main/java/jfyg/queries/AccountQueries.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jfyg.queries
33
import io.reactivex.disposables.Disposable
44
import jfyg.response.account.AccountBalanceResponse
55
import jfyg.response.account.AccountBlockResponse
6+
import jfyg.response.account.AccountInternalTransactionResponse
67
import jfyg.response.account.AccountMultiBalanceResponse
78
import jfyg.response.account.AccountTransactionResponse
89

@@ -42,6 +43,15 @@ interface AccountQueries {
4243
endblock: String?,
4344
sort: String?): Disposable?
4445

46+
/**
47+
* Get a list of 'Internal' transactions by address
48+
*/
49+
fun accountInternalTransactions(module: String?,
50+
action: String?,
51+
address: String?,
52+
startblock: String?,
53+
endblock: String?,
54+
sort: String?): Disposable?
4555

4656
fun handleResponse(response: AccountBalanceResponse)
4757

@@ -51,4 +61,6 @@ interface AccountQueries {
5161

5262
fun handleResponse(response: AccountTransactionResponse)
5363

64+
fun handleResponse(response: AccountInternalTransactionResponse)
65+
5466
}

etherscanapi/src/main/java/jfyg/queries/QueryMediator.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package jfyg.queries
33
import android.util.Log
44
import io.reactivex.android.schedulers.AndroidSchedulers
55
import io.reactivex.disposables.Disposable
6-
import io.reactivex.schedulers.Schedulers
76
import jfyg.ApiKey
87
import jfyg.network.RestClient
98
import jfyg.response.account.AccountBalanceResponse
109
import jfyg.response.account.AccountBlockResponse
10+
import jfyg.response.account.AccountInternalTransactionResponse
1111
import jfyg.response.account.AccountMultiBalanceResponse
1212
import jfyg.response.account.AccountTransactionResponse
1313
import jfyg.response.stat.StatPriceResponse
@@ -25,6 +25,7 @@ class QueryMediator : AccountQueries, StatQueries { //todo #36
2525
private var accountMultiBalanceInfo = AccountMultiBalanceResponse()
2626
private var accountBlockInfo = AccountBlockResponse()
2727
private var accountTransactionInfo = AccountTransactionResponse()
28+
private var accountInternalTransactionInfo = AccountInternalTransactionResponse()
2829

2930

3031
override fun accountBalance(module: String?, action: String?, address: String?, tag: String?): Disposable? =
@@ -56,6 +57,14 @@ class QueryMediator : AccountQueries, StatQueries { //todo #36
5657
.observeOn(AndroidSchedulers.mainThread())
5758
.subscribe(this::handleResponse, this::handleError)
5859

60+
override fun accountInternalTransactions(module: String?, action: String?, address: String?, startblock: String?,
61+
endblock: String?, sort: String?): Disposable? =
62+
RestClient().getQuery().getAccountInternalTransactions(module, action, address, startblock, endblock, sort,
63+
ApiKey.takeOff.callApiKey())
64+
65+
.observeOn(AndroidSchedulers.mainThread())
66+
.subscribe(this::handleResponse, this::handleError)
67+
5968

6069
override fun statPrice(module: String, action: String): Disposable? =
6170
RestClient().getQuery().getStat(module, action, ApiKey.takeOff.callApiKey())
@@ -95,6 +104,10 @@ class QueryMediator : AccountQueries, StatQueries { //todo #36
95104
accountMultiBalanceInfo = response
96105
}
97106

107+
override fun handleResponse(response: AccountInternalTransactionResponse) {
108+
accountInternalTransactionInfo = response
109+
}
110+
98111
private fun handleError(error: Throwable) {
99112
Log.d(TAG, "The error ${error.message}")
100113
}
@@ -105,5 +118,6 @@ class QueryMediator : AccountQueries, StatQueries { //todo #36
105118
fun fetchAccountMultiBalance(): AccountMultiBalanceResponse? = accountMultiBalanceInfo
106119
fun fetchAccountBlock(): AccountBlockResponse? = accountBlockInfo
107120
fun fetchAccountTransaction(): AccountTransactionResponse? = accountTransactionInfo
121+
fun fetchAccountInternalTransaction(): AccountInternalTransactionResponse? = accountInternalTransactionInfo
108122

109123
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package jfyg.response.account
2+
3+
import jfyg.model.TransactionsInternal
4+
import jfyg.response.BaseResponse
5+
6+
/**
7+
* Internal Transactions recorded by an account
8+
*/
9+
class AccountInternalTransactionResponse(var result: ArrayList<TransactionsInternal>? = null) : BaseResponse() {
10+
}

etherscanapi/src/test/java/jfyg/account/AccountTest.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder
55
import jfyg.response.BaseResponse
66
import jfyg.response.account.AccountBalanceResponse
77
import jfyg.response.account.AccountBlockResponse
8+
import jfyg.response.account.AccountInternalTransactionResponse
89
import jfyg.response.account.AccountMultiBalanceResponse
910
import jfyg.response.account.AccountTransactionResponse
1011
import org.junit.Assert.assertEquals
@@ -112,6 +113,45 @@ class AccountTest {
112113
]
113114
}"""
114115

116+
private val internalTransaction = """
117+
{
118+
"status": "1",
119+
"message": "OK",
120+
"result": [
121+
{
122+
"blockNumber": "2535368",
123+
"timeStamp": "1477837690",
124+
"hash": "0x8a1a9989bda84f80143181a68bc137ecefa64d0d4ebde45dd94fc0cf49e70cb6",
125+
"from": "0x20d42f2e99a421147acf198d775395cac2e8b03d",
126+
"to": "",
127+
"value": "0",
128+
"contractAddress": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
129+
"input": "",
130+
"type": "create",
131+
"gas": "254791",
132+
"gasUsed": "46750",
133+
"traceId": "0",
134+
"isError": "0",
135+
"errCode": ""
136+
},
137+
{
138+
"blockNumber": "2535479",
139+
"timeStamp": "1477839134",
140+
"hash": "0x1a50f1dc0bc912745f7d09b988669f71d199719e2fb7592c2074ede9578032d0",
141+
"from": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
142+
"to": "0x20d42f2e99a421147acf198d775395cac2e8b03d",
143+
"value": "100000000000000000",
144+
"contractAddress": "",
145+
"input": "",
146+
"type": "call",
147+
"gas": "235231",
148+
"gasUsed": "0",
149+
"traceId": "0",
150+
"isError": "0",
151+
"errCode": ""
152+
}
153+
]
154+
}"""
115155
private val inputBadResponse = """
116156
{
117157
"status": "0",
@@ -166,6 +206,17 @@ class AccountTest {
166206
assertEquals("0", response.result?.get(1)?.isError)
167207
}
168208

209+
@Test
210+
fun getInternalTransactions() {
211+
val response = gson.fromJson(internalTransaction, AccountInternalTransactionResponse::class.java)
212+
assertEquals("0x20d42f2e99a421147acf198d775395cac2e8b03d", response.result?.get(0)?.transactionFrom)
213+
assertEquals("0x20d42f2e99a421147acf198d775395cac2e8b03d", response.result?.get(1)?.transactionTo)
214+
assertEquals("0", response.result?.get(0)?.value)
215+
assertEquals("235231", response.result?.get(1)?.gas)
216+
assertEquals("call", response.result?.get(1)?.type)
217+
assertEquals("0", response.result?.get(1)?.isError)
218+
}
219+
169220
@Test
170221
fun networkStatusIsDown() {
171222
val response = gson.fromJson(inputBadResponse, BaseResponse::class.java)

0 commit comments

Comments
 (0)