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 UpdateInstantiateConfig command #1121

Merged
merged 5 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 31 additions & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
- [MsgStoreCodeResponse](#cosmwasm.wasm.v1.MsgStoreCodeResponse)
- [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin)
- [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse)
- [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig)
- [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse)

- [Msg](#cosmwasm.wasm.v1.Msg)

Expand Down Expand Up @@ -1287,7 +1289,7 @@ MsgClearAdmin removes any admin stored for a smart contract

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `sender` | [string](#string) | | Sender is the actor that signed the messages |
| `contract` | [string](#string) | | Contract is the address of the smart contract |


Expand Down Expand Up @@ -1506,6 +1508,33 @@ MsgUpdateAdminResponse returns empty data




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

### MsgUpdateInstantiateConfig
MsgUpdateInstantiateConfig updates instantiate config for a smart contract


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `code_id` | [uint64](#uint64) | | CodeID references the new WASM code |
| `new_instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | NewInstantiatePermission is the new access control |






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

### MsgUpdateInstantiateConfigResponse
MsgUpdateInstantiateConfigResponse returns empty data





<!-- end messages -->

<!-- end enums -->
Expand All @@ -1527,6 +1556,7 @@ Msg defines the wasm Msg service.
| `MigrateContract` | [MsgMigrateContract](#cosmwasm.wasm.v1.MsgMigrateContract) | [MsgMigrateContractResponse](#cosmwasm.wasm.v1.MsgMigrateContractResponse) | Migrate runs a code upgrade/ downgrade for a smart contract | |
| `UpdateAdmin` | [MsgUpdateAdmin](#cosmwasm.wasm.v1.MsgUpdateAdmin) | [MsgUpdateAdminResponse](#cosmwasm.wasm.v1.MsgUpdateAdminResponse) | UpdateAdmin sets a new admin for a smart contract | |
| `ClearAdmin` | [MsgClearAdmin](#cosmwasm.wasm.v1.MsgClearAdmin) | [MsgClearAdminResponse](#cosmwasm.wasm.v1.MsgClearAdminResponse) | ClearAdmin removes any admin stored for a smart contract | |
| `UpdateInstantiateConfig` | [MsgUpdateInstantiateConfig](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfig) | [MsgUpdateInstantiateConfigResponse](#cosmwasm.wasm.v1.MsgUpdateInstantiateConfigResponse) | UpdateInstantiateConfig updates instantiate config for a smart contract | |

<!-- end services -->

Expand Down
18 changes: 17 additions & 1 deletion proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ service Msg {
rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse);
// ClearAdmin removes any admin stored for a smart contract
rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse);
// UpdateInstantiateConfig updates instantiate config for a smart contract
rpc UpdateInstantiateConfig(MsgUpdateInstantiateConfig)
returns (MsgUpdateInstantiateConfigResponse);
}

// MsgStoreCode submit Wasm code to the system
Expand Down Expand Up @@ -166,11 +169,24 @@ message MsgUpdateAdminResponse {}

// MsgClearAdmin removes any admin stored for a smart contract
message MsgClearAdmin {
// Sender is the that actor that signed the messages
// Sender is the actor that signed the messages
string sender = 1;
// Contract is the address of the smart contract
string contract = 3;
}

// MsgClearAdminResponse returns empty data
message MsgClearAdminResponse {}

// MsgUpdateInstantiateConfig updates instantiate config for a smart contract
message MsgUpdateInstantiateConfig {
// Sender is the that actor that signed the messages
string sender = 1;
// CodeID references the new WASM code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
// CodeID references the new WASM code
// CodeID references the stored WASM code

uint64 code_id = 2 [ (gogoproto.customname) = "CodeID" ];
// NewInstantiatePermission is the new access control
AccessConfig new_instantiate_permission = 3;
}

// MsgUpdateInstantiateConfigResponse returns empty data
message MsgUpdateInstantiateConfigResponse {}
42 changes: 42 additions & 0 deletions x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,45 @@ func ClearContractAdminCmd() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// UpdateInstantiateConfigCmd updates instantiate config for a smart contract.
func UpdateInstantiateConfigCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "update-instantiate-config [code_id_int64]",
Short: "Update instantiate config for a codeID",
Aliases: []string{"update-instantiate-config"},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
codeID, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}
perm, err := parseAccessConfigFlags(cmd.Flags())
alpe marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

msg := types.MsgUpdateInstantiateConfig{
Sender: string(clientCtx.GetFromAddress()),
CodeID: codeID,
NewInstantiatePermission: perm,
}
if err = msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
SilenceUsage: true,
}

cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateNobody, "", "Nobody except the governance process can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Deprecated: Only this address can instantiate a contract from the code, optional")
cmd.Flags().StringSlice(flagInstantiateByAnyOfAddress, []string{}, "Any of the addresses can instantiate a contract from the code, optional")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
2 changes: 2 additions & 0 deletions x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func NewHandler(k types.ContractOpsKeeper) sdk.Handler {
res, err = msgServer.UpdateAdmin(sdk.WrapSDKContext(ctx), msg)
case *MsgClearAdmin:
res, err = msgServer.ClearAdmin(sdk.WrapSDKContext(ctx), msg)
case *types.MsgUpdateInstantiateConfig:
res, err = msgServer.UpdateInstantiateConfig(sdk.WrapSDKContext(ctx), msg)
default:
errMsg := fmt.Sprintf("unrecognized wasm message type: %T", msg)
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)
Expand Down
13 changes: 13 additions & 0 deletions x/wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,16 @@ func (m msgServer) ClearAdmin(goCtx context.Context, msg *types.MsgClearAdmin) (

return &types.MsgClearAdminResponse{}, nil
}

func (m msgServer) UpdateInstantiateConfig(goCtx context.Context, msg *types.MsgUpdateInstantiateConfig) (*types.MsgUpdateInstantiateConfigResponse, error) {
if err := msg.ValidateBasic(); err != nil {
return nil, err
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := m.keeper.SetAccessConfig(ctx, msg.CodeID, sdk.AccAddress(msg.Sender), *msg.NewInstantiatePermission); err != nil {
alpe marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

return &types.MsgUpdateInstantiateConfigResponse{}, nil
}
32 changes: 32 additions & 0 deletions x/wasm/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,35 @@ func (msg MsgInstantiateContract2) GetSigners() []sdk.AccAddress {
}
return []sdk.AccAddress{senderAddr}
}

func (msg MsgUpdateInstantiateConfig) Route() string {
return RouterKey
}

func (msg MsgUpdateInstantiateConfig) Type() string {
return "update-instantiate-config"
}

func (msg MsgUpdateInstantiateConfig) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return err
}

if err := msg.NewInstantiatePermission.ValidateBasic(); err != nil {
alpe marked this conversation as resolved.
Show resolved Hide resolved
return sdkerrors.Wrap(err, "instantiate permission")
}

return nil
alpe marked this conversation as resolved.
Show resolved Hide resolved
}

func (msg MsgUpdateInstantiateConfig) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgUpdateInstantiateConfig) GetSigners() []sdk.AccAddress {
senderAddr, err := sdk.AccAddressFromBech32(msg.Sender)
alpe marked this conversation as resolved.
Show resolved Hide resolved
if err != nil { // should never happen as valid basic rejects invalid addresses
panic(err.Error())
}
return []sdk.AccAddress{senderAddr}
}
Loading