Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Remove addresses for code upload params #1493

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
- [Query](#cosmwasm.wasm.v1.Query)

- [cosmwasm/wasm/v1/tx.proto](#cosmwasm/wasm/v1/tx.proto)
- [MsgAddCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses)
- [MsgAddCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse)
- [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin)
- [MsgClearAdminResponse](#cosmwasm.wasm.v1.MsgClearAdminResponse)
- [MsgExecuteContract](#cosmwasm.wasm.v1.MsgExecuteContract)
Expand All @@ -94,6 +96,8 @@
- [MsgMigrateContractResponse](#cosmwasm.wasm.v1.MsgMigrateContractResponse)
- [MsgPinCodes](#cosmwasm.wasm.v1.MsgPinCodes)
- [MsgPinCodesResponse](#cosmwasm.wasm.v1.MsgPinCodesResponse)
- [MsgRemoveCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses)
- [MsgRemoveCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse)
- [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract)
- [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse)
- [MsgStoreCode](#cosmwasm.wasm.v1.MsgStoreCode)
Expand Down Expand Up @@ -1333,6 +1337,34 @@ Query provides defines the gRPC querier service



<a name="cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses"></a>

### MsgAddCodeUploadParamsAddresses
MsgAddCodeUploadParamsAddresses is the
MsgAddCodeUploadParamsAddresses request type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `addresses` | [string](#string) | repeated | |






<a name="cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse"></a>

### MsgAddCodeUploadParamsAddressesResponse
MsgAddCodeUploadParamsAddressesResponse defines the response
structure for executing a MsgAddCodeUploadParamsAddresses message.






<a name="cosmwasm.wasm.v1.MsgClearAdmin"></a>

### MsgClearAdmin
Expand Down Expand Up @@ -1532,6 +1564,34 @@ Since: 0.40



<a name="cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses"></a>

### MsgRemoveCodeUploadParamsAddresses
MsgRemoveCodeUploadParamsAddresses is the
MsgRemoveCodeUploadParamsAddresses request type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `addresses` | [string](#string) | repeated | |






<a name="cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse"></a>

### MsgRemoveCodeUploadParamsAddressesResponse
MsgRemoveCodeUploadParamsAddressesResponse defines the response
structure for executing a MsgRemoveCodeUploadParamsAddresses message.






<a name="cosmwasm.wasm.v1.MsgStoreAndInstantiateContract"></a>

### MsgStoreAndInstantiateContract
Expand Down Expand Up @@ -1803,6 +1863,8 @@ Since: 0.40 | |
| `StoreAndInstantiateContract` | [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) | [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) | StoreAndInstantiateContract defines a governance operation for storing and instantiating the contract. The authority is defined in the keeper.

Since: 0.40 | |
| `RemoveCodeUploadParamsAddresses` | [MsgRemoveCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddresses) | [MsgRemoveCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgRemoveCodeUploadParamsAddressesResponse) | RemoveCodeUploadParamsAddresses defines a governance operation for removing addresses from code upload params. The authority is defined in the keeper. | |
| `AddCodeUploadParamsAddresses` | [MsgAddCodeUploadParamsAddresses](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddresses) | [MsgAddCodeUploadParamsAddressesResponse](#cosmwasm.wasm.v1.MsgAddCodeUploadParamsAddressesResponse) | AddCodeUploadParamsAddresses defines a governance operation for adding addresses to code upload params. The authority is defined in the keeper. | |

<!-- end services -->

Expand Down
44 changes: 43 additions & 1 deletion proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ service Msg {
// Since: 0.40
rpc StoreAndInstantiateContract(MsgStoreAndInstantiateContract)
returns (MsgStoreAndInstantiateContractResponse);
// RemoveCodeUploadParamsAddresses defines a governance operation for
// removing addresses from code upload params.
// The authority is defined in the keeper.
rpc RemoveCodeUploadParamsAddresses(MsgRemoveCodeUploadParamsAddresses)
returns (MsgRemoveCodeUploadParamsAddressesResponse);
// AddCodeUploadParamsAddresses defines a governance operation for
// adding addresses to code upload params.
// The authority is defined in the keeper.
rpc AddCodeUploadParamsAddresses(MsgAddCodeUploadParamsAddresses)
returns (MsgAddCodeUploadParamsAddressesResponse);
}

// MsgStoreCode submit Wasm code to the system
Expand Down Expand Up @@ -388,4 +398,36 @@ message MsgStoreAndInstantiateContractResponse {
string address = 1;
// Data contains bytes to returned from the contract
bytes data = 2;
}
}

// MsgAddCodeUploadParamsAddresses is the
// MsgAddCodeUploadParamsAddresses request type.
message MsgAddCodeUploadParamsAddresses {
option (amino.name) = "wasm/MsgAddCodeUploadParamsAddresses";
option (cosmos.msg.v1.signer) = "authority";

// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

repeated string addresses = 2 [ (gogoproto.moretags) = "yaml:\"addresses\"" ];
}

// MsgAddCodeUploadParamsAddressesResponse defines the response
// structure for executing a MsgAddCodeUploadParamsAddresses message.
message MsgAddCodeUploadParamsAddressesResponse {}

// MsgRemoveCodeUploadParamsAddresses is the
// MsgRemoveCodeUploadParamsAddresses request type.
message MsgRemoveCodeUploadParamsAddresses {
option (amino.name) = "wasm/MsgRemoveCodeUploadParamsAddresses";
option (cosmos.msg.v1.signer) = "authority";

// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

repeated string addresses = 2 [ (gogoproto.moretags) = "yaml:\"addresses\"" ];
}

// MsgRemoveCodeUploadParamsAddressesResponse defines the response
// structure for executing a MsgRemoveCodeUploadParamsAddresses message.
message MsgRemoveCodeUploadParamsAddressesResponse {}
86 changes: 86 additions & 0 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func SubmitProposalCmd() *cobra.Command {
ProposalPinCodesCmd(),
ProposalUnpinCodesCmd(),
ProposalUpdateInstantiateConfigCmd(),
ProposalAddCodeUploadParamsAddresses(),
ProposalRemoveCodeUploadParamsAddresses(),
)
return cmd
}
Expand Down Expand Up @@ -805,6 +807,90 @@ $ %s tx gov submit-proposal update-instantiate-config 1:nobody 2:everybody 3:%s1
return cmd
}

func ProposalAddCodeUploadParamsAddresses() *cobra.Command {
cmd := &cobra.Command{
Use: "add-code-upload-params-addresses [addresses] --title [text] --summary [text] --authority [address]",
Short: "Submit an add code upload params addresses proposal to add addresses to code upload config params",
Args: cobra.MinimumNArgs(1),
alpe marked this conversation as resolved.
Show resolved Hide resolved
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, proposalTitle, summary, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}

authority, err := cmd.Flags().GetString(flagAuthority)
if err != nil {
return fmt.Errorf("authority: %s", err)
}

if len(authority) == 0 {
return errors.New("authority address is required")
}

msg := types.MsgAddCodeUploadParamsAddresses{
Authority: authority,
Addresses: args,
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary)
if err != nil {
return err
}
if err = proposalMsg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposalMsg)
},
SilenceUsage: true,
}
// proposal flags
addCommonProposalFlags(cmd)
return cmd
}

func ProposalRemoveCodeUploadParamsAddresses() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-code-upload-params-addresses [addresses] --title [text] --summary [text] --authority [address]",
Short: "Submit a remove code upload params addresses proposal to remove addresses from code upload config params",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, proposalTitle, summary, deposit, err := getProposalInfo(cmd)
if err != nil {
return err
}

authority, err := cmd.Flags().GetString(flagAuthority)
if err != nil {
return fmt.Errorf("authority: %s", err)
}

if len(authority) == 0 {
return errors.New("authority address is required")
}

msg := types.MsgRemoveCodeUploadParamsAddresses{
Authority: authority,
Addresses: args,
}

proposalMsg, err := v1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, clientCtx.GetFromAddress().String(), "", proposalTitle, summary)
if err != nil {
return err
}
if err = proposalMsg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposalMsg)
},
SilenceUsage: true,
}
// proposal flags
addCommonProposalFlags(cmd)
return cmd
}

