diff --git a/app/build.gradle b/app/build.gradle index 3813ecb..df6579e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -157,7 +157,7 @@ dependencies { implementation files('lib/AF-Android-SDK.jar') // Room - def room_version = '2.4.1' + def room_version = '2.4.2' implementation "androidx.room:room-runtime:$room_version" implementation "androidx.room:room-ktx:$room_version" implementation "androidx.room:room-rxjava2:$room_version" @@ -234,7 +234,7 @@ dependencies { implementation "com.github.WalletConnect:WalletConnectKotlinV2:1.0.0-beta04" // Unstoppable Domains - implementation 'com.unstoppabledomains:resolution:4.0.0' + implementation 'com.github.unstoppabledomains:resolution-java:6.1.0' // in case native file tor.so not loading, do full gradle clean and build. implementation 'com.github.horizontalsystems:tor-kit-android:6c775c1' diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/address/IAddressHandler.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/address/IAddressHandler.kt index 28100ae..2c2f332 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/address/IAddressHandler.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/address/IAddressHandler.kt @@ -1,9 +1,9 @@ package io.horizontalsystems.bankwallet.modules.address - -import com.unstoppabledomains.resolution.Resolution import io.horizontalsystems.bankwallet.entities.Address import io.horizontalsystems.ethereumkit.core.AddressValidator import io.horizontalsystems.marketkit2.models.CoinType +import com.unstoppabledomains.resolution.Resolution +import java.net.URL interface IAddressHandler { fun isSupported(value: String): Boolean @@ -12,67 +12,73 @@ interface IAddressHandler { class AddressHandlerUdn(private val coinType: CoinType, private val coinCode: String) : IAddressHandler { private val resolution = Resolution() - private val chain by lazy { chain(coinType) } - private val chainCoinCode by lazy { chainCoinCode(coinType) } + private val currencyVersion by lazy { version(coinType, coinCode) } override fun isSupported(value: String): Boolean { return value.contains(".") && resolution.isSupported(value) } override fun parseAddress(value: String): Address { - return Address(resolveAddress(value), value) + return if (currencyVersion != ""){ + Address(resolveMultiChain(value, coinCode, currencyVersion), value) + }else { + Address(resolveSingleChain(value, coinCode), value) + } } - private fun resolveAddress(value: String): String { - val fetchers = mutableListOf<() -> String?>() - fetchers.add { - chain?.let { resolution.getMultiChainAddress(value, coinCode, it) } - } - fetchers.add { - resolution.getAddress(value, coinCode) - } - fetchers.add { - chainCoinCode?.let { resolution.getAddress(value, it) } + private fun resolveMultiChain(domain: String, currency: String, version: String): String { + val resolvedAddress: String + try{ + resolvedAddress = resolution.getMultiChainAddress(domain, currency, version) + return resolvedAddress + }catch(e: Exception){ + throw Exception("Unstoppable Domains - Resolution Error: $e") } + } - var lastError: Exception? = null - for (fetcher in fetchers) { - try { - fetcher.invoke()?.let { resolvedAddress -> - return resolvedAddress - } - } catch (e: Exception) { - lastError = e - } + private fun resolveSingleChain(domain: String, currency: String): String { + val resolvedAddress: String + if (currency == "BNB"){ + return resolveMultiChain(domain, currency, "BEP20") + } + try{ + resolvedAddress = resolution.getAddress(domain, currency) + return resolvedAddress + }catch(e: Exception){ + throw Exception("Unstoppable Domains - Resolution Error: $e") } - - throw lastError!! } companion object { - private fun chainCoinCode(coinType: CoinType) = when (coinType) { - is CoinType.Ethereum, - is CoinType.Erc20, - is CoinType.BinanceSmartChain, - is CoinType.Bep20, - is CoinType.Polygon, - is CoinType.Mrc20 -> "ETH" -// is CoinType.EthereumOptimism -> "ETH" -// is CoinType.OptimismErc20 -> "ETH" -// is CoinType.EthereumArbitrumOne -> "ETH" -// is CoinType.ArbitrumOneErc20 -> "ETH" - else -> null - } - - private fun chain(coinType: CoinType) = when (coinType) { - is CoinType.Erc20 -> "ERC20" - is CoinType.Bep20 -> "BEP20" - is CoinType.Polygon, - is CoinType.Mrc20 -> "MATIC" - else -> null + private fun version(coinType: CoinType, coinCode: String): String { + val url = "https://unstoppabledomains.com/api/uns-resolver-keys" + val expectedVersion = coinType.toString().split("|")[0].uppercase() + val supportedCurrencies: MutableList = ArrayList() + var version = "" + try{ + val jsonString = URL(url).readText() + val keys = jsonString.split("keys\":{\"crypto.")[1].split("crypto.") + for (key in keys) { + val currency = key.split("\":{\"deprecated") + supportedCurrencies.add(currency[0]) + } + }catch(e: Exception){ + throw Exception("Unstoppable Domains - API Error: $e") + } + for (currency in supportedCurrencies) { + if(currency.startsWith(coinCode)){ + if(currency.contains(expectedVersion)){ + version = expectedVersion + } + } + } + if (expectedVersion.contains("[0-9]".toRegex()) && version != expectedVersion) { + throw Exception("Unstoppable Domains - Unsupported Currency Version: $expectedVersion") + } else { + return version + } } } - } class AddressHandlerEvm : IAddressHandler { diff --git a/marketkit2/build.gradle b/marketkit2/build.gradle index 225042c..7ce7bad 100644 --- a/marketkit2/build.gradle +++ b/marketkit2/build.gradle @@ -43,7 +43,7 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' //Room - def room_version = '2.3.0' + def room_version = '2.4.2' implementation "androidx.room:room-runtime:$room_version" implementation "androidx.room:room-rxjava2:$room_version" kapt "androidx.room:room-compiler:$room_version"