Rename fromTendermint34Event to fromTendermintEvent

and let it support both Tendermint 0.34 and 0.37 events as input
This commit is contained in:
Simon Warta
2023-03-02 14:12:47 +01:00
parent 3d0546a582
commit 3daa7b6c4a
5 changed files with 12 additions and 10 deletions
@@ -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,
+5 -5
View File
@@ -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),
}),
),
};
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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,