Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Infura options from RpcSource #308

Merged
merged 1 commit into from
Mar 13, 2024
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
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
Loading