Skip to content

Commit

Permalink
Remove Infura options from RpcSource
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Mar 13, 2024
1 parent 4ec928a commit 74af53b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ object Configuration {
val watchAddress: String? = null
const val defaultsWords = "apart approve black comfort steel spin real renew tone primary key cherry"

const val infuraProjectId = "2a1306f1d12f4c109a4d4fb9be46b02e"
const val infuraSecret = "fc479a9290b64a84a15fa6544a130218"
const val ethereumRpc = "https://api-dev.blocksdecoded.com/v1/ethereum-rpc/mainnet"
const val etherscanKey = "GKNHXT22ED7PRVCKZATFZQD1YI7FK9AAYE"
const val arbiscanApiKey = "Z43JN5434XVNA5D73UGPWKF26G5D9MGDPZ"
const val bscScanKey = "5ZGSHWYHZVA8XZHB8PF6UUTRNNB4KT43ZZ"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.horizontalsystems.ethereumkit.sample.modules.main.ShowTxType
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.net.URI

class AddressWatchViewModel : ViewModel() {

Expand Down Expand Up @@ -133,17 +134,7 @@ class AddressWatchViewModel : ViewModel() {
}
Chain.Ethereum -> {
transactionSource = TransactionSource.ethereumEtherscan(Configuration.etherscanKey)
rpcSource = if (Configuration.webSocket)
RpcSource.ethereumInfuraWebSocket(Configuration.infuraProjectId, Configuration.infuraSecret)
else
RpcSource.ethereumInfuraHttp(Configuration.infuraProjectId, Configuration.infuraSecret)
}
Chain.EthereumGoerli -> {
transactionSource = TransactionSource.goerliEtherscan(Configuration.etherscanKey)
rpcSource = if (Configuration.webSocket)
RpcSource.goerliInfuraWebSocket(Configuration.infuraProjectId, Configuration.infuraSecret)
else
RpcSource.goerliInfuraHttp(Configuration.infuraProjectId, Configuration.infuraSecret)
rpcSource = RpcSource.Http(listOf(URI(Configuration.ethereumRpc)), null)
}
else -> {
rpcSource = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import java.math.BigDecimal
import java.net.URI
import java.util.logging.Logger

class MainViewModel : ViewModel() {
Expand Down Expand Up @@ -198,25 +199,14 @@ class MainViewModel : ViewModel() {

Chain.Ethereum -> {
transactionSource = TransactionSource.ethereumEtherscan(Configuration.etherscanKey)
rpcSource = if (Configuration.webSocket)
RpcSource.ethereumInfuraWebSocket(Configuration.infuraProjectId, Configuration.infuraSecret)
else
RpcSource.ethereumInfuraHttp(Configuration.infuraProjectId, Configuration.infuraSecret)
rpcSource = RpcSource.Http(listOf(URI(Configuration.ethereumRpc)), null)
}

Chain.ArbitrumOne -> {
transactionSource = TransactionSource.arbiscan(Configuration.arbiscanApiKey)
rpcSource = RpcSource.arbitrumOneRpcHttp()
}

Chain.EthereumGoerli -> {
transactionSource = TransactionSource.goerliEtherscan(Configuration.etherscanKey)
rpcSource = if (Configuration.webSocket)
RpcSource.goerliInfuraWebSocket(Configuration.infuraProjectId, Configuration.infuraSecret)
else
RpcSource.goerliInfuraHttp(Configuration.infuraProjectId, Configuration.infuraSecret)
}

else -> {
throw Exception("Could not get rpcSource & transactionSource!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,6 @@ sealed class RpcSource {
data class WebSocket(val uri: URI, val auth: String?) : RpcSource()

companion object {
private fun infuraHttp(subdomain: String, projectId: String, projectSecret: String? = null): Http {
return Http(listOf(URI("https://$subdomain.infura.io/v3/$projectId")), projectSecret)
}

private fun infuraWebSocket(subdomain: String, projectId: String, projectSecret: String? = null): WebSocket {
return WebSocket(URI("https://$subdomain.infura.io/ws/v3/$projectId"), projectSecret)
}

fun ethereumInfuraHttp(projectId: String, projectSecret: String? = null): Http {
return infuraHttp("mainnet", projectId, projectSecret)
}

fun goerliInfuraHttp(projectId: String, projectSecret: String? = null): Http {
return infuraHttp("goerli", projectId, projectSecret)
}

fun ethereumInfuraWebSocket(projectId: String, projectSecret: String? = null): WebSocket {
return infuraWebSocket("mainnet", projectId, projectSecret)
}

fun goerliInfuraWebSocket(projectId: String, projectSecret: String? = null): WebSocket {
return infuraWebSocket("goerli", projectId, projectSecret)
}

fun bscRpcHttp(): Http {
return Http(listOf(URI("https://bscrpc.com")), null)
}
Expand Down

0 comments on commit 74af53b

Please sign in to comment.