Skip to content

Commit

Permalink
Merge pull request #1443 from cosmos/sdk47-types
Browse files Browse the repository at this point in the history
Add group and gov v1 message types
  • Loading branch information
webmaster128 authored Jun 22, 2023
2 parents 2bd1dea + c1e8126 commit 9ecee56
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to
waiting for block inclusion. ([#1396])
- @cosmjs/cosmwasm-stargate: Add Amino JSON support for
`MsgStoreCode.instantiate_permission`. ([#334])
- @cosmjs/stargate: Add group and gov v1 message types

[#334]: https://github.com/cosmos/cosmjs/issues/334
[#1266]: https://github.com/cosmos/cosmjs/issues/1266
Expand Down
1 change: 1 addition & 0 deletions packages/stargate/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
createEvidenceAminoConverters,
createFeegrantAminoConverters,
createGovAminoConverters,
createGroupAminoConverters,
createIbcAminoConverters,
createSlashingAminoConverters,
createStakingAminoConverters,
Expand Down
3 changes: 3 additions & 0 deletions packages/stargate/src/modules/gov/aminomessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export function isAminoMsgDeposit(msg: AminoMsg): msg is AminoMsgDeposit {
}

export function createGovAminoConverters(): AminoConverters {
// Gov v1 types missing, see
// https://github.com/cosmos/cosmjs/issues/1442

return {
"/cosmos.gov.v1beta1.MsgDeposit": {
aminoType: "cosmos-sdk/MsgDeposit",
Expand Down
22 changes: 22 additions & 0 deletions packages/stargate/src/modules/gov/messages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
import {
MsgDeposit as V1MsgDeposit,
MsgSubmitProposal as V1MsgSubmitProposal,
MsgUpdateParams as V1MsgUpdateParams,
MsgVote as V1MsgVote,
MsgVoteWeighted as V1MsgVoteWeighted,
} from "cosmjs-types/cosmos/gov/v1/tx";
import { MsgDeposit, MsgSubmitProposal, MsgVote, MsgVoteWeighted } from "cosmjs-types/cosmos/gov/v1beta1/tx";

export const govTypes: ReadonlyArray<[string, GeneratedType]> = [
["/cosmos.gov.v1.MsgDeposit", V1MsgDeposit],
["/cosmos.gov.v1.MsgSubmitProposal", V1MsgSubmitProposal],
["/cosmos.gov.v1.MsgUpdateParams", V1MsgUpdateParams],
["/cosmos.gov.v1.MsgVote", V1MsgVote],
["/cosmos.gov.v1.MsgVoteWeighted", V1MsgVoteWeighted],

["/cosmos.gov.v1beta1.MsgDeposit", MsgDeposit],
["/cosmos.gov.v1beta1.MsgSubmitProposal", MsgSubmitProposal],
["/cosmos.gov.v1beta1.MsgVote", MsgVote],
["/cosmos.gov.v1beta1.MsgVoteWeighted", MsgVoteWeighted],
];

// There are no EncodeObject implementations for the new v1 message types because
// those things don't scale (https://github.com/cosmos/cosmjs/issues/1440). We need to
// address this more fundamentally. Users can use
// const msg = {
// typeUrl: "/cosmos.gov.v1.MsgDeposit",
// value: MsgDeposit.fromPartial({ ... })
// }
// in their app.

export interface MsgDepositEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmos.gov.v1beta1.MsgDeposit";
readonly value: Partial<MsgDeposit>;
Expand Down
6 changes: 6 additions & 0 deletions packages/stargate/src/modules/group/aminomessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { AminoConverters } from "../../aminotypes";

export function createGroupAminoConverters(): AminoConverters {
// Missing, see https://github.com/cosmos/cosmjs/issues/1441
return {};
}
43 changes: 43 additions & 0 deletions packages/stargate/src/modules/group/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { GeneratedType } from "@cosmjs/proto-signing";
import {
MsgCreateGroup,
MsgCreateGroupPolicy,
MsgCreateGroupWithPolicy,
MsgExec,
MsgLeaveGroup,
MsgSubmitProposal,
MsgUpdateGroupAdmin,
MsgUpdateGroupMembers,
MsgUpdateGroupMetadata,
MsgUpdateGroupPolicyAdmin,
MsgUpdateGroupPolicyDecisionPolicy,
MsgUpdateGroupPolicyMetadata,
MsgVote,
MsgWithdrawProposal,
} from "cosmjs-types/cosmos/group/v1/tx";

export const groupTypes: ReadonlyArray<[string, GeneratedType]> = [
["/cosmos.group.v1.MsgCreateGroup", MsgCreateGroup],
["/cosmos.group.v1.MsgCreateGroupPolicy", MsgCreateGroupPolicy],
["/cosmos.group.v1.MsgCreateGroupWithPolicy", MsgCreateGroupWithPolicy],
["/cosmos.group.v1.MsgExec", MsgExec],
["/cosmos.group.v1.MsgLeaveGroup", MsgLeaveGroup],
["/cosmos.group.v1.MsgSubmitProposal", MsgSubmitProposal],
["/cosmos.group.v1.MsgUpdateGroupAdmin", MsgUpdateGroupAdmin],
["/cosmos.group.v1.MsgUpdateGroupMembers", MsgUpdateGroupMembers],
["/cosmos.group.v1.MsgUpdateGroupMetadata", MsgUpdateGroupMetadata],
["/cosmos.group.v1.MsgUpdateGroupPolicyAdmin", MsgUpdateGroupPolicyAdmin],
["/cosmos.group.v1.MsgUpdateGroupPolicyDecisionPolicy", MsgUpdateGroupPolicyDecisionPolicy],
["/cosmos.group.v1.MsgUpdateGroupPolicyMetadata", MsgUpdateGroupPolicyMetadata],
["/cosmos.group.v1.MsgVote", MsgVote],
["/cosmos.group.v1.MsgWithdrawProposal", MsgWithdrawProposal],
];

// There are no EncodeObject implementations for the new v1 message types because
// those things don't scale (https://github.com/cosmos/cosmjs/issues/1440). We need to
// address this more fundamentally. Users can use
// const msg = {
// typeUrl: "/cosmos.group.v1.MsgCreateGroup",
// value: MsgCreateGroup.fromPartial({ ... })
// }
// in their app.
2 changes: 2 additions & 0 deletions packages/stargate/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export {
MsgVoteWeightedEncodeObject,
} from "./gov/messages";
export { GovExtension, GovParamsType, GovProposalId, setupGovExtension } from "./gov/queries";
export { createGroupAminoConverters } from "./group/aminomessages";
export { groupTypes } from "./group/messages";
export { AminoMsgTransfer, createIbcAminoConverters, isAminoMsgTransfer } from "./ibc/aminomessages";
export { ibcTypes, isMsgTransferEncodeObject, MsgTransferEncodeObject } from "./ibc/messages";
export { IbcExtension, setupIbcExtension } from "./ibc/queries";
Expand Down
2 changes: 2 additions & 0 deletions packages/stargate/src/signingstargateclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
distributionTypes,
feegrantTypes,
govTypes,
groupTypes,
ibcTypes,
MsgDelegateEncodeObject,
MsgSendEncodeObject,
Expand Down Expand Up @@ -64,6 +65,7 @@ export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
...distributionTypes,
...feegrantTypes,
...govTypes,
...groupTypes,
...stakingTypes,
...ibcTypes,
...vestingTypes,
Expand Down

0 comments on commit 9ecee56

Please sign in to comment.