feat: Add MsgCreateGroupWithPolicy to x/group (#10963)
## Description Closes: #10655 This PR adds a new msg MsgCreateGroupWithPolicy It has a boolean field GroupPolicyAsAdmin, if set to true, that would update also the admin of the newly created group and group policy to the group policy address itself --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
+104
-2
@@ -18,8 +18,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FlagExec = "exec"
|
||||
ExecTry = "try"
|
||||
FlagExec = "exec"
|
||||
ExecTry = "try"
|
||||
FlagGroupPolicyAsAdmin = "group-policy-as-admin"
|
||||
)
|
||||
|
||||
// TxCmd returns a root CLI command handler for all x/group transaction commands.
|
||||
@@ -37,6 +38,7 @@ func TxCmd(name string) *cobra.Command {
|
||||
MsgUpdateGroupAdminCmd(),
|
||||
MsgUpdateGroupMetadataCmd(),
|
||||
MsgUpdateGroupMembersCmd(),
|
||||
MsgCreateGroupWithPolicyCmd(),
|
||||
MsgCreateGroupPolicyCmd(),
|
||||
MsgUpdateGroupPolicyAdminCmd(),
|
||||
MsgUpdateGroupPolicyDecisionPolicyCmd(),
|
||||
@@ -283,6 +285,106 @@ func MsgUpdateGroupMetadataCmd() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
// MsgCreateGroupWithPolicyCmd creates a CLI command for Msg/CreateGroupWithPolicy.
|
||||
func MsgCreateGroupWithPolicyCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "create-group-with-policy [admin] [group-metadata] [group-policy-metadata] [members-json-file] [decision-policy]",
|
||||
Short: "Create a group with policy which is an aggregation " +
|
||||
"of member accounts with associated weights, " +
|
||||
"an administrator account and a decision policy. Note, the '--from' flag is " +
|
||||
"ignored as it is implied from [admin].",
|
||||
Long: strings.TrimSpace(
|
||||
fmt.Sprintf(`Create a group with policy which is an aggregation of member accounts with associated weights,
|
||||
an administrator account and decision policy. Note, the '--from' flag is ignored as it is implied from [admin].
|
||||
Members accounts can be given through a members JSON file that contains an array of members.
|
||||
If group-policy-as-admin flag is set to true, the admin of the newly created group and group policy is set with the group policy address itself.
|
||||
|
||||
Example:
|
||||
$ %s tx group create-group-with-policy [admin] [group-metadata] [group-policy-metadata] [members-json-file] \
|
||||
'{"@type":"/cosmos.group.v1beta1.ThresholdDecisionPolicy", "threshold":"1", "timeout":"1s"}'
|
||||
|
||||
where members.json contains:
|
||||
|
||||
{
|
||||
"members": [
|
||||
{
|
||||
"address": "addr1",
|
||||
"weight": "1",
|
||||
"metadata": "some metadata"
|
||||
},
|
||||
{
|
||||
"address": "addr2",
|
||||
"weight": "1",
|
||||
"metadata": "some metadata"
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
version.AppName,
|
||||
),
|
||||
),
|
||||
Args: cobra.MinimumNArgs(5),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := cmd.Flags().Set(flags.FlagFrom, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx, err := client.GetClientTxContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
groupPolicyAsAdmin, err := cmd.Flags().GetBool(FlagGroupPolicyAsAdmin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
members, err := parseMembers(clientCtx, args[3])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
groupMetadata, err := base64.StdEncoding.DecodeString(args[1])
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "group metadata is malformed, proper base64 string is required")
|
||||
}
|
||||
|
||||
groupPolicyMetadata, err := base64.StdEncoding.DecodeString(args[2])
|
||||
if err != nil {
|
||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "group policy metadata is malformed, proper base64 string is required")
|
||||
}
|
||||
|
||||
var policy group.DecisionPolicy
|
||||
if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[4]), &policy); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg, err := group.NewMsgCreateGroupWithPolicy(
|
||||
clientCtx.GetFromAddress().String(),
|
||||
members,
|
||||
groupMetadata,
|
||||
groupPolicyMetadata,
|
||||
groupPolicyAsAdmin,
|
||||
policy,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = msg.ValidateBasic(); err != nil {
|
||||
return fmt.Errorf("message validation failed: %w", err)
|
||||
}
|
||||
|
||||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
|
||||
},
|
||||
}
|
||||
cmd.Flags().Bool(FlagGroupPolicyAsAdmin, false, "Sets admin of the newly created group and group policy with group policy address itself when true")
|
||||
flags.AddTxFlagsToCmd(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// MsgCreateGroupPolicyCmd creates a CLI command for Msg/CreateGroupPolicy.
|
||||
func MsgCreateGroupPolicyCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
|
||||
Reference in New Issue
Block a user