From b399c3c37413ab6bd8c53f39772b6d1649f75b61 Mon Sep 17 00:00:00 2001 From: Luca Spinazzola Date: Thu, 29 Sep 2022 16:34:25 -0400 Subject: [PATCH] refactor TxsResponse -> TxResponse --- .../io/eqoty/secretk/client/CosmWasmClient.kt | 4 ++-- .../secretk/client/SigningCosmWasmClient.kt | 17 +++++------------ .../secretk/types/response/TxResponseData.kt | 6 +++--- 3 files changed, 10 insertions(+), 17 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 a3ff5c9..6c8cc38 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/CosmWasmClient.kt @@ -70,8 +70,8 @@ open class CosmWasmClient protected constructor( } } - suspend fun postTx(tx: UByteArray): TxsResponseData { - val response: TxsResponse = restClient.postTx(tx, false) + suspend fun postTx(tx: UByteArray): TxResponseData { + val response: TxResponse = restClient.postTx(tx, false) val txResponse = response.tx_response if (txResponse.txhash.isBlank()) { throw Error("Unexpected response data format") 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 a16f05a..86ade4b 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/client/SigningCosmWasmClient.kt @@ -5,7 +5,6 @@ import io.eqoty.secretk.BroadcastMode import io.eqoty.secretk.types.* import io.eqoty.secretk.types.proto.* import io.eqoty.secretk.types.response.* -import io.eqoty.secretk.types.result.ExecuteResult import io.eqoty.secretk.utils.EncryptionUtils import io.eqoty.secretk.utils.EnigmaUtils import io.eqoty.secretk.utils.decodeToString @@ -92,7 +91,7 @@ private constructor( suspend fun execute( msgs: List>, txOptions: TxOptions = TxOptions(), - ): ExecuteResult { + ): TxResponseData { val txRawProto = prepareAndSign(msgs, txOptions) val txRawBytes = ProtoBuf.encodeToByteArray(txRawProto).toUByteArray() val txResponse = try { @@ -124,7 +123,7 @@ private constructor( throw err } - val data: List = if (this.restClient.broadcastMode == BroadcastMode.Block) { + txResponse.data = if (this.restClient.broadcastMode == BroadcastMode.Block) { // inject tx here to standardize decoding tx responses. Since txsQuery responses (not implemented yet) // will actually have a tx value populated. txResponse.tx = AnyProto(value = txRawBytes.toByteArray()) @@ -133,12 +132,7 @@ private constructor( emptyList() } - - return ExecuteResult( - logs = txResponse.logs, - transactionHash = txResponse.txhash, - data = data - ) + return txResponse } private suspend fun prepareAndSign( @@ -362,7 +356,7 @@ private constructor( return ProtoBuf.encodeToByteArray(txBodyEncoded) } - private suspend fun decodeTxResponses(postTxResult: TxsResponseData): List { + private suspend fun decodeTxResponses(postTxResult: TxResponseData): List { val nonces = mutableMapOf() val txRaw: TxRawProto = ProtoBuf.decodeFromByteArray(postTxResult.tx!!.value) val txBody: TxBodyProto = ProtoBuf.decodeFromByteArray(txRaw.bodyBytes) @@ -371,8 +365,7 @@ private constructor( msgs.forEachIndexed { i, anyProto -> nonces[i] = extractMessageNonceIfNeeded(anyProto) } - - val txMsgData: TxMsgDataProto = ProtoBuf.decodeFromByteArray(postTxResult.data.decodeHex().toByteArray()) + val txMsgData: TxMsgDataProto = ProtoBuf.decodeFromByteArray(postTxResult.rawData.decodeHex().toByteArray()) val dataFields = txMsgData.data val data = dataFields.mapIndexed { i, msgDataProto -> val msgTyped: MsgProto = msgDataProto.toMsgResponseType() diff --git a/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/response/TxResponseData.kt b/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/response/TxResponseData.kt index c0efa72..9d2a808 100644 --- a/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/response/TxResponseData.kt +++ b/secretk/src/commonMain/kotlin/io/eqoty/secretk/types/response/TxResponseData.kt @@ -6,12 +6,12 @@ import io.eqoty.secretk.types.response.logs.Log import kotlinx.serialization.SerialName @kotlinx.serialization.Serializable -data class TxsResponse( - val tx_response: TxsResponseData, +data class TxResponse( + val tx_response: TxResponseData, ) @kotlinx.serialization.Serializable -data class TxsResponseData( +data class TxResponseData( /** The block height */ val height: String, /** The transaction hash. */