From 3daa7b6c4aa6be09c593d6b4fc8e82681cc98e0f Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 2 Mar 2023 14:10:52 +0100 Subject: [PATCH] Rename `fromTendermint34Event` to `fromTendermintEvent` and let it support both Tendermint 0.34 and 0.37 events as input --- CHANGELOG.md | 2 ++ packages/cosmwasm-stargate/src/cosmwasmclient.ts | 4 ++-- packages/stargate/src/events.ts | 10 +++++----- packages/stargate/src/index.ts | 2 +- packages/stargate/src/stargateclient.ts | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3596ebde..c5d0b2f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to - @cosmjs/proto-signing: Remove `fromJSON`/`toJSON` from `TsProtoGeneratedType` such that generated types are not required to generate those anymore. The methods were provided by ts-proto but we never needed them. ([#1329]) +- @cosmjs/stargate: Rename `fromTendermint34Event` to `fromTendermintEvent` and + let it support both Tendermint 0.34 and 0.37 events as input. [#1002]: https://github.com/cosmos/cosmjs/issues/1002 [#1240]: https://github.com/cosmos/cosmjs/pull/1240 diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.ts index ab357d9a..158d3eab 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.ts @@ -10,7 +10,7 @@ import { BroadcastTxError, Coin, DeliverTxResponse, - fromTendermint34Event, + fromTendermintEvent, IndexedTx, isSearchByHeightQuery, isSearchBySentFromOrToQuery, @@ -464,7 +464,7 @@ export class CosmWasmClient { height: tx.height, hash: toHex(tx.hash).toUpperCase(), code: tx.result.code, - events: tx.result.events.map(fromTendermint34Event), + events: tx.result.events.map(fromTendermintEvent), rawLog: tx.result.log || "", tx: tx.tx, gasUsed: tx.result.gasUsed, diff --git a/packages/stargate/src/events.ts b/packages/stargate/src/events.ts index b4b70cce..57f12aaa 100644 --- a/packages/stargate/src/events.ts +++ b/packages/stargate/src/events.ts @@ -1,5 +1,5 @@ import { fromUtf8 } from "@cosmjs/encoding"; -import { tendermint34 } from "@cosmjs/tendermint-rpc"; +import { tendermint34, tendermint37 } from "@cosmjs/tendermint-rpc"; /** * An event attribute. @@ -30,16 +30,16 @@ export interface Event { } /** - * Takes a Tendemrint 0.34 event with binary encoded key and value + * Takes a Tendermint 0.34 or 0.37 event with binary encoded key and value * and converts it into an `Event` with string attributes. */ -export function fromTendermint34Event(event: tendermint34.Event): Event { +export function fromTendermintEvent(event: tendermint34.Event | tendermint37.Event): Event { return { type: event.type, attributes: event.attributes.map( (attr): Attribute => ({ - key: fromUtf8(attr.key, true), - value: fromUtf8(attr.value, true), + key: typeof attr.key == "string" ? attr.key : fromUtf8(attr.key, true), + value: typeof attr.value == "string" ? attr.value : fromUtf8(attr.value, true), }), ), }; diff --git a/packages/stargate/src/index.ts b/packages/stargate/src/index.ts index fab188f7..62560972 100644 --- a/packages/stargate/src/index.ts +++ b/packages/stargate/src/index.ts @@ -1,6 +1,6 @@ export { Account, accountFromAny, AccountParser } from "./accounts"; export { AminoConverter, AminoConverters, AminoTypes } from "./aminotypes"; -export { Attribute, Event, fromTendermint34Event } from "./events"; +export { Attribute, Event, fromTendermintEvent } from "./events"; export { calculateFee, GasPrice } from "./fee"; export * as logs from "./logs"; export { diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 410af111..400f59ff 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -10,7 +10,7 @@ import { QueryDelegatorDelegationsResponse } from "cosmjs-types/cosmos/staking/v import { DelegationResponse } from "cosmjs-types/cosmos/staking/v1beta1/staking"; import { Account, accountFromAny, AccountParser } from "./accounts"; -import { Event, fromTendermint34Event } from "./events"; +import { Event, fromTendermintEvent } from "./events"; import { AuthExtension, BankExtension, @@ -471,7 +471,7 @@ export class StargateClient { height: tx.height, hash: toHex(tx.hash).toUpperCase(), code: tx.result.code, - events: tx.result.events.map(fromTendermint34Event), + events: tx.result.events.map(fromTendermintEvent), rawLog: tx.result.log || "", tx: tx.tx, gasUsed: tx.result.gasUsed,