From d39bb1c424fe5c4fffd10cb062d352271c408baa Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Fri, 30 Sep 2022 00:29:20 -0400 Subject: [PATCH] add ability to pass in chainId instead of making a rest call to get it log a warning if chainId isn't passed in (as it makes execution slower) --- .../io/eqoty/secretk/client/CosmWasmClient.kt | 4 ++-- .../secretk/client/SigningCosmWasmClient.kt | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt index cc403d7..a85e832 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt @@ -10,13 +10,13 @@ import kotlinx.serialization.json.jsonObject open class CosmWasmClient protected constructor( apiUrl: String, encryptionUtils: EncryptionUtils, - broadcastMode: BroadcastMode = BroadcastMode.Block + broadcastMode: BroadcastMode = BroadcastMode.Block, + private var chainId: String? = null ) { internal val restClient = RestClient(apiUrl, broadcastMode, encryptionUtils) /** Any address the chain considers valid (valid bech32 with proper prefix) */ protected var anyValidAddress: String? = null - private var chainId: String? = null suspend fun getCodeInfoByCodeId(codeId: String): CodeInfoResponse.CodeInfo = restClient.getCodeInfoByCodeId(codeId) diff --git a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt index 50e3179..af91c20 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt @@ -1,5 +1,6 @@ package io.eqoty.secretk.client +import co.touchlab.kermit.Logger import com.ionspin.kotlin.bignum.integer.toBigInteger import io.eqoty.secretk.BroadcastMode import io.eqoty.secretk.types.* @@ -17,14 +18,24 @@ import okio.ByteString.Companion.decodeBase64 import okio.ByteString.Companion.decodeHex import kotlin.math.ceil -class SigningCosmWasmClient//| OfflineSigner +class SigningCosmWasmClient private constructor( val apiUrl: String, val senderAddress: String, val wallet: Wallet, encryptionUtils: EncryptionUtils, - broadcastMode: BroadcastMode = BroadcastMode.Block -) : CosmWasmClient(apiUrl, encryptionUtils, broadcastMode) { + broadcastMode: BroadcastMode = BroadcastMode.Block, + chainId: String? = null +) : CosmWasmClient(apiUrl, encryptionUtils, broadcastMode, chainId) { + + init { + if (chainId.isNullOrBlank()) { + Logger.w( + "SigningCosmWasmClient was created without the \"chainId\" parameter. This is discouraged " + + "and will result in slower execution times for your app." + ) + } + } private fun encodePubkey( pubkey: PubKey,