diff --git a/CHANGELOG.md b/CHANGELOG.md index ba5791f16b..69dfbbce0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to - @cosmjs/tendermint-rpc: Fix decoding validator updates due to slashing ([#1177]). - @cosmjs/math: Check for negative values in `Decimal.fromAtomics` ([#1188]). +- @cosmjs/tendermint-rpc: Fix `key` and `value` type in `RpcAbciQueryResponse` + to also include the `null` option. [#1170]: https://github.com/cosmos/cosmjs/issues/1170 [#1177]: https://github.com/cosmos/cosmjs/issues/1177 diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index e292e802ac..93d3214f8c 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -68,10 +68,20 @@ function decodeQueryProof(data: RpcQueryProof): responses.QueryProof { } interface RpcAbciQueryResponse { - /** base64 encoded */ - readonly key: string; - /** base64 encoded */ - readonly value?: string; + /** + * Base64 encoded + * + * This can be null since this iy a byte slice and due to + * https://github.com/tendermint/tendermint/blob/v0.34.19/abci/types/result.go#L50 + */ + readonly key?: string | null; + /** + * Base64 encoded + * + * This can be null since this is a byte slice and due to + * https://github.com/tendermint/tendermint/blob/v0.34.19/abci/types/result.go#L50 + */ + readonly value?: string | null; readonly proofOps?: RpcQueryProof | null; readonly height?: string; /** An integer; can be negative */ @@ -84,8 +94,8 @@ interface RpcAbciQueryResponse { function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryResponse { return { - key: fromBase64(optional(data.key, "")), - value: fromBase64(optional(data.value, "")), + key: fromBase64(assertString(data.key ?? "")), + value: fromBase64(assertString(data.value ?? "")), proof: may(decodeQueryProof, data.proofOps), height: may(Integer.parse, data.height), code: may(Integer.parse, data.code), diff --git a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts index d0da2ce50f..dcc07eadf4 100644 --- a/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint35/adaptor/responses.ts @@ -68,10 +68,20 @@ function decodeQueryProof(data: RpcQueryProof): responses.QueryProof { } interface RpcAbciQueryResponse { - /** base64 encoded */ - readonly key: string; - /** base64 encoded */ - readonly value?: string; + /** + * Base64 encoded + * + * This can be null since this is a byte slice and due to + * https://github.com/tendermint/tendermint/blob/v0.35.7/abci/types/result.go#L53 + */ + readonly key?: string | null; + /** + * Base64 encoded + * + * This can be null since this is a byte slice and due to + * https://github.com/tendermint/tendermint/blob/v0.35.7/abci/types/result.go#L53 + */ + readonly value?: string | null; readonly proofOps?: RpcQueryProof | null; readonly height?: string; readonly index?: string; @@ -83,8 +93,8 @@ interface RpcAbciQueryResponse { function decodeAbciQuery(data: RpcAbciQueryResponse): responses.AbciQueryResponse { return { - key: fromBase64(optional(data.key, "")), - value: fromBase64(optional(data.value, "")), + key: fromBase64(assertString(data.key ?? "")), + value: fromBase64(assertString(data.value ?? "")), proof: may(decodeQueryProof, data.proofOps), height: may(Integer.parse, data.height), code: may(Integer.parse, data.code),