Skip to content

Commit

Permalink
use existed registry instead of creating new on convertation, fix fro…
Browse files Browse the repository at this point in the history
…mamino parser
  • Loading branch information
lukachi committed Mar 25, 2024
1 parent 36dee48 commit fe53ccc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions packages/client/src/helpers/authz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ 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> {
export function createAuthzAminoConverters(
stargateRegistry: Registry,
): Record<string, AminoConverter> {
const aminoTypes = new AminoTypes({
...createDefaultAminoConverters(),
})
const stargateRegistry = new Registry()

return {
[MessageTypeUrls.Exec]: {
Expand All @@ -28,8 +29,6 @@ export function createAuthzAminoConverters(): Record<string, AminoConverter> {
} => {
return {
msgs: msgs.map(msg => {
stargateRegistry.register(msg.typeUrl, MsgExec)

return aminoTypes.toAmino({
typeUrl: msg.typeUrl,
value: stargateRegistry.decode({
Expand All @@ -50,7 +49,17 @@ export function createAuthzAminoConverters(): Record<string, AminoConverter> {
msgs: AminoMsg[]
}): MsgExec =>
MsgExec.fromPartial({
msgs: msgs.map(msg => aminoTypes.fromAmino(msg)),
msgs: msgs.map(msg => {
const res = aminoTypes.fromAmino(msg)

return {
typeUrl: res.typeUrl,
value: stargateRegistry.encode({
typeUrl: res.typeUrl,
value: res.value,
}),
}
}),
grantee,
}),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/helpers/broadcast-maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const makeBroadcastMaker = async (config: Config, wallet: Wallet) => {
},
aminoTypes: new AminoTypes({
...createDefaultAminoConverters(),
...createAuthzAminoConverters(),
...createAuthzAminoConverters(stargateRegistry),
}),
},
)
Expand Down

0 comments on commit fe53ccc

Please sign in to comment.