Skip to content

Commit

Permalink
refactor TxsResponse -> TxResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Sep 29, 2022
1 parent 71bd6b2 commit b399c3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +91,7 @@ private constructor(
suspend fun execute(
msgs: List<Msg<*>>,
txOptions: TxOptions = TxOptions(),
): ExecuteResult {
): TxResponseData {
val txRawProto = prepareAndSign(msgs, txOptions)
val txRawBytes = ProtoBuf.encodeToByteArray(txRawProto).toUByteArray()
val txResponse = try {
Expand Down Expand Up @@ -124,7 +123,7 @@ private constructor(

throw err
}
val data: List<String> = 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())
Expand All @@ -133,12 +132,7 @@ private constructor(
emptyList()
}


return ExecuteResult(
logs = txResponse.logs,
transactionHash = txResponse.txhash,
data = data
)
return txResponse
}

private suspend fun prepareAndSign(
Expand Down Expand Up @@ -362,7 +356,7 @@ private constructor(
return ProtoBuf.encodeToByteArray(txBodyEncoded)
}

private suspend fun decodeTxResponses(postTxResult: TxsResponseData): List<String> {
private suspend fun decodeTxResponses(postTxResult: TxResponseData): List<String> {
val nonces = mutableMapOf<Int, UByteArray?>()
val txRaw: TxRawProto = ProtoBuf.decodeFromByteArray(postTxResult.tx!!.value)
val txBody: TxBodyProto = ProtoBuf.decodeFromByteArray(txRaw.bodyBytes)
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit b399c3c

Please sign in to comment.