@@ -3,14 +3,14 @@ package jfyg.etherscan.helloetherescan
33import android.os.Bundle
44import android.support.v7.app.AppCompatActivity
55import 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
1311import kotlinx.android.synthetic.main.activity_main.*
12+ import kotlinx.coroutines.GlobalScope
13+ import kotlinx.coroutines.launch
1414
1515
1616class 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+
0 commit comments