Skip to content

Commit

Permalink
handle decoding protobufs with null Msg data
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Sep 29, 2022
1 parent b399c3c commit e69747e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ internal class RestClient(
suspend fun decryptDataField(msg: MsgProto, nonce: UByteArray?): UByteArray {
val dataField = when (msg) {
is MsgExecuteContractResponseProto -> {
msg.data.toUByteArray()
msg.data?.toUByteArray() ?: UByteArray(0) { 0u }
}

is MsgInstantiateContractResponseProto -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import kotlinx.serialization.protobuf.ProtoNumber
@kotlinx.serialization.Serializable
class MsgDataProto(
@ProtoNumber(1) val msgType: String = "",
@ProtoNumber(2) val data: ByteArray,
@ProtoNumber(2) val data: ByteArray? = null,
) : MsgProto() {
fun toMsgResponseType(): MsgProto = when (msgType) {
"/secret.compute.v1beta1.MsgInstantiateContract" -> {
ProtoBuf.decodeFromByteArray(data) as MsgInstantiateContractResponseProto
ProtoBuf.decodeFromByteArray(data ?: byteArrayOf()) as MsgInstantiateContractResponseProto
}

"/secret.compute.v1beta1.MsgExecuteContract" -> {
ProtoBuf.decodeFromByteArray(data) as MsgExecuteContractResponseProto
ProtoBuf.decodeFromByteArray(data ?: byteArrayOf()) as MsgExecuteContractResponseProto
}

"/secret.compute.v1beta1.MsgStoreCode" -> {
ProtoBuf.decodeFromByteArray(data) as MsgStoreCodeResponseProto
ProtoBuf.decodeFromByteArray(data ?: byteArrayOf()) as MsgStoreCodeResponseProto
}

else -> throw UnsupportedOperationException("calling toMsg() on an Any proto with typeUrl:${msgType} is not supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import kotlinx.serialization.protobuf.ProtoNumber
*/
@kotlinx.serialization.Serializable
class MsgExecuteContractResponseProto(
@ProtoNumber(1) val data: ByteArray
@ProtoNumber(1) val data: ByteArray? = null
) : MsgProto()

0 comments on commit e69747e

Please sign in to comment.