Skip to content

Commit

Permalink
amino converter wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Mar 22, 2024
1 parent 6835cf1 commit 9cddb5a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/client/src/helpers/authz.ts
Original file line number Diff line number Diff line change
@@ -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<string, AminoConverter> {
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,
}),
},
}
}
7 changes: 7 additions & 0 deletions packages/client/src/helpers/broadcast-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from '@cosmjs/proto-signing/build/registry'
import {
type Account,
AminoTypes,
createDefaultAminoConverters,
type DeliverTxResponse,
GasPrice,
SigningStargateClient,
Expand All @@ -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'
Expand All @@ -38,6 +41,10 @@ export const makeBroadcastMaker = async (config: Config, wallet: Wallet) => {
}
return baseAccountToAccount(EthAccount.decode(acc.value).baseAccount!)
},
aminoTypes: new AminoTypes({
...createDefaultAminoConverters(),
...createAuthzAminoConverters(),
}),
},
)

Expand Down

0 comments on commit 9cddb5a

Please sign in to comment.