diff --git a/packages/client/src/helpers/authz.ts b/packages/client/src/helpers/authz.ts new file mode 100644 index 00000000..bc6cd49d --- /dev/null +++ b/packages/client/src/helpers/authz.ts @@ -0,0 +1,38 @@ +import type { AminoMsg } from '@cosmjs/amino' +import { + type AminoConverter, + AminoTypes, + createDefaultAminoConverters, +} from '@cosmjs/stargate' + +import { MsgExec } from '@/codec/cosmos/authz/v1beta1/tx' +import { MessageTypeUrls } from '@/enums' + +// TODO: https://github.com/likecoin/iscn-js/blob/1ac7fb6f3b568e0d35e598442769a283c669c34b/src/messages/authz.ts#L98 +export function createAuthzAminoConverters(): Record { + const aminoTypes = new AminoTypes({ + ...createDefaultAminoConverters(), + }) + + return { + [MessageTypeUrls.Exec]: { + aminoType: 'cosmos-sdk/MsgExec', + toAmino: ({ msgs, grantee }: MsgExec) => ({ + msgs: msgs.map(msg => aminoTypes.toAmino(msg)), + grantee, + }), + /* eslint-disable camelcase */ + fromAmino: ({ + msgs, + grantee, + }: { + grantee: string + msgs: AminoMsg[] + }): MsgExec => + MsgExec.fromPartial({ + msgs: msgs.map(msg => aminoTypes.fromAmino(msg)), + grantee, + }), + }, + } +} diff --git a/packages/client/src/helpers/broadcast-maker.ts b/packages/client/src/helpers/broadcast-maker.ts index b11e7c03..eabdfe6d 100644 --- a/packages/client/src/helpers/broadcast-maker.ts +++ b/packages/client/src/helpers/broadcast-maker.ts @@ -7,6 +7,8 @@ import { } from '@cosmjs/proto-signing/build/registry' import { type Account, + AminoTypes, + createDefaultAminoConverters, type DeliverTxResponse, GasPrice, SigningStargateClient, @@ -15,6 +17,7 @@ import { import { BaseAccount } from '@/codec/cosmos/auth/auth' import { EthAccount } from '@/codec/ethermint/account' import { WalletBroadcastError } from '@/errors' +import { createAuthzAminoConverters } from '@/helpers/authz' import type { Config, Wallet } from '@/types' import { stub } from './stub' @@ -38,6 +41,10 @@ export const makeBroadcastMaker = async (config: Config, wallet: Wallet) => { } return baseAccountToAccount(EthAccount.decode(acc.value).baseAccount!) }, + aminoTypes: new AminoTypes({ + ...createDefaultAminoConverters(), + ...createAuthzAminoConverters(), + }), }, )