Skip to content

Commit

Permalink
Update API sync mode to Blockchair API for BTC and BCH.
Browse files Browse the repository at this point in the history
  • Loading branch information
omurovch committed Nov 15, 2023
1 parent 4b57adb commit d82ff86
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ android {
resValue "string", "trongridApiKey", "33374494-8060-447e-8367-90c5efd4ed95"
resValue "string", "udnApiKey", "r2phzgatt_zt9-hd_wyvdjrdsrimnxgokm7knyag1malzgcz"
resValue "string", "oneInchApiKey", "ElyK7s22HR0JD78CEXVPnpZA8UyuUwIl"
resValue "string", "blockchairApiKey", "M___unstoppn7jfFpe40X___________"
}

appcenterdebug {
Expand Down Expand Up @@ -135,6 +136,7 @@ android {
resValue "string", "trongridApiKey", "8f5ae2c8-8012-42a8-b0ca-ffc2741f6a29"
resValue "string", "udnApiKey", "r2phzgatt_zt9-hd_wyvdjrdsrimnxgokm7knyag1malzgcz"
resValue "string", "oneInchApiKey", "ElyK7s22HR0JD78CEXVPnpZA8UyuUwIl"
resValue "string", "blockchairApiKey", "M___unstoppn7jfFpe40X___________"
}

appcenterrelease {
Expand Down Expand Up @@ -270,7 +272,7 @@ dependencies {
debugImplementation leakCanary

// Wallet kits
implementation 'com.github.horizontalsystems:bitcoin-kit-android:8e990e3'
implementation 'com.github.horizontalsystems:bitcoin-kit-android:2bd239f'
implementation 'com.github.horizontalsystems:ethereum-kit-android:94bb971'
implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49'
implementation 'com.github.horizontalsystems:binance-chain-kit-android:7e4d7c0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
evmSyncSourceStorage = EvmSyncSourceStorage(appDatabase)
evmSyncSourceManager = EvmSyncSourceManager(appConfigProvider, blockchainSettingsStorage, evmSyncSourceStorage)

btcBlockchainManager = BtcBlockchainManager(blockchainSettingsStorage, marketKit)
btcBlockchainManager = BtcBlockchainManager(blockchainSettingsStorage, appConfigProvider, marketKit)

binanceKitManager = BinanceKitManager()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.horizontalsystems.bankwallet.core.managers

import io.horizontalsystems.bankwallet.core.providers.AppConfigProvider
import io.horizontalsystems.bankwallet.core.storage.BlockchainSettingsStorage
import io.horizontalsystems.bankwallet.entities.AccountOrigin
import io.horizontalsystems.bankwallet.entities.BtcRestoreMode
import io.horizontalsystems.bankwallet.entities.TransactionDataSortMode
import io.horizontalsystems.bitcoincore.BitcoinCore
import io.horizontalsystems.bitcoincore.BitcoinCore.SyncMode
import io.horizontalsystems.marketkit.models.BlockchainType
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject

class BtcBlockchainManager(
private val storage: BlockchainSettingsStorage,
marketKit: MarketKitWrapper
private val appConfigProvider: AppConfigProvider,
marketKit: MarketKitWrapper,
) {

private val restoreModeUpdatedSubject = PublishSubject.create<BlockchainType>()
Expand All @@ -38,14 +40,21 @@ class BtcBlockchainManager(
return storage.btcRestoreMode(blockchainType) ?: BtcRestoreMode.Api
}

fun syncMode(blockchainType: BlockchainType, accountOrigin: AccountOrigin): BitcoinCore.SyncMode {
private fun apiSyncMode(blockchainType: BlockchainType) = when (blockchainType) {
BlockchainType.Bitcoin,
BlockchainType.BitcoinCash -> SyncMode.Blockchair(appConfigProvider.blockchairApiKey)

else -> SyncMode.Api()
}

fun syncMode(blockchainType: BlockchainType, accountOrigin: AccountOrigin): SyncMode {
if (accountOrigin == AccountOrigin.Created) {
return BitcoinCore.SyncMode.NewWallet()
return apiSyncMode(blockchainType)
}

return when (restoreMode(blockchainType)) {
BtcRestoreMode.Api -> BitcoinCore.SyncMode.Api()
BtcRestoreMode.Blockchain -> BitcoinCore.SyncMode.Full()
BtcRestoreMode.Api -> apiSyncMode(blockchainType)
BtcRestoreMode.Blockchain -> SyncMode.Full()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class AppConfigProvider(localStorage: ILocalStorage) {
Translator.getString(R.string.oneInchApiKey)
}

val blockchairApiKey by lazy {
Translator.getString(R.string.blockchairApiKey)
}

val fiatDecimal: Int = 2
val feeRateAdjustForCurrencies: List<String> = listOf("USD", "EUR")

Expand Down

0 comments on commit d82ff86

Please sign in to comment.