func addCommonProposalFlags(cmd *cobra.Command) {
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().String(cli.FlagTitle, "", "Title of proposal")
Expand Down
75 changes: 75 additions & 0 deletions x/wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,81 @@ func (m msgServer) StoreAndInstantiateContract(goCtx context.Context, req *types
}, nil
}

// AddCodeUploadParamsAddresses adds addresses to code upload params
func (m msgServer) AddCodeUploadParamsAddresses(goCtx context.Context, req *types.MsgAddCodeUploadParamsAddresses) (*types.MsgAddCodeUploadParamsAddressesResponse, error) {
if err := req.ValidateBasic(); err != nil {
return nil, err
}
authority := m.keeper.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)

params := m.keeper.GetParams(ctx)
if params.CodeUploadAccess.Permission != types.AccessTypeAnyOfAddresses {
alpe marked this conversation as resolved.
Show resolved Hide resolved
return nil, errorsmod.Wrap(types.ErrInvalid, "permission")
}

addresses := params.CodeUploadAccess.Addresses
for _, newAddr := range req.Addresses {
if !contains(addresses, newAddr) {
addresses = append(addresses, newAddr)
}
}

params.CodeUploadAccess.Addresses = addresses
if err := m.keeper.SetParams(ctx, params); err != nil {
return nil, err
}

return &types.MsgAddCodeUploadParamsAddressesResponse{}, nil
}

// RemoveCodeUploadParamsAddresses removes addresses to code upload params
func (m msgServer) RemoveCodeUploadParamsAddresses(goCtx context.Context, req *types.MsgRemoveCodeUploadParamsAddresses) (*types.MsgRemoveCodeUploadParamsAddressesResponse, error) {
if err := req.ValidateBasic(); err != nil {
return nil, err
}
authority := m.keeper.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)

params := m.keeper.GetParams(ctx)
if params.CodeUploadAccess.Permission != types.AccessTypeAnyOfAddresses {
return nil, errorsmod.Wrap(types.ErrInvalid, "permission")
}
addresses := params.CodeUploadAccess.Addresses
newAddresses := make([]string, 0)
for _, addr := range addresses {
if contains(req.Addresses, addr) {
continue
}
newAddresses = append(newAddresses, addr)
}

params.CodeUploadAccess.Addresses = newAddresses

if err := m.keeper.SetParams(ctx, params); err != nil {
return nil, err
}

return &types.MsgRemoveCodeUploadParamsAddressesResponse{}, nil
}

func contains[T comparable](src []T, o T) bool {
for _, v := range src {
if v == o {
return true
}
}
return false
}

func (m msgServer) selectAuthorizationPolicy(ctx sdk.Context, actor string) types.AuthorizationPolicy {
if actor == m.keeper.GetAuthority() {
return newGovAuthorizationPolicy(m.keeper.propagateGovAuthorization)
Expand Down
Loading