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

Replace Blockchair API with BlocksDecoded proxy #646

Merged
merged 1 commit into from
Feb 27, 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 @@ -260,7 +260,7 @@ class BitcoinCashKit : AbstractKit {
is NetworkType.MainNet -> {

if (syncMode is SyncMode.Blockchair) {
val blockchairApi = BlockchairApi(syncMode.key, network.blockchairChainId)
val blockchairApi = BlockchairApi(network.blockchairChainId)
val blockchairBlockHashFetcher = BlockchairBlockHashFetcher(blockchairApi)
val blockHashFetcher = BlockHashFetcher(hsBlockHashFetcher, blockchairBlockHashFetcher, checkpoint.block.height)
val blockchairProvider = BlockchairTransactionProvider(blockchairApi, blockHashFetcher)
Expand Down Expand Up @@ -305,7 +305,7 @@ class BitcoinCashKit : AbstractKit {
"BitcoinCash-${networkType.description}-$walletId-${syncMode.javaClass.simpleName}"

fun clear(context: Context, networkType: NetworkType, walletId: String) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair(""))) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair())) {
try {
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseName(networkType, walletId, syncMode)))
} catch (ex: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class BitcoinCore(
sealed class SyncMode {
class Full : SyncMode()
class Api : SyncMode()
class Blockchair(val key: String) : SyncMode()
class Blockchair : SyncMode()
}

sealed class StateError : Exception() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class BitcoinCoreBuilder {
val blockchairApi = if (apiTransactionProvider is BlockchairTransactionProvider) {
apiTransactionProvider.blockchairApi
} else {
BlockchairApi(syncMode.key, network.blockchairChainId)
BlockchairApi(network.blockchairChainId)
}
val lastBlockProvider = BlockchairLastBlockProvider(blockchairApi)
apiSyncer = BlockchairApiSyncer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import java.util.Locale
import java.util.TimeZone

class BlockchairApi(
private val secretKey: String,
private val chainId: String,
) {
private val apiManager = ApiManager("https://api.blockchair.com")
private val apiManager = ApiManager("https://api.blocksdecoded.com/v1/blockchair")
private val limit = 10000
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())

Expand Down Expand Up @@ -64,7 +63,7 @@ class BlockchairApi(
}

fun lastBlockHeader(): BlockHeaderItem {
val params = "?limit=0&key=$secretKey"
val params = "?limit=0"
val url = "$chainId/stats"
val response = apiManager.doOkHttpGet(url + params).asObject()
val data = response.get("data").asObject()
Expand All @@ -84,7 +83,7 @@ class BlockchairApi(
receivedTransactionItems: List<Transaction> = emptyList()
): Pair<List<AddressItem>, List<Transaction>> {
try {
val params = "?transaction_details=true&limit=$limit,0&offset=${receivedTransactionItems.size}&key=$secretKey"
val params = "?transaction_details=true&limit=$limit,0&offset=${receivedTransactionItems.size}"
val url = "$chainId/dashboards/addresses/${addresses.joinToString(separator = ",")}"
val response = apiManager.doOkHttpGet(url + params).asObject()
val data = response.get("data").asObject()
Expand Down Expand Up @@ -134,7 +133,7 @@ class BlockchairApi(

private fun fetchBlockHashes(heights: List<Int>): Map<Int, String> {
try {
val params = "?limit=0&key=$secretKey"
val params = "?limit=0"
val url = "$chainId/dashboards/blocks/${heights.joinToString(separator = ",")}"
val response = apiManager.doOkHttpGet(url + params).asObject()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class BitcoinKit : AbstractKit {
NetworkType.MainNet -> {
val hsBlockHashFetcher = HsBlockHashFetcher("https://api.blocksdecoded.com/v1/blockchains/bitcoin")
if (syncMode is SyncMode.Blockchair) {
val blockchairApi = BlockchairApi(syncMode.key, network.blockchairChainId)
val blockchairApi = BlockchairApi(network.blockchairChainId)
val blockchairBlockHashFetcher = BlockchairBlockHashFetcher(blockchairApi)
val blockHashFetcher = BlockHashFetcher(hsBlockHashFetcher, blockchairBlockHashFetcher, checkpoint.block.height)
val blockchairProvider = BlockchairTransactionProvider(blockchairApi, blockHashFetcher)
Expand Down Expand Up @@ -367,7 +367,7 @@ class BitcoinKit : AbstractKit {
* @param walletId The string wallet ID of the BitcoinKit.
*/
fun clear(context: Context, networkType: NetworkType, walletId: String) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair(""))) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair())) {
for (purpose in Purpose.values()) try {
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseName(networkType, walletId, syncMode, purpose)))
} catch (ex: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class DashKit : AbstractKit, IInstantTransactionDelegate, BitcoinCore.Listener {
val insightApiProvider = InsightApi("https://insight.dash.org/insight-api")

if (syncMode is SyncMode.Blockchair) {
val blockchairApi = BlockchairApi(syncMode.key, network.blockchairChainId)
val blockchairApi = BlockchairApi(network.blockchairChainId)
val blockchairBlockHashFetcher = BlockchairBlockHashFetcher(blockchairApi)
val blockchairProvider = BlockchairTransactionProvider(blockchairApi, blockchairBlockHashFetcher)

Expand Down Expand Up @@ -384,7 +384,7 @@ class DashKit : AbstractKit, IInstantTransactionDelegate, BitcoinCore.Listener {
}

fun clear(context: Context, networkType: NetworkType, walletId: String) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair(""))) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair())) {
try {
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseNameCore(networkType, walletId, syncMode)))
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseName(networkType, walletId, syncMode)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class ECashKit : AbstractKit {
NetworkType.MainNet -> {
val chronikApiProvider = ChronikApi()
if (syncMode is SyncMode.Blockchair) {
val blockchairApi = BlockchairApi(syncMode.key, network.blockchairChainId)
val blockchairApi = BlockchairApi(network.blockchairChainId)
val blockchairBlockHashFetcher = BlockchairBlockHashFetcher(blockchairApi)
val blockchairProvider = BlockchairTransactionProvider(blockchairApi, blockchairBlockHashFetcher)

Expand Down Expand Up @@ -280,7 +280,7 @@ class ECashKit : AbstractKit {
"ECash-${networkType.name}-$walletId-${syncMode.javaClass.simpleName}"

fun clear(context: Context, networkType: NetworkType, walletId: String) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair(""))) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair())) {
try {
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseName(networkType, walletId, syncMode)))
} catch (ex: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class LitecoinKit : AbstractKit {
val bCoinApiProvider = BCoinApi("https://ltc.blocksdecoded.com/api")

if (syncMode is SyncMode.Blockchair) {
val blockchairApi = BlockchairApi(syncMode.key, network.blockchairChainId)
val blockchairApi = BlockchairApi(network.blockchairChainId)
val blockchairBlockHashFetcher = BlockchairBlockHashFetcher(blockchairApi)
val blockchairProvider = BlockchairTransactionProvider(blockchairApi, blockchairBlockHashFetcher)

Expand Down Expand Up @@ -301,7 +301,7 @@ class LitecoinKit : AbstractKit {
"Litecoin-${networkType.name}-$walletId-${syncMode.javaClass.simpleName}-${purpose.name}"

fun clear(context: Context, networkType: NetworkType, walletId: String) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair(""))) {
for (syncMode in listOf(SyncMode.Api(), SyncMode.Full(), SyncMode.Blockchair())) {
for (purpose in Purpose.values())
try {
SQLiteDatabase.deleteDatabase(context.getDatabasePath(getDatabaseName(networkType, walletId, syncMode, purpose)))
Expand Down
Loading