Skip to content

Commit 25e13ad

Browse files
committed
Switch Etherscan to V2
1 parent aae7f27 commit 25e13ad

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/EthereumKit.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class EthereumKit(
468468
}
469469

470470
val transactionBuilder = TransactionBuilder(address, chain.id)
471-
val transactionProvider = transactionProvider(transactionSource, address)
471+
val transactionProvider = transactionProvider(transactionSource, address, chain.id)
472472

473473
val apiDatabase = EthereumDatabaseManager.getEthereumApiDatabase(application, walletId, chain)
474474
val storage = ApiStorage(apiDatabase)
@@ -516,10 +516,10 @@ class EthereumKit(
516516
EthereumDatabaseManager.clear(context, chain, walletId)
517517
}
518518

519-
private fun transactionProvider(transactionSource: TransactionSource, address: Address): ITransactionProvider {
519+
private fun transactionProvider(transactionSource: TransactionSource, address: Address, chainId: Int): ITransactionProvider {
520520
when (transactionSource.type) {
521521
is TransactionSource.SourceType.Etherscan -> {
522-
val service = EtherscanService(transactionSource.type.apiBaseUrl, transactionSource.type.apiKeys)
522+
val service = EtherscanService(transactionSource.type.apiBaseUrl, transactionSource.type.apiKeys, chainId)
523523
return EtherscanTransactionProvider(service, address)
524524
}
525525
}

ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/models/TransactionSource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TransactionSource(val name: String, val type: SourceType) {
1515
private fun etherscan(apiSubdomain: String, txSubdomain: String?, apiKeys: List<String>): TransactionSource {
1616
return TransactionSource(
1717
"etherscan.io",
18-
SourceType.Etherscan("https://$apiSubdomain.etherscan.io", "https://${txSubdomain?.let { "$it." } ?: ""}etherscan.io", apiKeys)
18+
SourceType.Etherscan("https://$apiSubdomain.etherscan.io/v2/", "https://${txSubdomain?.let { "$it." } ?: ""}etherscan.io", apiKeys)
1919
)
2020
}
2121

ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/network/EtherscanService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import java.util.logging.Logger
2020

2121
class EtherscanService(
2222
baseUrl: String,
23-
private val apiKeys: List<String>
23+
private val apiKeys: List<String>,
24+
private val chainId: Int,
2425
) {
2526
private val apiKeysSize = apiKeys.size
2627
private var apiKeyIndex = 0
@@ -43,6 +44,7 @@ class EtherscanService(
4344

4445
val url = originalUrl.newBuilder()
4546
.addQueryParameter("apikey", getNextApiKey())
47+
.addQueryParameter("chainid", chainId.toString())
4648
.build()
4749

4850
val request = originalRequest.newBuilder()
@@ -161,7 +163,7 @@ class EtherscanService(
161163
}
162164

163165
private interface EtherscanServiceAPI {
164-
@GET("/api")
166+
@GET("api")
165167
fun accountApi(
166168
@Query("module") module: String = "account",
167169
@Query("action") action: String,

0 commit comments

Comments
 (0)