Remove "not_supported_by_chain" option for Amino converter types
This commit is contained in:
parent
d8412cf90a
commit
3885c0178e
@ -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
|
||||
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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<string, AminoConverter | "not_supported_by_chain">;
|
||||
|
||||
function isAminoConverter(
|
||||
converter: [string, AminoConverter | "not_supported_by_chain"],
|
||||
): converter is [string, AminoConverter] {
|
||||
return typeof converter[1] !== "string";
|
||||
}
|
||||
export type AminoConverters = Record<string, AminoConverter>;
|
||||
|
||||
/**
|
||||
* 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<string, AminoConverter | "not_supported_by_chain">;
|
||||
private readonly register: Record<string, AminoConverter>;
|
||||
|
||||
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: {
|
||||
|
||||
@ -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<string, AminoConverter> {
|
||||
return {
|
||||
"/cosmos.distribution.v1beta1.MsgFundCommunityPool": {
|
||||
aminoType: "cosmos-sdk/MsgFundCommunityPool",
|
||||
|
||||
@ -143,7 +143,7 @@ export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate {
|
||||
return msg.type === "cosmos-sdk/MsgUndelegate";
|
||||
}
|
||||
|
||||
export function createStakingAminoConverters(): Record<string, AminoConverter | "not_supported_by_chain"> {
|
||||
export function createStakingAminoConverters(): Record<string, AminoConverter> {
|
||||
return {
|
||||
"/cosmos.staking.v1beta1.MsgBeginRedelegate": {
|
||||
aminoType: "cosmos-sdk/MsgBeginRedelegate",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user