From 8b5f2b8a4e875562ae8562de487c9c4cd75cd180 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 29 Jun 2022 08:52:00 +0200 Subject: [PATCH 1/2] Fix decoding of events with no attributes --- CHANGELOG.md | 6 ++++ .../tendermint34/adaptor/responses.spec.ts | 30 +++++++++++++++++-- .../src/tendermint34/adaptor/responses.ts | 7 +++-- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e809dfde..e34e8dc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to ## [Unreleased] +### Fixed + +- @cosmjs/tendermint-rpc: Fix decoding events without attributes ([#1198]). + +[#1198]: https://github.com/cosmos/cosmjs/pull/1198 + ## [0.28.9] - 2022-06-21 This version replaces the 0.28.8 release which was erroneously tagged as 0.26.8 diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts index d00a3120..0ad26490 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.spec.ts @@ -1,9 +1,35 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { fromBase64, fromHex } from "@cosmjs/encoding"; +import { fromBase64, fromHex, toUtf8 } from "@cosmjs/encoding"; -import { decodeValidatorGenesis, decodeValidatorInfo, decodeValidatorUpdate } from "./responses"; +import { decodeEvent, decodeValidatorGenesis, decodeValidatorInfo, decodeValidatorUpdate } from "./responses"; describe("Adaptor Responses", () => { + describe("decodeEvent", () => { + it("works with attributes", () => { + // from https://rpc.mainnet-1.tgrade.confio.run/tx?hash=0x2C44715748022DB2FB5F40105383719BFCFCEE51DBC02FF4088BE3F5924CD7BF + const event = decodeEvent({ + type: "coin_spent", + attributes: [ + { key: "c3BlbmRlcg==", value: "dGdyYWRlMWpzN2V6cm01NWZxZ3h1M3A2MmQ5eG42cGF0amt1Mno3bmU1ZHZn" }, + { key: "YW1vdW50", value: "NjAwMDAwMDAwMHV0Z2Q=" }, + ], + }); + expect(event.type).toEqual("coin_spent"); + expect(event.attributes).toEqual([ + { key: toUtf8("spender"), value: toUtf8("tgrade1js7ezrm55fqgxu3p62d9xn6patjku2z7ne5dvg") }, + { key: toUtf8("amount"), value: toUtf8("6000000000utgd") }, + ]); + }); + + it("works with no attribute", () => { + const event = decodeEvent({ + type: "cosmos.module.EmittedEvent", + }); + expect(event.type).toEqual("cosmos.module.EmittedEvent"); + expect(event.attributes).toEqual([]); + }); + }); + describe("decodeValidatorGenesis", () => { it("works for genesis format", () => { // from https://raw.githubusercontent.com/cosmos/mainnet/master/genesis.json diff --git a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts index f4ac865f..e7f1eefc 100644 --- a/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts +++ b/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts @@ -111,13 +111,14 @@ function decodeAttributes(attributes: readonly RpcAttribute[]): responses.Attrib interface RpcEvent { readonly type: string; - readonly attributes: readonly RpcAttribute[]; + /** Can be omitted (see https://github.com/cosmos/cosmjs/pull/1198) */ + readonly attributes?: readonly RpcAttribute[]; } -function decodeEvent(event: RpcEvent): responses.Event { +export function decodeEvent(event: RpcEvent): responses.Event { return { type: event.type, - attributes: decodeAttributes(event.attributes), + attributes: event.attributes ? decodeAttributes(event.attributes) : [], }; } From 09f3e0ab0b5833284d5529fced8317a3f6bcbe7a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 29 Jun 2022 14:46:46 +0200 Subject: [PATCH 2/2] Set version 0.28.10 --- CHANGELOG.md | 5 ++++- packages/amino/package.json | 2 +- packages/cli/package.json | 2 +- packages/cosmwasm-stargate/package.json | 2 +- packages/crypto/package.json | 2 +- packages/encoding/package.json | 2 +- packages/faucet-client/package.json | 2 +- packages/faucet/package.json | 2 +- packages/json-rpc/package.json | 2 +- packages/ledger-amino/package.json | 2 +- packages/math/package.json | 2 +- packages/proto-signing/package.json | 2 +- packages/socket/package.json | 2 +- packages/stargate/package.json | 2 +- packages/stream/package.json | 2 +- packages/tendermint-rpc/package.json | 2 +- packages/utils/package.json | 2 +- 17 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e34e8dc3..6df5f883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to ## [Unreleased] +## [0.28.10] - 2022-06-29 + ### Fixed - @cosmjs/tendermint-rpc: Fix decoding events without attributes ([#1198]). @@ -929,7 +931,8 @@ CHANGELOG entries missing. Please see [the diff][0.24.1]. `FeeTable`. @cosmjs/cosmwasm has its own `FeeTable` with those properties. - @cosmjs/sdk38: Rename package to @cosmjs/launchpad. -[unreleased]: https://github.com/cosmos/cosmjs/compare/v0.28.9...HEAD +[unreleased]: https://github.com/cosmos/cosmjs/compare/v0.28.10...HEAD +[0.28.10]: https://github.com/cosmos/cosmjs/compare/v0.28.9...v0.28.10 [0.28.9]: https://github.com/cosmos/cosmjs/compare/v0.28.8...v0.28.9 [0.28.8]: https://github.com/cosmos/cosmjs/compare/v0.28.7...v0.28.8 [0.28.7]: https://github.com/cosmos/cosmjs/compare/v0.28.6...v0.28.7 diff --git a/packages/amino/package.json b/packages/amino/package.json index 72601b24..4571fac8 100644 --- a/packages/amino/package.json +++ b/packages/amino/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/amino", - "version": "0.28.9", + "version": "0.28.10", "description": "Helpers for Amino based signing.", "contributors": [ "Simon Warta " diff --git a/packages/cli/package.json b/packages/cli/package.json index 5267aa9c..88abce12 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/cli", - "version": "0.28.9", + "version": "0.28.10", "description": "Command line interface", "contributors": [ "IOV SAS ", diff --git a/packages/cosmwasm-stargate/package.json b/packages/cosmwasm-stargate/package.json index 40dfc05b..188d03cb 100644 --- a/packages/cosmwasm-stargate/package.json +++ b/packages/cosmwasm-stargate/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/cosmwasm-stargate", - "version": "0.28.9", + "version": "0.28.10", "description": "CosmWasm SDK", "contributors": [ "Will Clark " diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 575f07c3..9b5e6091 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/crypto", - "version": "0.28.9", + "version": "0.28.10", "description": "Cryptography resources for blockchain projects", "contributors": [ "IOV SAS ", diff --git a/packages/encoding/package.json b/packages/encoding/package.json index a57fb122..0f69d119 100644 --- a/packages/encoding/package.json +++ b/packages/encoding/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/encoding", - "version": "0.28.9", + "version": "0.28.10", "description": "Encoding helpers for blockchain projects", "contributors": [ "IOV SAS " diff --git a/packages/faucet-client/package.json b/packages/faucet-client/package.json index b0ab1a0f..09149b06 100644 --- a/packages/faucet-client/package.json +++ b/packages/faucet-client/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/faucet-client", - "version": "0.28.9", + "version": "0.28.10", "description": "The faucet client", "contributors": [ "Will Clark " diff --git a/packages/faucet/package.json b/packages/faucet/package.json index 1b4844b2..8133b624 100644 --- a/packages/faucet/package.json +++ b/packages/faucet/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/faucet", - "version": "0.28.9", + "version": "0.28.10", "description": "The faucet", "contributors": [ "Ethan Frey ", diff --git a/packages/json-rpc/package.json b/packages/json-rpc/package.json index 77ebd965..0552e601 100644 --- a/packages/json-rpc/package.json +++ b/packages/json-rpc/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/json-rpc", - "version": "0.28.9", + "version": "0.28.10", "description": "Framework for implementing a JSON-RPC 2.0 API", "contributors": [ "IOV SAS ", diff --git a/packages/ledger-amino/package.json b/packages/ledger-amino/package.json index 1e65cbee..5ebc9b07 100644 --- a/packages/ledger-amino/package.json +++ b/packages/ledger-amino/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/ledger-amino", - "version": "0.28.9", + "version": "0.28.10", "description": "A library for signing Amino-encoded transactions using Ledger devices", "contributors": [ "Will Clark " diff --git a/packages/math/package.json b/packages/math/package.json index 609c6a21..060d46ea 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/math", - "version": "0.28.9", + "version": "0.28.10", "description": "Math helpers for blockchain projects", "contributors": [ "IOV SAS " diff --git a/packages/proto-signing/package.json b/packages/proto-signing/package.json index ff0f4d2b..223d3ec2 100644 --- a/packages/proto-signing/package.json +++ b/packages/proto-signing/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/proto-signing", - "version": "0.28.9", + "version": "0.28.10", "description": "Utilities for protobuf based signing (Cosmos SDK 0.40+)", "contributors": [ "Will Clark ", diff --git a/packages/socket/package.json b/packages/socket/package.json index d57b4dc3..e5affa27 100644 --- a/packages/socket/package.json +++ b/packages/socket/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/socket", - "version": "0.28.9", + "version": "0.28.10", "description": "Utility functions for working with WebSockets", "contributors": [ "IOV SAS ", diff --git a/packages/stargate/package.json b/packages/stargate/package.json index 550f2a66..29d696ad 100644 --- a/packages/stargate/package.json +++ b/packages/stargate/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/stargate", - "version": "0.28.9", + "version": "0.28.10", "description": "Utilities for Cosmos SDK 0.40", "contributors": [ "Simon Warta " diff --git a/packages/stream/package.json b/packages/stream/package.json index 3de03e97..2de22491 100644 --- a/packages/stream/package.json +++ b/packages/stream/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/stream", - "version": "0.28.9", + "version": "0.28.10", "description": "Utility functions for producing and consuming streams", "contributors": [ "IOV SAS ", diff --git a/packages/tendermint-rpc/package.json b/packages/tendermint-rpc/package.json index 0c2be6c2..f796b408 100644 --- a/packages/tendermint-rpc/package.json +++ b/packages/tendermint-rpc/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/tendermint-rpc", - "version": "0.28.9", + "version": "0.28.10", "description": "Tendermint RPC clients", "contributors": [ "IOV SAS ", diff --git a/packages/utils/package.json b/packages/utils/package.json index 7f11e43f..343310cb 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@cosmjs/utils", - "version": "0.28.9", + "version": "0.28.10", "description": "Utility tools, primarily for testing code", "contributors": [ "IOV SAS "