Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/src/main/java/jfyg/etherscan/helloetherescan/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import android.support.v7.app.AppCompatActivity
import android.util.Log
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.rxkotlin.subscribeBy
import jfyg.account.Account
import jfyg.contract.ContractABI
import jfyg.stat.Stat
import jfyg.transaction.TxContractStatus
import jfyg.data.account.Account
import jfyg.data.contract.ContractABI
import jfyg.data.stat.Stat
import jfyg.data.transaction.TxContractStatus
import kotlinx.android.synthetic.main.activity_main.*


Expand All @@ -30,7 +30,8 @@ class MainActivity : AppCompatActivity() {
fab.setOnClickListener {

//stat test
stat.getLastPriceInBtc().observeOn(AndroidSchedulers.mainThread())
stat.getLastPriceInBtc()
.observeOn(AndroidSchedulers.mainThread())
?.subscribeBy {
Log.d(TAG, "The current price of Ether in Btc: $it")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

data class Balances(var account: String? = null,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

data class Blocks(var blockNumber: String? = null,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

data class TxExecutionStatus(var isError: String? = null,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package jfyg.model
package jfyg.data

data class TxReceiptStatus(var status: String? = null)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

import com.google.gson.annotations.SerializedName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.model
package jfyg.data

import com.google.gson.annotations.SerializedName

Expand All @@ -9,10 +9,10 @@ data class TxsInternal(var blockNumber: String? = null,
var hash: String? = null,

@SerializedName("from")
var transactionFrom: String? = null,
var transactionFrom: String? = null,

@SerializedName("to")
var transactionTo: String? = null,
var transactionTo: String? = null,

var value: String? = null,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package jfyg.account
package jfyg.data.account

import io.reactivex.Single
import jfyg.model.Balances
import jfyg.model.Blocks
import jfyg.model.Txs
import jfyg.model.TxsInternal
import jfyg.queries.QueryMediator
import jfyg.data.Balances
import jfyg.data.Blocks
import jfyg.data.Txs
import jfyg.data.TxsInternal
import jfyg.network.queries.ApiQuery
import jfyg.utils.QueryUtils

/**
* https://etherscan.io/apis#accounts
*/
class Account : AccountContract {

private val query = QueryMediator()
private val query = ApiQuery()
private val genericNetworkQuery = query.accountBalance("account",
"balance",
"0x82e4499D4b2A669831a3881d61BB24f7b620c61a",
"latest")

private val queryUtil = QueryUtils()

/**
* Return account balance
*/
Expand All @@ -36,7 +34,7 @@ class Account : AccountContract {
override fun getMultiBalance(addresses: ArrayList<String>?): Single<ArrayList<Balances>> =
query.accountMultiBalance("account",
"balancemulti",
queryUtil.retrieveList(addresses),
QueryUtils.retrieveList(addresses),
"latest").map { it.result }

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package jfyg.account
package jfyg.data.account

import io.reactivex.Single
import jfyg.model.Balances
import jfyg.model.Blocks
import jfyg.model.Txs
import jfyg.model.TxsInternal
import jfyg.data.Balances
import jfyg.data.Blocks
import jfyg.data.Txs
import jfyg.data.TxsInternal

/**
* https://etherscan.io/apis#accounts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package jfyg.contract
package jfyg.data.contract

import io.reactivex.Single
import jfyg.queries.QueryMediator
import jfyg.network.queries.ApiQuery

/**
* Newly verified Contracts are synced to the API servers within 5 minutes or less
* https://etherscan.io/apis#contracts
*/
class ContractABI : ContractABIContract {
private val query = QueryMediator()

private val query = ApiQuery()
private val abiQuery = query.contractABI("contract",
"getabi",
"0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.contract
package jfyg.data.contract

import io.reactivex.Single

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package jfyg.stat
package jfyg.data.stat

import io.reactivex.Single
import jfyg.queries.QueryMediator
import jfyg.network.queries.ApiQuery

/**
* https://etherscan.io/apis#stats
*/
class Stat : StatContract {

private val query = QueryMediator()
private val query = ApiQuery()
private val supplyQuery = query.statSupply("stats", "ethsupply")
private val priceQuery = query.statPrice("stats", "ethprice")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.stat
package jfyg.data.stat

import io.reactivex.Single

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package jfyg.transaction
package jfyg.data.transaction

import io.reactivex.Single
import jfyg.model.TxExecutionStatus
import jfyg.model.TxReceiptStatus
import jfyg.data.TxExecutionStatus
import jfyg.data.TxReceiptStatus

/**
* https://etherscan.io/apis#transactions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package jfyg.transaction
package jfyg.data.transaction

import io.reactivex.Single
import jfyg.model.TxExecutionStatus
import jfyg.model.TxReceiptStatus
import jfyg.queries.QueryMediator
import jfyg.data.TxExecutionStatus
import jfyg.data.TxReceiptStatus
import jfyg.network.queries.ApiQuery

/**
* https://etherscan.io/apis#transactions
*/
class TxContractStatus : TxContract {

private val query = QueryMediator()
private val query = ApiQuery()
private val genericNetworkQuery = query.txReceiptStatus("transaction",
"getstatus",
"0x15f8e5ea1079d9a0bb04a4c58ae5fe7654b5b2b4463375ff7ffb490aa0032f3a")
Expand Down
22 changes: 11 additions & 11 deletions etherscanapi/src/main/java/jfyg/network/NetworkService.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package jfyg.network

import io.reactivex.Single
import jfyg.response.account.AccountBalanceResponse
import jfyg.response.account.AccountBlockResponse
import jfyg.response.account.AccountInternalTxResponse
import jfyg.response.account.AccountMultiBalanceResponse
import jfyg.response.account.AccountTxResponse
import jfyg.response.contract.ContractABIResponse
import jfyg.response.stat.StatPriceResponse
import jfyg.response.stat.StatSupplyResponse
import jfyg.response.transaction.TxContractExecutionResponse
import jfyg.response.transaction.TxContractReceiptResponse
import jfyg.network.response.account.AccountBalanceResponse
import jfyg.network.response.account.AccountBlockResponse
import jfyg.network.response.account.AccountInternalTxResponse
import jfyg.network.response.account.AccountMultiBalanceResponse
import jfyg.network.response.account.AccountTxResponse
import jfyg.network.response.contract.ContractABIResponse
import jfyg.network.response.stat.StatPriceResponse
import jfyg.network.response.stat.StatSupplyResponse
import jfyg.network.response.transaction.TxContractExecutionResponse
import jfyg.network.response.transaction.TxContractReceiptResponse
import retrofit2.http.GET
import retrofit2.http.Query

/**
* Etherscan request endpoints
* Etherscan request service
*/
internal interface NetworkService {

Expand Down
3 changes: 2 additions & 1 deletion etherscanapi/src/main/java/jfyg/network/RestClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import com.google.gson.GsonBuilder
import io.reactivex.schedulers.Schedulers
import jfyg.utils.Const

/**
* Client used to create the network call
*/
internal class RestClient {

private var baseUrl: String = "http://api.etherscan.io/"
private var baseUrl: String = Const.BASE_URL
private var networkService: NetworkService

init {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package jfyg.queries
package jfyg.network.queries

import io.reactivex.Single
import jfyg.response.account.AccountBalanceResponse
import jfyg.response.account.AccountBlockResponse
import jfyg.response.account.AccountInternalTxResponse
import jfyg.response.account.AccountMultiBalanceResponse
import jfyg.response.account.AccountTxResponse
import jfyg.network.response.account.AccountBalanceResponse
import jfyg.network.response.account.AccountBlockResponse
import jfyg.network.response.account.AccountInternalTxResponse
import jfyg.network.response.account.AccountMultiBalanceResponse
import jfyg.network.response.account.AccountTxResponse

internal interface AccountQueries {
internal interface AccountApi {

/**
* Get ether balance for a single address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package jfyg.queries
package jfyg.network.queries

import io.reactivex.Single
import jfyg.ApiKey
import jfyg.network.RestClient
import jfyg.response.account.AccountBalanceResponse
import jfyg.response.account.AccountBlockResponse
import jfyg.response.account.AccountInternalTxResponse
import jfyg.response.account.AccountMultiBalanceResponse
import jfyg.response.account.AccountTxResponse
import jfyg.response.contract.ContractABIResponse
import jfyg.response.stat.StatPriceResponse
import jfyg.response.stat.StatSupplyResponse
import jfyg.response.transaction.TxContractExecutionResponse
import jfyg.response.transaction.TxContractReceiptResponse
import jfyg.network.response.account.AccountBalanceResponse
import jfyg.network.response.account.AccountBlockResponse
import jfyg.network.response.account.AccountInternalTxResponse
import jfyg.network.response.account.AccountMultiBalanceResponse
import jfyg.network.response.account.AccountTxResponse
import jfyg.network.response.contract.ContractABIResponse
import jfyg.network.response.stat.StatPriceResponse
import jfyg.network.response.stat.StatSupplyResponse
import jfyg.network.response.transaction.TxContractExecutionResponse
import jfyg.network.response.transaction.TxContractReceiptResponse

/**
* A mediator between the responses and errors that come from every query
*/
internal class QueryMediator : AccountQueries, StatQueries, ContractABIQueries, TxQueries {
internal class ApiQuery : AccountApi, StatApi, ContractABIApi, TxApi {


override fun accountBalance(module: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package jfyg.queries
package jfyg.network.queries

import io.reactivex.Single
import jfyg.response.contract.ContractABIResponse
import jfyg.network.response.contract.ContractABIResponse

internal interface ContractABIQueries {
internal interface ContractABIApi {

/**
* Get ABI for a contracts from a given address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package jfyg.queries
package jfyg.network.queries

import io.reactivex.Single
import jfyg.response.stat.StatPriceResponse
import jfyg.response.stat.StatSupplyResponse
import jfyg.network.response.stat.StatPriceResponse
import jfyg.network.response.stat.StatSupplyResponse

internal interface StatQueries {
internal interface StatApi {

/**
* Get ether last price
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package jfyg.queries
package jfyg.network.queries

import io.reactivex.Single
import jfyg.response.transaction.TxContractExecutionResponse
import jfyg.response.transaction.TxContractReceiptResponse
import jfyg.network.response.transaction.TxContractExecutionResponse
import jfyg.network.response.transaction.TxContractReceiptResponse

internal interface TxQueries {
internal interface TxApi {

/**
* Check contract execution status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jfyg.response
package jfyg.network.response

/**
* Base response that all queries will utilize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package jfyg.response.account
package jfyg.network.response.account

import jfyg.response.BaseResponse
import jfyg.network.response.BaseResponse

/**
* Balance of Ether existing in an account
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jfyg.response.account
package jfyg.network.response.account

import jfyg.model.Blocks
import jfyg.response.BaseResponse
import jfyg.data.Blocks
import jfyg.network.response.BaseResponse

/**
* Blocks mined by an account
Expand Down
Loading