Updated on 2026-08-14
This commit is contained in:
parent
9c5490bced
commit
c211d221ea
14 changed files with 251 additions and 113 deletions
|
|
@ -3,8 +3,8 @@ package com.tangem.lib.visa
|
|||
import com.ihsanbal.logging.Level
|
||||
import com.ihsanbal.logging.LoggingInterceptor
|
||||
import com.tangem.lib.visa.model.VisaContractInfo
|
||||
import com.tangem.lib.visa.utils.VisaConfig
|
||||
import com.tangem.lib.visa.utils.VisaConfig.NETWORK_LOGS_TAG
|
||||
import com.tangem.lib.visa.utils.Constants
|
||||
import com.tangem.lib.visa.utils.Constants.NETWORK_LOGS_TAG
|
||||
import com.tangem.lib.visa.utils.toHexString
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import okhttp3.OkHttpClient
|
||||
|
|
@ -24,16 +24,16 @@ interface VisaContractInfoProvider {
|
|||
suspend fun getContractInfo(walletAddress: String): VisaContractInfo
|
||||
|
||||
class Builder(
|
||||
private val useTestnetRpc: Boolean,
|
||||
private val bridgeProcessorAddress: String,
|
||||
private val paymentAccountRegistryAddress: String,
|
||||
private val isNetworkLoggingEnabled: Boolean,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val baseUrl: String = VisaConfig.BASE_RPC_URL,
|
||||
private val bridgeProcessorAddress: String = VisaConfig.BRIDGE_PROCESSOR_CONTRACT_ADDRESS,
|
||||
private val paymentAccountRegistryAddress: String = VisaConfig.PAYMENT_ACCOUNT_REGISTRY_ADDRESS,
|
||||
private val chainId: Long = VisaConfig.CHAIN_ID,
|
||||
private val networkTimeoutSeconds: Long = VisaConfig.NETWORK_TIMEOUT_SECONDS,
|
||||
private val decimals: Int = VisaConfig.DECIMALS,
|
||||
private val gasLimit: Long = VisaConfig.GAS_LIMIT,
|
||||
private val privateKey: String = ByteArray(VisaConfig.PRIVATE_KEY_LENGTH).toHexString(),
|
||||
private val chainId: Long = Constants.CHAIN_ID,
|
||||
private val decimals: Int = Constants.DECIMALS,
|
||||
private val gasLimit: Long = Constants.GAS_LIMIT,
|
||||
private val networkTimeoutSeconds: Long = Constants.NETWORK_TIMEOUT_SECONDS,
|
||||
private val privateKey: String = ByteArray(Constants.PRIVATE_KEY_LENGTH).toHexString(),
|
||||
) {
|
||||
|
||||
fun build(): VisaContractInfoProvider {
|
||||
|
|
@ -52,6 +52,8 @@ interface VisaContractInfoProvider {
|
|||
}
|
||||
|
||||
private fun createWeb3J(): Web3j {
|
||||
val baseUrl: String = if (useTestnetRpc) Constants.TESTNET_RPC_URL else Constants.MAINNET_RPC_URL
|
||||
|
||||
val httpClient = OkHttpClient.Builder().apply {
|
||||
connectTimeout(networkTimeoutSeconds, TimeUnit.SECONDS)
|
||||
readTimeout(networkTimeoutSeconds, TimeUnit.SECONDS)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import com.ihsanbal.logging.Level
|
|||
import com.ihsanbal.logging.LoggingInterceptor
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.datasource.api.common.response.ApiResponseCallAdapterFactory
|
||||
import com.tangem.lib.visa.utils.VisaConfig
|
||||
import com.tangem.lib.visa.utils.VisaConfig.NETWORK_LOGS_TAG
|
||||
import com.tangem.lib.visa.utils.Constants
|
||||
import com.tangem.lib.visa.utils.Constants.NETWORK_LOGS_TAG
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
|
|
@ -17,7 +17,8 @@ class VisaApiBuilder(
|
|||
private val useDevApi: Boolean,
|
||||
private val isNetworkLoggingEnabled: Boolean,
|
||||
private val moshi: Moshi,
|
||||
private val networkTimeoutSeconds: Long = VisaConfig.NETWORK_TIMEOUT_SECONDS,
|
||||
private val headers: Map<String, String>,
|
||||
private val networkTimeoutSeconds: Long = Constants.NETWORK_TIMEOUT_SECONDS,
|
||||
) {
|
||||
|
||||
fun build(): VisaApi {
|
||||
|
|
@ -35,13 +36,23 @@ class VisaApiBuilder(
|
|||
if (isNetworkLoggingEnabled) {
|
||||
addInterceptor(createNetworkLoggingInterceptor())
|
||||
}
|
||||
|
||||
if (headers.isNotEmpty()) {
|
||||
addInterceptor { chain ->
|
||||
val request = chain.request().newBuilder().apply {
|
||||
headers.forEach { (key, value) -> addHeader(key, value) }
|
||||
}.build()
|
||||
|
||||
chain.proceed(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private fun createRetrofit(okHttpClient: OkHttpClient): Retrofit {
|
||||
val baseUrl = if (useDevApi) VisaConfig.VISA_API_DEV_URL else VisaConfig.VISA_API_PROD_URL
|
||||
val baseUrl = if (useDevApi) Constants.VISA_API_DEV_URL else Constants.VISA_API_PROD_URL
|
||||
|
||||
return Retrofit.Builder()
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.tangem.lib.visa.utils
|
||||
|
||||
internal object VisaConfig {
|
||||
internal object Constants {
|
||||
|
||||
const val MAINNET_RPC_URL = "https://polygon-rpc.com/"
|
||||
const val TESTNET_RPC_URL = "https://rpc-amoy.polygon.technology/"
|
||||
|
||||
const val BASE_RPC_URL = "https://polygon-mumbai.g.alchemy.com/v2/_1qqjXgBC_IikaXChnna8KTcV2eMMIQG/"
|
||||
const val BRIDGE_PROCESSOR_CONTRACT_ADDRESS = "0xe32ecbbc1ec17fa9c160569cd613ad568ca50279"
|
||||
const val PAYMENT_ACCOUNT_REGISTRY_ADDRESS = "0x3f4ae01073d1a9d5a92315fe118e57d1cdec7c44"
|
||||
const val CHAIN_ID = 80_001L
|
||||
const val DECIMALS = 9
|
||||
const val GAS_LIMIT = 500_000_000L
|
||||
Loading…
Add table
Add a link
Reference in a new issue