diff --git a/CHANGELOG.md b/CHANGELOG.md index 319c75d8..4dddf154 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,10 @@ and this project adheres to - @cosmjs/stargate: Remove `QueryClient.queryUnverified` and `QueryClient.queryVerified`. Please use `QueryClient.queryAbci` and `QueryClient.queryStoreVerified` instead. +- @cosmjs/stargate: Remove "not_supported_by_chain" option for Amino converter + types since this is not needed anymore. ([#1403]) +[#1403]: https://github.com/cosmos/cosmjs/issues/1403 [#1409]: https://github.com/cosmos/cosmjs/issues/1409 [#1411]: https://github.com/cosmos/cosmjs/pull/1411 diff --git a/packages/stargate/src/aminotypes.spec.ts b/packages/stargate/src/aminotypes.spec.ts index a7d06a1b..ff768706 100644 --- a/packages/stargate/src/aminotypes.spec.ts +++ b/packages/stargate/src/aminotypes.spec.ts @@ -192,17 +192,6 @@ describe("AminoTypes", () => { }); }); - it("throws for types which are not on chain yet", () => { - expect(() => { - new AminoTypes({ "/cosmos.feegrant.v1beta1.MsgRevokeAllowance": "not_supported_by_chain" }).toAmino({ - typeUrl: "/cosmos.feegrant.v1beta1.MsgRevokeAllowance", - value: 0, - }); - }).toThrowError( - /The message type '\/cosmos.feegrant.v1beta1.MsgRevokeAllowance' cannot be signed using the Amino JSON sign mode because this is not supported by chain./i, - ); - }); - it("throws for unknown type url", () => { expect(() => new AminoTypes(createBankAminoConverters()).fromAmino({ diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index cd7f83b0..f0cbdd62 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -9,13 +9,7 @@ export interface AminoConverter { } /** A map from protobuf type URL to the AminoConverter implementation if supported on chain */ -export type AminoConverters = Record; - -function isAminoConverter( - converter: [string, AminoConverter | "not_supported_by_chain"], -): converter is [string, AminoConverter] { - return typeof converter[1] !== "string"; -} +export type AminoConverters = Record; /** * A map from Stargate message types as used in the messages's `Any` type @@ -26,7 +20,7 @@ export class AminoTypes { // There is no uniqueness guarantee of the Amino type identifier in the type // system or constructor. Instead it's the user's responsibility to ensure // there is no overlap when fromAmino is called. - private readonly register: Record; + private readonly register: Record; public constructor(types: AminoConverters) { this.register = types; @@ -34,11 +28,6 @@ export class AminoTypes { public toAmino({ typeUrl, value }: EncodeObject): AminoMsg { const converter = this.register[typeUrl]; - if (converter === "not_supported_by_chain") { - throw new Error( - `The message type '${typeUrl}' cannot be signed using the Amino JSON sign mode because this is not supported by chain.`, - ); - } if (!converter) { throw new Error( `Type URL '${typeUrl}' does not exist in the Amino message type register. ` + @@ -53,9 +42,7 @@ export class AminoTypes { } public fromAmino({ type, value }: AminoMsg): EncodeObject { - const matches = Object.entries(this.register) - .filter(isAminoConverter) - .filter(([_typeUrl, { aminoType }]) => aminoType === type); + const matches = Object.entries(this.register).filter(([_typeUrl, { aminoType }]) => aminoType === type); switch (matches.length) { case 0: { diff --git a/packages/stargate/src/modules/distribution/aminomessages.ts b/packages/stargate/src/modules/distribution/aminomessages.ts index f9844f55..12836d4e 100644 --- a/packages/stargate/src/modules/distribution/aminomessages.ts +++ b/packages/stargate/src/modules/distribution/aminomessages.ts @@ -72,10 +72,7 @@ export function isAminoMsgFundCommunityPool(msg: AminoMsg): msg is AminoMsgFundC return msg.type === "cosmos-sdk/MsgFundCommunityPool"; } -export function createDistributionAminoConverters(): Record< - string, - AminoConverter | "not_supported_by_chain" -> { +export function createDistributionAminoConverters(): Record { return { "/cosmos.distribution.v1beta1.MsgFundCommunityPool": { aminoType: "cosmos-sdk/MsgFundCommunityPool", diff --git a/packages/stargate/src/modules/staking/aminomessages.ts b/packages/stargate/src/modules/staking/aminomessages.ts index 775b0301..7b4c3732 100644 --- a/packages/stargate/src/modules/staking/aminomessages.ts +++ b/packages/stargate/src/modules/staking/aminomessages.ts @@ -143,7 +143,7 @@ export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate { return msg.type === "cosmos-sdk/MsgUndelegate"; } -export function createStakingAminoConverters(): Record { +export function createStakingAminoConverters(): Record { return { "/cosmos.staking.v1beta1.MsgBeginRedelegate": { aminoType: "cosmos-sdk/MsgBeginRedelegate",