From b315fe8e09ef9170410c60fc3f9c4edbb3209258 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 21 Jan 2022 14:19:40 +0100 Subject: [PATCH 01/13] Add new proto types for the sudo an execute proposals --- proto/cosmwasm/wasm/v1/proposal.proto | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/proto/cosmwasm/wasm/v1/proposal.proto b/proto/cosmwasm/wasm/v1/proposal.proto index 759124c0f8..56131199cb 100644 --- a/proto/cosmwasm/wasm/v1/proposal.proto +++ b/proto/cosmwasm/wasm/v1/proposal.proto @@ -56,6 +56,7 @@ message MigrateContractProposal { string title = 1; // Description is a human readable text string description = 2; + // FIXME: I think this is unused? Migrate has no sender // RunAs is the address that is passed to the contract's environment as sender string run_as = 3; // Contract is the address of the smart contract @@ -66,6 +67,33 @@ message MigrateContractProposal { bytes msg = 6 [ (gogoproto.casttype) = "RawContractMessage" ]; } +// SudoContractProposal gov proposal content type to call sudo on a contract. +message SudoContractProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // Contract is the address of the smart contract + string contract = 3; + // Msg json encoded message to be passed to the contract as sudo + bytes msg = 4 [ (gogoproto.casttype) = "RawContractMessage" ]; +} + +// ExecuteContractProposal gov proposal content type to call execute on a +// contract. +message ExecuteContractProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's environment as sender + string run_as = 3; + // Contract is the address of the smart contract + string contract = 4; + // Msg json encoded message to be passed to the contract as sudo + bytes msg = 5 [ (gogoproto.casttype) = "RawContractMessage" ]; +} + // UpdateAdminProposal gov proposal content type to set an admin for a contract. message UpdateAdminProposal { // Title is a short summary From 6bd6ffe90b984ed58d5169e9df2a80417e23c919 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 21 Jan 2022 14:21:21 +0100 Subject: [PATCH 02/13] Compile proto files --- docs/proto/proto-docs.md | 42 +- x/wasm/types/genesis.pb.go | 5 +- x/wasm/types/ibc.pb.go | 5 +- x/wasm/types/proposal.pb.go | 841 +++++++++++++++++++++++++++++++++--- x/wasm/types/query.pb.go | 7 +- x/wasm/types/tx.pb.go | 7 +- x/wasm/types/types.pb.go | 7 +- 7 files changed, 834 insertions(+), 80 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index e9ea878143..41756a7a6f 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -46,10 +46,12 @@ - [cosmwasm/wasm/v1/proposal.proto](#cosmwasm/wasm/v1/proposal.proto) - [ClearAdminProposal](#cosmwasm.wasm.v1.ClearAdminProposal) + - [ExecuteContractProposal](#cosmwasm.wasm.v1.ExecuteContractProposal) - [InstantiateContractProposal](#cosmwasm.wasm.v1.InstantiateContractProposal) - [MigrateContractProposal](#cosmwasm.wasm.v1.MigrateContractProposal) - [PinCodesProposal](#cosmwasm.wasm.v1.PinCodesProposal) - [StoreCodeProposal](#cosmwasm.wasm.v1.StoreCodeProposal) + - [SudoContractProposal](#cosmwasm.wasm.v1.SudoContractProposal) - [UnpinCodesProposal](#cosmwasm.wasm.v1.UnpinCodesProposal) - [UpdateAdminProposal](#cosmwasm.wasm.v1.UpdateAdminProposal) @@ -658,6 +660,26 @@ contract. + + +### ExecuteContractProposal +ExecuteContractProposal gov proposal content type to call execute on a +contract. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | Title is a short summary | +| `description` | [string](#string) | | Description is a human readable text | +| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | +| `contract` | [string](#string) | | Contract is the address of the smart contract | +| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo | + + + + + + ### InstantiateContractProposal @@ -691,7 +713,7 @@ MigrateContractProposal gov proposal content type to migrate a contract. | ----- | ---- | ----- | ----------- | | `title` | [string](#string) | | Title is a short summary | | `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | +| `run_as` | [string](#string) | | FIXME: I think this is unused? Migrate has no sender RunAs is the address that is passed to the contract's environment as sender | | `contract` | [string](#string) | | Contract is the address of the smart contract | | `code_id` | [uint64](#uint64) | | CodeID references the new WASM code | | `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on migration | @@ -738,6 +760,24 @@ StoreCodeProposal gov proposal content type to submit WASM code to the system + + +### SudoContractProposal +SudoContractProposal gov proposal content type to call sudo on a contract. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | Title is a short summary | +| `description` | [string](#string) | | Description is a human readable text | +| `contract` | [string](#string) | | Contract is the address of the smart contract | +| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo | + + + + + + ### UnpinCodesProposal diff --git a/x/wasm/types/genesis.pb.go b/x/wasm/types/genesis.pb.go index 14fb3e7fd0..0c5096e421 100644 --- a/x/wasm/types/genesis.pb.go +++ b/x/wasm/types/genesis.pb.go @@ -5,12 +5,11 @@ package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/wasm/types/ibc.pb.go b/x/wasm/types/ibc.pb.go index d9f4a3809a..ac6c9f0060 100644 --- a/x/wasm/types/ibc.pb.go +++ b/x/wasm/types/ibc.pb.go @@ -5,12 +5,11 @@ package types import ( fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/wasm/types/proposal.pb.go b/x/wasm/types/proposal.pb.go index 53dd2c1fdf..a80392b383 100644 --- a/x/wasm/types/proposal.pb.go +++ b/x/wasm/types/proposal.pb.go @@ -6,14 +6,13 @@ package types import ( bytes "bytes" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -132,6 +131,7 @@ type MigrateContractProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // Description is a human readable text Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // FIXME: I think this is unused? Migrate has no sender // RunAs is the address that is passed to the contract's environment as sender RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` // Contract is the address of the smart contract @@ -174,6 +174,97 @@ func (m *MigrateContractProposal) XXX_DiscardUnknown() { var xxx_messageInfo_MigrateContractProposal proto.InternalMessageInfo +// SudoContractProposal gov proposal content type to call sudo on a contract. +type SudoContractProposal struct { + // Title is a short summary + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // Description is a human readable text + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,3,opt,name=contract,proto3" json:"contract,omitempty"` + // Msg json encoded message to be passed to the contract as sudo + Msg RawContractMessage `protobuf:"bytes,4,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` +} + +func (m *SudoContractProposal) Reset() { *m = SudoContractProposal{} } +func (*SudoContractProposal) ProtoMessage() {} +func (*SudoContractProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_be6422d717c730cb, []int{3} +} +func (m *SudoContractProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SudoContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SudoContractProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *SudoContractProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_SudoContractProposal.Merge(m, src) +} +func (m *SudoContractProposal) XXX_Size() int { + return m.Size() +} +func (m *SudoContractProposal) XXX_DiscardUnknown() { + xxx_messageInfo_SudoContractProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_SudoContractProposal proto.InternalMessageInfo + +// ExecuteContractProposal gov proposal content type to call execute on a +// contract. +type ExecuteContractProposal struct { + // Title is a short summary + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + // Description is a human readable text + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + // RunAs is the address that is passed to the contract's environment as sender + RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` + // Contract is the address of the smart contract + Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` + // Msg json encoded message to be passed to the contract as sudo + Msg RawContractMessage `protobuf:"bytes,5,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` +} + +func (m *ExecuteContractProposal) Reset() { *m = ExecuteContractProposal{} } +func (*ExecuteContractProposal) ProtoMessage() {} +func (*ExecuteContractProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_be6422d717c730cb, []int{4} +} +func (m *ExecuteContractProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ExecuteContractProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ExecuteContractProposal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ExecuteContractProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_ExecuteContractProposal.Merge(m, src) +} +func (m *ExecuteContractProposal) XXX_Size() int { + return m.Size() +} +func (m *ExecuteContractProposal) XXX_DiscardUnknown() { + xxx_messageInfo_ExecuteContractProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_ExecuteContractProposal proto.InternalMessageInfo + // UpdateAdminProposal gov proposal content type to set an admin for a contract. type UpdateAdminProposal struct { // Title is a short summary @@ -189,7 +280,7 @@ type UpdateAdminProposal struct { func (m *UpdateAdminProposal) Reset() { *m = UpdateAdminProposal{} } func (*UpdateAdminProposal) ProtoMessage() {} func (*UpdateAdminProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{3} + return fileDescriptor_be6422d717c730cb, []int{5} } func (m *UpdateAdminProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -232,7 +323,7 @@ type ClearAdminProposal struct { func (m *ClearAdminProposal) Reset() { *m = ClearAdminProposal{} } func (*ClearAdminProposal) ProtoMessage() {} func (*ClearAdminProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{4} + return fileDescriptor_be6422d717c730cb, []int{6} } func (m *ClearAdminProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -275,7 +366,7 @@ type PinCodesProposal struct { func (m *PinCodesProposal) Reset() { *m = PinCodesProposal{} } func (*PinCodesProposal) ProtoMessage() {} func (*PinCodesProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{5} + return fileDescriptor_be6422d717c730cb, []int{7} } func (m *PinCodesProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -318,7 +409,7 @@ type UnpinCodesProposal struct { func (m *UnpinCodesProposal) Reset() { *m = UnpinCodesProposal{} } func (*UnpinCodesProposal) ProtoMessage() {} func (*UnpinCodesProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_be6422d717c730cb, []int{6} + return fileDescriptor_be6422d717c730cb, []int{8} } func (m *UnpinCodesProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -351,6 +442,8 @@ func init() { proto.RegisterType((*StoreCodeProposal)(nil), "cosmwasm.wasm.v1.StoreCodeProposal") proto.RegisterType((*InstantiateContractProposal)(nil), "cosmwasm.wasm.v1.InstantiateContractProposal") proto.RegisterType((*MigrateContractProposal)(nil), "cosmwasm.wasm.v1.MigrateContractProposal") + proto.RegisterType((*SudoContractProposal)(nil), "cosmwasm.wasm.v1.SudoContractProposal") + proto.RegisterType((*ExecuteContractProposal)(nil), "cosmwasm.wasm.v1.ExecuteContractProposal") proto.RegisterType((*UpdateAdminProposal)(nil), "cosmwasm.wasm.v1.UpdateAdminProposal") proto.RegisterType((*ClearAdminProposal)(nil), "cosmwasm.wasm.v1.ClearAdminProposal") proto.RegisterType((*PinCodesProposal)(nil), "cosmwasm.wasm.v1.PinCodesProposal") @@ -360,51 +453,53 @@ func init() { func init() { proto.RegisterFile("cosmwasm/wasm/v1/proposal.proto", fileDescriptor_be6422d717c730cb) } var fileDescriptor_be6422d717c730cb = []byte{ - // 698 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x54, 0xcd, 0x6e, 0xd3, 0x4a, - 0x14, 0x8e, 0x9b, 0xc4, 0x49, 0xa7, 0xd1, 0xbd, 0xb9, 0xbe, 0x69, 0x6f, 0x6e, 0x41, 0x76, 0x64, - 0xa4, 0xca, 0x1b, 0x6c, 0x52, 0x24, 0x04, 0xec, 0xe2, 0xb0, 0x69, 0x45, 0xa5, 0xca, 0x55, 0x55, - 0x89, 0x4d, 0x34, 0xb1, 0xa7, 0xa9, 0x45, 0x3c, 0x63, 0x79, 0x26, 0x0d, 0x79, 0x0b, 0x1e, 0x80, - 0x07, 0x40, 0x6c, 0x10, 0x6f, 0x51, 0xb1, 0xaa, 0xc4, 0xa6, 0x2b, 0x43, 0xdd, 0x37, 0xc8, 0x12, - 0x09, 0x09, 0xcd, 0x8c, 0x13, 0xd2, 0x82, 0x00, 0x89,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0x43, 0xbd, 0x18, 0x25, 0x51, 0x48, 0x29, 0xe7, 0xae, 0xb4, 0x14, 0x6b, 0x65, 0x53, 0xb7, 0xaf, - 0x6a, 0x64, 0x77, 0x7c, 0x1f, 0x51, 0xda, 0x25, 0xf8, 0x30, 0x1c, 0x78, 0xab, 0x0b, 0xd1, 0xbb, - 0xf3, 0xe0, 0xed, 0x52, 0xb5, 0x5c, 0x57, 0xb7, 0x4b, 0x55, 0xb5, 0x5e, 0x31, 0x5f, 0x2f, 0x81, - 0x6b, 0x5b, 0x9f, 0x50, 0x5d, 0x82, 0x59, 0x02, 0x7d, 0xf6, 0xab, 0x94, 0x68, 0x80, 0x32, 0x0c, - 0xa2, 0x10, 0x0b, 0x01, 0x96, 0x3d, 0x69, 0x68, 0x37, 0x40, 0x85, 0xab, 0xd2, 0x0b, 0x83, 0x66, - 0xb9, 0xa5, 0x58, 0x25, 0x17, 0x64, 0xa9, 0xa1, 0x72, 0x09, 0xb6, 0x1e, 0x78, 0x2a, 0x77, 0x6d, - 0x05, 0x3c, 0x74, 0x08, 0xfb, 0x68, 0xd8, 0x54, 0x65, 0xa8, 0x30, 0x34, 0x0b, 0x14, 0x23, 0x3a, - 0x10, 0x7a, 0xd4, 0xdc, 0xb5, 0xf7, 0xa9, 0xa1, 0x79, 0x70, 0x3c, 0xab, 0x62, 0x07, 0x51, 0x0a, - 0x07, 0xc8, 0xe3, 0x10, 0x0d, 0x82, 0xf2, 0xe1, 0x08, 0x07, 0xb4, 0x59, 0x6d, 0x15, 0xad, 0x95, - 0xcd, 0xff, 0x6d, 0x39, 0x37, 0x36, 0x9f, 0x1b, 0x3b, 0x9f, 0x1b, 0xbb, 0x4b, 0x42, 0xec, 0xde, - 0x3a, 0x49, 0x8d, 0xc2, 0x8b, 0xb7, 0x86, 0x35, 0x08, 0xd9, 0xd1, 0xa8, 0x6f, 0xfb, 0x24, 0x72, - 0xf2, 0x21, 0x93, 0x9f, 0x9b, 0x34, 0x78, 0x9c, 0x4f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39, - 0xc9, 0x74, 0xe5, 0x34, 0xd3, 0x95, 0x77, 0x99, 0xae, 0x3c, 0xbd, 0xd0, 0x0b, 0xa7, 0x17, 0x7a, - 0xe1, 0xec, 0x42, 0x2f, 0x3c, 0xda, 0x58, 0xb8, 0x9b, 0x5d, 0x42, 0xa3, 0x83, 0xd9, 0x03, 0x1f, - 0x38, 0x4f, 0xe4, 0x43, 0x2f, 0xee, 0x67, 0x5f, 0x15, 0xcf, 0xfc, 0xed, 0x8f, 0x01, 0x00, 0x00, - 0xff, 0xff, 0x9a, 0x01, 0xce, 0x1b, 0x6f, 0x06, 0x00, 0x00, + // 732 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0xcd, 0x36, 0x89, 0x93, 0x6e, 0x23, 0x08, 0x26, 0x6d, 0x43, 0x41, 0x76, 0x64, 0xa4, 0xca, + 0x17, 0x6c, 0x52, 0x24, 0x04, 0xdc, 0xe2, 0xc0, 0xa1, 0x15, 0x95, 0x2a, 0x57, 0x55, 0x25, 0x2e, + 0xd1, 0xc6, 0xde, 0xa6, 0x16, 0xb1, 0xd7, 0xf2, 0x6e, 0x9a, 0xe6, 0x2f, 0x38, 0x70, 0xe4, 0x03, + 0x10, 0x07, 0x10, 0x7f, 0x51, 0x71, 0xaa, 0xc4, 0xa5, 0x27, 0x43, 0xd3, 0x3f, 0xc8, 0x11, 0x09, + 0x09, 0xad, 0xd7, 0x09, 0x69, 0x41, 0x2d, 0x12, 0x05, 0xc4, 0xc5, 0xc9, 0x78, 0xde, 0xf8, 0xbd, + 0x79, 0x9e, 0xf1, 0x42, 0xd5, 0x21, 0xd4, 0xef, 0x23, 0xea, 0x9b, 0xc9, 0x65, 0xaf, 0x6e, 0x86, + 0x11, 0x09, 0x09, 0x45, 0x5d, 0x23, 0x8c, 0x08, 0x23, 0x72, 0x79, 0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xeb, 0xa1, + 0x02, 0x0e, 0x86, 0x0a, 0x38, 0x1c, 0x2a, 0xe0, 0xf3, 0x50, 0x01, 0x2f, 0x4e, 0x94, 0xcc, 0xe1, + 0x89, 0x92, 0x39, 0x3a, 0x51, 0x32, 0xcf, 0x96, 0xa7, 0xbe, 0x71, 0x4d, 0x42, 0xfd, 0xed, 0xf1, + 0x41, 0xe9, 0x9a, 0xfb, 0xe2, 0xc0, 0x4c, 0xbe, 0x73, 0x6d, 0x29, 0x39, 0x2e, 0xef, 0x7d, 0x0b, + 0x00, 0x00, 0xff, 0xff, 0x7a, 0x1d, 0x54, 0x9b, 0xb7, 0x07, 0x00, 0x00, } func (this *StoreCodeProposal) Equal(that interface{}) bool { @@ -532,6 +627,75 @@ func (this *MigrateContractProposal) Equal(that interface{}) bool { } return true } +func (this *SudoContractProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*SudoContractProposal) + if !ok { + that2, ok := that.(SudoContractProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if this.Contract != that1.Contract { + return false + } + if !bytes.Equal(this.Msg, that1.Msg) { + return false + } + return true +} +func (this *ExecuteContractProposal) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ExecuteContractProposal) + if !ok { + that2, ok := that.(ExecuteContractProposal) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Title != that1.Title { + return false + } + if this.Description != that1.Description { + return false + } + if this.RunAs != that1.RunAs { + return false + } + if this.Contract != that1.Contract { + return false + } + if !bytes.Equal(this.Msg, that1.Msg) { + return false + } + return true +} func (this *UpdateAdminProposal) Equal(that interface{}) bool { if that == nil { return this == nil @@ -875,6 +1039,115 @@ func (m *MigrateContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *SudoContractProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *SudoContractProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SudoContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x22 + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ExecuteContractProposal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ExecuteContractProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ExecuteContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Msg) > 0 { + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0x2a + } + if len(m.Contract) > 0 { + i -= len(m.Contract) + copy(dAtA[i:], m.Contract) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Contract))) + i-- + dAtA[i] = 0x22 + } + if len(m.RunAs) > 0 { + i -= len(m.RunAs) + copy(dAtA[i:], m.RunAs) + i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) + i-- + dAtA[i] = 0x1a + } + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintProposal(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *UpdateAdminProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1194,7 +1467,7 @@ func (m *MigrateContractProposal) Size() (n int) { return n } -func (m *UpdateAdminProposal) Size() (n int) { +func (m *SudoContractProposal) Size() (n int) { if m == nil { return 0 } @@ -1208,18 +1481,18 @@ func (m *UpdateAdminProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.NewAdmin) + l = len(m.Contract) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.Contract) + l = len(m.Msg) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } return n } -func (m *ClearAdminProposal) Size() (n int) { +func (m *ExecuteContractProposal) Size() (n int) { if m == nil { return 0 } @@ -1233,14 +1506,22 @@ func (m *ClearAdminProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } + l = len(m.RunAs) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } l = len(m.Contract) if l > 0 { n += 1 + l + sovProposal(uint64(l)) } + l = len(m.Msg) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } return n } -func (m *PinCodesProposal) Size() (n int) { +func (m *UpdateAdminProposal) Size() (n int) { if m == nil { return 0 } @@ -1254,9 +1535,55 @@ func (m *PinCodesProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - if len(m.CodeIDs) > 0 { - l = 0 - for _, e := range m.CodeIDs { + l = len(m.NewAdmin) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + return n +} + +func (m *ClearAdminProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Contract) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + return n +} + +func (m *PinCodesProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovProposal(uint64(l)) + } + if len(m.CodeIDs) > 0 { + l = 0 + for _, e := range m.CodeIDs { l += sovProposal(uint64(e)) } n += 1 + sovProposal(uint64(l)) + l @@ -2038,6 +2365,398 @@ func (m *MigrateContractProposal) Unmarshal(dAtA []byte) error { } return nil } +func (m *SudoContractProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: SudoContractProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SudoContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) + if m.Msg == nil { + m.Msg = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ExecuteContractProposal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ExecuteContractProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ExecuteContractProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RunAs = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Contract = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = append(m.Msg[:0], dAtA[iNdEx:postIndex]...) + if m.Msg == nil { + m.Msg = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipProposal(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthProposal + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *UpdateAdminProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/wasm/types/query.pb.go b/x/wasm/types/query.pb.go index d5e3828e27..a6f0f8e710 100644 --- a/x/wasm/types/query.pb.go +++ b/x/wasm/types/query.pb.go @@ -7,10 +7,6 @@ import ( bytes "bytes" context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - query "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" @@ -20,6 +16,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/wasm/types/tx.pb.go b/x/wasm/types/tx.pb.go index 4113f370b5..dd82a4ae1b 100644 --- a/x/wasm/types/tx.pb.go +++ b/x/wasm/types/tx.pb.go @@ -6,10 +6,6 @@ package types import ( context "context" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/gogo/protobuf/gogoproto" @@ -18,6 +14,9 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/x/wasm/types/types.pb.go b/x/wasm/types/types.pb.go index 4adacd95e9..93f1a612f1 100644 --- a/x/wasm/types/types.pb.go +++ b/x/wasm/types/types.pb.go @@ -6,15 +6,14 @@ package types import ( bytes "bytes" fmt "fmt" - io "io" - math "math" - math_bits "math/bits" - types "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" _ "github.com/regen-network/cosmos-proto" github_com_tendermint_tendermint_libs_bytes "github.com/tendermint/tendermint/libs/bytes" + io "io" + math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. From d227112cc316e3f28c9441fbf9ee749c2d1d865f Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 21 Jan 2022 14:29:30 +0100 Subject: [PATCH 03/13] Registered new proposal types --- x/wasm/keeper/proposal_handler.go | 57 +++++++++++++++ x/wasm/types/proposal.go | 116 ++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+) diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index 4076540fa1..810fd6ca1b 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/hex" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -35,6 +36,10 @@ func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []t return handleInstantiateProposal(ctx, k, *c) case *types.MigrateContractProposal: return handleMigrateProposal(ctx, k, *c) + case *types.SudoContractProposal: + return handleSudoProposal(ctx, k, *c) + case *types.ExecuteContractProposal: + return handleExecuteProposal(ctx, k, *c) case *types.UpdateAdminProposal: return handleUpdateAdminProposal(ctx, k, *c) case *types.ClearAdminProposal: @@ -115,6 +120,58 @@ func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.M return nil } +func handleSudoProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.SudoContractProposal) error { + return fmt.Errorf("Not implemented") + //if err := p.ValidateBasic(); err != nil { + // return err + //} + // + //contractAddr, err := sdk.AccAddressFromBech32(p.Contract) + //if err != nil { + // return sdkerrors.Wrap(err, "contract") + //} + //runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) + //if err != nil { + // return sdkerrors.Wrap(err, "run as address") + //} + //data, err := k.Migrate(ctx, contractAddr, runAsAddr, p.CodeID, p.Msg) + //if err != nil { + // return err + //} + // + //ctx.EventManager().EmitEvent(sdk.NewEvent( + // types.EventTypeGovContractResult, + // sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), + //)) + //return nil +} + +func handleExecuteProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.ExecuteContractProposal) error { + return fmt.Errorf("Not implemented") + //if err := p.ValidateBasic(); err != nil { + // return err + //} + // + //contractAddr, err := sdk.AccAddressFromBech32(p.Contract) + //if err != nil { + // return sdkerrors.Wrap(err, "contract") + //} + //runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) + //if err != nil { + // return sdkerrors.Wrap(err, "run as address") + //} + //data, err := k.Migrate(ctx, contractAddr, runAsAddr, p.CodeID, p.Msg) + //if err != nil { + // return err + //} + // + //ctx.EventManager().EmitEvent(sdk.NewEvent( + // types.EventTypeGovContractResult, + // sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), + //)) + //return nil +} + func handleUpdateAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UpdateAdminProposal) error { if err := p.ValidateBasic(); err != nil { return err diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index c3fc543ed9..97df3b4ae8 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -16,6 +16,8 @@ const ( ProposalTypeStoreCode ProposalType = "StoreCode" ProposalTypeInstantiateContract ProposalType = "InstantiateContract" ProposalTypeMigrateContract ProposalType = "MigrateContract" + ProposalTypeSudoContract ProposalType = "SudoContract" + ProposalTypeExecuteContract ProposalType = "ExecuteContract" ProposalTypeUpdateAdmin ProposalType = "UpdateAdmin" ProposalTypeClearAdmin ProposalType = "ClearAdmin" ProposalTypePinCodes ProposalType = "PinCodes" @@ -30,6 +32,8 @@ var EnableAllProposals = []ProposalType{ ProposalTypeStoreCode, ProposalTypeInstantiateContract, ProposalTypeMigrateContract, + ProposalTypeSudoContract, + ProposalTypeExecuteContract, ProposalTypeUpdateAdmin, ProposalTypeClearAdmin, ProposalTypePinCodes, @@ -58,6 +62,8 @@ func init() { // register new content types with the sdk govtypes.RegisterProposalType(string(ProposalTypeStoreCode)) govtypes.RegisterProposalType(string(ProposalTypeInstantiateContract)) govtypes.RegisterProposalType(string(ProposalTypeMigrateContract)) + govtypes.RegisterProposalType(string(ProposalTypeSudoContract)) + govtypes.RegisterProposalType(string(ProposalTypeExecuteContract)) govtypes.RegisterProposalType(string(ProposalTypeUpdateAdmin)) govtypes.RegisterProposalType(string(ProposalTypeClearAdmin)) govtypes.RegisterProposalType(string(ProposalTypePinCodes)) @@ -65,6 +71,8 @@ func init() { // register new content types with the sdk govtypes.RegisterProposalTypeCodec(&StoreCodeProposal{}, "wasm/StoreCodeProposal") govtypes.RegisterProposalTypeCodec(&InstantiateContractProposal{}, "wasm/InstantiateContractProposal") govtypes.RegisterProposalTypeCodec(&MigrateContractProposal{}, "wasm/MigrateContractProposal") + govtypes.RegisterProposalTypeCodec(&SudoContractProposal{}, "wasm/SudoContractProposal") + govtypes.RegisterProposalTypeCodec(&ExecuteContractProposal{}, "wasm/ExecuteContractProposal") govtypes.RegisterProposalTypeCodec(&UpdateAdminProposal{}, "wasm/UpdateAdminProposal") govtypes.RegisterProposalTypeCodec(&ClearAdminProposal{}, "wasm/ClearAdminProposal") govtypes.RegisterProposalTypeCodec(&PinCodesProposal{}, "wasm/PinCodesProposal") @@ -277,6 +285,114 @@ func (p MigrateContractProposal) MarshalYAML() (interface{}, error) { }, nil } +// ProposalRoute returns the routing key of a parameter change proposal. +func (p SudoContractProposal) ProposalRoute() string { return RouterKey } + +// GetTitle returns the title of the proposal +func (p *SudoContractProposal) GetTitle() string { return p.Title } + +// GetDescription returns the human readable description of the proposal +func (p SudoContractProposal) GetDescription() string { return p.Description } + +// ProposalType returns the type +func (p SudoContractProposal) ProposalType() string { return string(ProposalTypeSudoContract) } + +// ValidateBasic validates the proposal +func (p SudoContractProposal) ValidateBasic() error { + if err := validateProposalCommons(p.Title, p.Description); err != nil { + return err + } + if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { + return sdkerrors.Wrap(err, "contract") + } + if err := p.Msg.ValidateBasic(); err != nil { + return sdkerrors.Wrap(err, "payload msg") + } + return nil +} + +// String implements the Stringer interface. +func (p SudoContractProposal) String() string { + return fmt.Sprintf(`Migrate Contract Proposal: + Title: %s + Description: %s + Contract: %s + Msg %q +`, p.Title, p.Description, p.Contract, p.Msg) +} + +// MarshalYAML pretty prints the migrate message +func (p SudoContractProposal) MarshalYAML() (interface{}, error) { + return struct { + Title string `yaml:"title"` + Description string `yaml:"description"` + Contract string `yaml:"contract"` + Msg string `yaml:"msg"` + }{ + Title: p.Title, + Description: p.Description, + Contract: p.Contract, + Msg: string(p.Msg), + }, nil +} + +// ProposalRoute returns the routing key of a parameter change proposal. +func (p ExecuteContractProposal) ProposalRoute() string { return RouterKey } + +// GetTitle returns the title of the proposal +func (p *ExecuteContractProposal) GetTitle() string { return p.Title } + +// GetDescription returns the human readable description of the proposal +func (p ExecuteContractProposal) GetDescription() string { return p.Description } + +// ProposalType returns the type +func (p ExecuteContractProposal) ProposalType() string { return string(ProposalTypeExecuteContract) } + +// ValidateBasic validates the proposal +func (p ExecuteContractProposal) ValidateBasic() error { + if err := validateProposalCommons(p.Title, p.Description); err != nil { + return err + } + if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { + return sdkerrors.Wrap(err, "contract") + } + if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { + return sdkerrors.Wrap(err, "run as") + } + if err := p.Msg.ValidateBasic(); err != nil { + return sdkerrors.Wrap(err, "payload msg") + } + return nil +} + +// String implements the Stringer interface. +func (p ExecuteContractProposal) String() string { + return fmt.Sprintf(`Migrate Contract Proposal: + Title: %s + Description: %s + Contract: %s + Run as: %s + Msg %q +`, p.Title, p.Description, p.Contract, p.RunAs, p.Msg) +} + +// MarshalYAML pretty prints the migrate message +func (p ExecuteContractProposal) MarshalYAML() (interface{}, error) { + return struct { + Title string `yaml:"title"` + Description string `yaml:"description"` + Contract string `yaml:"contract"` + Msg string `yaml:"msg"` + RunAs string `yaml:"run_as"` + }{ + Title: p.Title, + Description: p.Description, + Contract: p.Contract, + Msg: string(p.Msg), + RunAs: p.RunAs, + }, nil +} + // ProposalRoute returns the routing key of a parameter change proposal. func (p UpdateAdminProposal) ProposalRoute() string { return RouterKey } From 53a44eb4d7de37a3d43d09ce28b4ecdfd8da4440 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 21 Jan 2022 14:37:53 +0100 Subject: [PATCH 04/13] Wire up proposal handlers --- x/wasm/keeper/contract_keeper.go | 5 ++ x/wasm/keeper/proposal_handler.go | 89 ++++++++++++++----------------- x/wasm/types/exported_keepers.go | 3 ++ 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/x/wasm/keeper/contract_keeper.go b/x/wasm/keeper/contract_keeper.go index cd84c97da2..ffdcc91895 100644 --- a/x/wasm/keeper/contract_keeper.go +++ b/x/wasm/keeper/contract_keeper.go @@ -17,6 +17,7 @@ type decoratedKeeper interface { pinCode(ctx sdk.Context, codeID uint64) error unpinCode(ctx sdk.Context, codeID uint64) error execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error) + Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) setContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error } @@ -53,6 +54,10 @@ func (p PermissionedKeeper) Migrate(ctx sdk.Context, contractAddress sdk.AccAddr return p.nested.migrate(ctx, contractAddress, caller, newCodeID, msg, p.authZPolicy) } +func (p PermissionedKeeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) { + return p.nested.Sudo(ctx, contractAddress, msg) +} + func (p PermissionedKeeper) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error { return p.nested.setContractAdmin(ctx, contractAddress, caller, newAdmin, p.authZPolicy) } diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index 810fd6ca1b..1a0369d0c1 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -2,8 +2,6 @@ package keeper import ( "encoding/hex" - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -121,55 +119,50 @@ func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.M } func handleSudoProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.SudoContractProposal) error { - return fmt.Errorf("Not implemented") - //if err := p.ValidateBasic(); err != nil { - // return err - //} - // - //contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - //if err != nil { - // return sdkerrors.Wrap(err, "contract") - //} - //runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - //if err != nil { - // return sdkerrors.Wrap(err, "run as address") - //} - //data, err := k.Migrate(ctx, contractAddr, runAsAddr, p.CodeID, p.Msg) - //if err != nil { - // return err - //} - // - //ctx.EventManager().EmitEvent(sdk.NewEvent( - // types.EventTypeGovContractResult, - // sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - //)) - //return nil + if err := p.ValidateBasic(); err != nil { + return err + } + + contractAddr, err := sdk.AccAddressFromBech32(p.Contract) + if err != nil { + return sdkerrors.Wrap(err, "contract") + } + data, err := k.Sudo(ctx, contractAddr, p.Msg) + if err != nil { + return err + } + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeGovContractResult, + sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), + )) + return nil } func handleExecuteProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.ExecuteContractProposal) error { - return fmt.Errorf("Not implemented") - //if err := p.ValidateBasic(); err != nil { - // return err - //} - // - //contractAddr, err := sdk.AccAddressFromBech32(p.Contract) - //if err != nil { - // return sdkerrors.Wrap(err, "contract") - //} - //runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) - //if err != nil { - // return sdkerrors.Wrap(err, "run as address") - //} - //data, err := k.Migrate(ctx, contractAddr, runAsAddr, p.CodeID, p.Msg) - //if err != nil { - // return err - //} - // - //ctx.EventManager().EmitEvent(sdk.NewEvent( - // types.EventTypeGovContractResult, - // sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), - //)) - //return nil + if err := p.ValidateBasic(); err != nil { + return err + } + + contractAddr, err := sdk.AccAddressFromBech32(p.Contract) + if err != nil { + return sdkerrors.Wrap(err, "contract") + } + runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) + if err != nil { + return sdkerrors.Wrap(err, "run as address") + } + // we currently don't support sending tokens as part of an execute proposal. should we? from which account? + data, err := k.Execute(ctx, contractAddr, runAsAddr, p.Msg, nil) + if err != nil { + return err + } + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeGovContractResult, + sdk.NewAttribute(types.AttributeKeyResultDataHex, hex.EncodeToString(data)), + )) + return nil } func handleUpdateAdminProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UpdateAdminProposal) error { diff --git a/x/wasm/types/exported_keepers.go b/x/wasm/types/exported_keepers.go index 02f227648b..525d219404 100644 --- a/x/wasm/types/exported_keepers.go +++ b/x/wasm/types/exported_keepers.go @@ -36,6 +36,9 @@ type ContractOpsKeeper interface { // Migrate allows to upgrade a contract to a new code with data migration. Migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte) ([]byte, error) + // Sudo allows to call privileged entry point of a contract. + Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) + // UpdateContractAdmin sets the admin value on the ContractInfo. It must be a valid address (use ClearContractAdmin to remove it) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error From 027b951f1930eca4aa5603fd4bd2afc0eb0000d7 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Fri, 21 Jan 2022 14:50:33 +0100 Subject: [PATCH 05/13] Wire up cli for exec and sudo proposal --- x/wasm/client/cli/gov_tx.go | 129 ++++++++++++++++++++++++++++++ x/wasm/client/proposal_handler.go | 3 + 2 files changed, 132 insertions(+) diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 267342f714..158f06327f 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -237,6 +237,135 @@ func ProposalMigrateContractCmd() *cobra.Command { return cmd } +func ProposalExecuteContractCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "execute-contract [contract_addr_bech32] [json_encoded_migration_args]", + Short: "Submit a execute wasm contract proposal (run by any address)", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + contract := args[0] + execMsg := []byte(args[1]) + + runAs, err := cmd.Flags().GetString(flagRunAs) + if err != nil { + return fmt.Errorf("run-as: %s", err) + } + if len(runAs) == 0 { + return errors.New("run-as address is required") + } + proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return fmt.Errorf("proposal title: %s", err) + } + proposalDescr, err := cmd.Flags().GetString(cli.FlagDescription) + if err != nil { + return fmt.Errorf("proposal description: %s", err) + } + depositArg, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + deposit, err := sdk.ParseCoinsNormalized(depositArg) + if err != nil { + return err + } + + content := types.ExecuteContractProposal{ + Title: proposalTitle, + Description: proposalDescr, + Contract: contract, + Msg: execMsg, + RunAs: runAs, + } + + msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) + if err != nil { + return err + } + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + cmd.Flags().String(flagRunAs, "", "The address that is passed as sender to the contract on proposal execution") + + // proposal flags + cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") + cmd.Flags().String(cli.FlagDescription, "", "Description of proposal") + cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal") + cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)") + // type values must match the "ProposalHandler" "routes" in cli + cmd.Flags().String(flagProposalType, "", "Permission of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade") + return cmd +} + +func ProposalSudoContractCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "sudo-contract [contract_addr_bech32] [json_encoded_migration_args]", + Short: "Submit a sudo wasm contract proposal (to call privileged commands)", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + contract := args[0] + sudoMsg := []byte(args[1]) + + proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return fmt.Errorf("proposal title: %s", err) + } + proposalDescr, err := cmd.Flags().GetString(cli.FlagDescription) + if err != nil { + return fmt.Errorf("proposal description: %s", err) + } + depositArg, err := cmd.Flags().GetString(cli.FlagDeposit) + if err != nil { + return err + } + deposit, err := sdk.ParseCoinsNormalized(depositArg) + if err != nil { + return err + } + + content := types.SudoContractProposal{ + Title: proposalTitle, + Description: proposalDescr, + Contract: contract, + Msg: sudoMsg, + } + + msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) + if err != nil { + return err + } + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + // proposal flagsExecute + cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") + cmd.Flags().String(cli.FlagDescription, "", "Description of proposal") + cmd.Flags().String(cli.FlagDeposit, "", "Deposit of proposal") + cmd.Flags().String(cli.FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)") + // type values must match the "ProposalHandler" "routes" in cli + cmd.Flags().String(flagProposalType, "", "Permission of proposal, types: store-code/instantiate/migrate/update-admin/clear-admin/text/parameter_change/software_upgrade") + return cmd +} + func ProposalUpdateContractAdminCmd() *cobra.Command { cmd := &cobra.Command{ Use: "set-contract-admin [contract_addr_bech32] [new_admin_addr_bech32]", diff --git a/x/wasm/client/proposal_handler.go b/x/wasm/client/proposal_handler.go index 02007a4edf..f6a4be6a45 100644 --- a/x/wasm/client/proposal_handler.go +++ b/x/wasm/client/proposal_handler.go @@ -12,6 +12,9 @@ var ProposalHandlers = []govclient.ProposalHandler{ govclient.NewProposalHandler(cli.ProposalStoreCodeCmd, rest.StoreCodeProposalHandler), govclient.NewProposalHandler(cli.ProposalInstantiateContractCmd, rest.InstantiateProposalHandler), govclient.NewProposalHandler(cli.ProposalMigrateContractCmd, rest.MigrateProposalHandler), + // TODO: enable rest + //govclient.NewProposalHandler(cli.ProposalExecuteContractCmd, rest.ExecuteProposalHandler), + //govclient.NewProposalHandler(cli.ProposalSudoContractCmd, rest.SudoProposalHandler), govclient.NewProposalHandler(cli.ProposalUpdateContractAdminCmd, rest.UpdateContractAdminProposalHandler), govclient.NewProposalHandler(cli.ProposalClearContractAdminCmd, rest.ClearContractAdminProposalHandler), govclient.NewProposalHandler(cli.ProposalPinCodesCmd, rest.PinCodeProposalHandler), From fb1240c29a8d279052cad1c7b7d49379e7fa86c1 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 13:11:05 +0100 Subject: [PATCH 06/13] Add rest routes for proposals; --- x/wasm/client/proposal_handler.go | 5 +- x/wasm/client/rest/gov.go | 89 +++++++++++++++++++++++++++++++ x/wasm/keeper/proposal_handler.go | 1 + 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/x/wasm/client/proposal_handler.go b/x/wasm/client/proposal_handler.go index f6a4be6a45..ad3363ac7a 100644 --- a/x/wasm/client/proposal_handler.go +++ b/x/wasm/client/proposal_handler.go @@ -12,9 +12,8 @@ var ProposalHandlers = []govclient.ProposalHandler{ govclient.NewProposalHandler(cli.ProposalStoreCodeCmd, rest.StoreCodeProposalHandler), govclient.NewProposalHandler(cli.ProposalInstantiateContractCmd, rest.InstantiateProposalHandler), govclient.NewProposalHandler(cli.ProposalMigrateContractCmd, rest.MigrateProposalHandler), - // TODO: enable rest - //govclient.NewProposalHandler(cli.ProposalExecuteContractCmd, rest.ExecuteProposalHandler), - //govclient.NewProposalHandler(cli.ProposalSudoContractCmd, rest.SudoProposalHandler), + govclient.NewProposalHandler(cli.ProposalExecuteContractCmd, rest.ExecuteProposalHandler), + govclient.NewProposalHandler(cli.ProposalSudoContractCmd, rest.SudoProposalHandler), govclient.NewProposalHandler(cli.ProposalUpdateContractAdminCmd, rest.UpdateContractAdminProposalHandler), govclient.NewProposalHandler(cli.ProposalClearContractAdminCmd, rest.ClearContractAdminProposalHandler), govclient.NewProposalHandler(cli.ProposalPinCodesCmd, rest.PinCodeProposalHandler), diff --git a/x/wasm/client/rest/gov.go b/x/wasm/client/rest/gov.go index 05b22d4554..ea17ddafb9 100644 --- a/x/wasm/client/rest/gov.go +++ b/x/wasm/client/rest/gov.go @@ -162,6 +162,95 @@ func MigrateProposalHandler(cliCtx client.Context) govrest.ProposalRESTHandler { } } +type ExecuteProposalJSONReq struct { + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + + Title string `json:"title" yaml:"title"` + Description string `json:"description" yaml:"description"` + + Proposer string `json:"proposer" yaml:"proposer"` + Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + + Contract string `json:"contract" yaml:"contract"` + Msg json.RawMessage `json:"msg" yaml:"msg"` + // RunAs is the role that is passed to the contract's environment + RunAs string `json:"run_as" yaml:"run_as"` +} + +func (s ExecuteProposalJSONReq) Content() govtypes.Content { + return &types.ExecuteContractProposal{ + Title: s.Title, + Description: s.Description, + Contract: s.Contract, + Msg: types.RawContractMessage(s.Msg), + RunAs: s.RunAs, + } +} +func (s ExecuteProposalJSONReq) GetProposer() string { + return s.Proposer +} +func (s ExecuteProposalJSONReq) GetDeposit() sdk.Coins { + return s.Deposit +} +func (s ExecuteProposalJSONReq) GetBaseReq() rest.BaseReq { + return s.BaseReq +} +func ExecuteProposalHandler(cliCtx client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "wasm_execute", + Handler: func(w http.ResponseWriter, r *http.Request) { + var req ExecuteProposalJSONReq + if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { + return + } + toStdTxResponse(cliCtx, w, req) + }, + } +} + +type SudoProposalJSONReq struct { + BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` + + Title string `json:"title" yaml:"title"` + Description string `json:"description" yaml:"description"` + + Proposer string `json:"proposer" yaml:"proposer"` + Deposit sdk.Coins `json:"deposit" yaml:"deposit"` + + Contract string `json:"contract" yaml:"contract"` + Msg json.RawMessage `json:"msg" yaml:"msg"` +} + +func (s SudoProposalJSONReq) Content() govtypes.Content { + return &types.SudoContractProposal{ + Title: s.Title, + Description: s.Description, + Contract: s.Contract, + Msg: types.RawContractMessage(s.Msg), + } +} +func (s SudoProposalJSONReq) GetProposer() string { + return s.Proposer +} +func (s SudoProposalJSONReq) GetDeposit() sdk.Coins { + return s.Deposit +} +func (s SudoProposalJSONReq) GetBaseReq() rest.BaseReq { + return s.BaseReq +} +func SudoProposalHandler(cliCtx client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "wasm_sudo", + Handler: func(w http.ResponseWriter, r *http.Request) { + var req SudoProposalJSONReq + if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) { + return + } + toStdTxResponse(cliCtx, w, req) + }, + } +} + type UpdateAdminJSONReq struct { BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"` diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index 1a0369d0c1..9f44e3b81b 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -2,6 +2,7 @@ package keeper import ( "encoding/hex" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" From 8a9771e8f6dda24d4151dfeb49cc0a0fd2b068fd Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 13:15:36 +0100 Subject: [PATCH 07/13] Add tests for Rest client --- x/wasm/client/proposal_handler_test.go | 70 ++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/x/wasm/client/proposal_handler_test.go b/x/wasm/client/proposal_handler_test.go index f433122dc8..3e82c62e07 100644 --- a/x/wasm/client/proposal_handler_test.go +++ b/x/wasm/client/proposal_handler_test.go @@ -183,6 +183,76 @@ func TestGovRestHandlers(t *testing.T) { }, expCode: http.StatusOK, }, + "execute contract": { + srcPath: "/gov/proposals/wasm_execute", + srcBody: dict{ + "title": "Test Proposal", + "description": "My proposal", + "type": "migrate", + "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + "msg": dict{"foo": "bar"}, + "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", + "deposit": []dict{{"denom": "ustake", "amount": "10"}}, + "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", + "base_req": aBaseReq, + }, + expCode: http.StatusOK, + }, + "execute contract fails with no run_as": { + srcPath: "/gov/proposals/wasm_execute", + srcBody: dict{ + "title": "Test Proposal", + "description": "My proposal", + "type": "migrate", + "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + "msg": dict{"foo": "bar"}, + "deposit": []dict{{"denom": "ustake", "amount": "10"}}, + "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", + "base_req": aBaseReq, + }, + expCode: http.StatusBadRequest, + }, + "execute contract fails with no message": { + srcPath: "/gov/proposals/wasm_execute", + srcBody: dict{ + "title": "Test Proposal", + "description": "My proposal", + "type": "migrate", + "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + "run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz", + "deposit": []dict{{"denom": "ustake", "amount": "10"}}, + "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", + "base_req": aBaseReq, + }, + expCode: http.StatusBadRequest, + }, + "sudo contract": { + srcPath: "/gov/proposals/wasm_sudo", + srcBody: dict{ + "title": "Test Proposal", + "description": "My proposal", + "type": "migrate", + "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + "msg": dict{"foo": "bar"}, + "deposit": []dict{{"denom": "ustake", "amount": "10"}}, + "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", + "base_req": aBaseReq, + }, + expCode: http.StatusOK, + }, + "sudo contract fails with no message": { + srcPath: "/gov/proposals/wasm_sudo", + srcBody: dict{ + "title": "Test Proposal", + "description": "My proposal", + "type": "migrate", + "contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr", + "deposit": []dict{{"denom": "ustake", "amount": "10"}}, + "proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np", + "base_req": aBaseReq, + }, + expCode: http.StatusBadRequest, + }, "update contract admin": { srcPath: "/gov/proposals/wasm_update_admin", srcBody: dict{ From 82f023ce51423aa9413ef36bc6eb25e572951e3a Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 13:44:57 +0100 Subject: [PATCH 08/13] Test execute and sudo proposal handlers --- x/wasm/keeper/proposal_integration_test.go | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index 9338c1dc80..92eed4fd73 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -206,6 +206,119 @@ func TestMigrateProposal(t *testing.T) { assert.Equal(t, types.AttributeKeyResultDataHex, string(em.Events()[1].Attributes[0].Key)) } +func TestExecuteProposal(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, "staking") + govKeeper, bankKeeper := keepers.GovKeeper, keepers.BankKeeper + + exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) + contractAddr := exampleContract.Contract + + // check balance + bal := bankKeeper.GetBalance(ctx, contractAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(100)) + + releaseMsg := struct { + Release struct{} `json:"release"` + }{} + releaseMsgBz, err := json.Marshal(releaseMsg) + require.NoError(t, err) + + // try with runAs that doesn't have pemission + badSrc := types.ExecuteContractProposal{ + Title: "First", + Description: "Beneficiary has no permission to run", + Contract: contractAddr.String(), + Msg: releaseMsgBz, + RunAs: exampleContract.BeneficiaryAddr.String(), + } + + em := sdk.NewEventManager() + + // fails on store - this doesn't have permission + storedProposal, err := govKeeper.SubmitProposal(ctx, &badSrc) + require.Error(t, err) + // balance should not change + bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(100)) + + // try again with the proper run-as + src := types.ExecuteContractProposal{ + Title: "Second", + Description: "Verifier can execute", + Contract: contractAddr.String(), + Msg: releaseMsgBz, + RunAs: exampleContract.VerifierAddr.String(), + } + + em = sdk.NewEventManager() + + // when stored + storedProposal, err = govKeeper.SubmitProposal(ctx, &src) + require.NoError(t, err) + + // and proposal execute + handler := govKeeper.Router().GetRoute(storedProposal.ProposalRoute()) + err = handler(ctx.WithEventManager(em), storedProposal.GetContent()) + require.NoError(t, err) + + // balance should be empty (proper release) + bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(0)) +} + +func TestSudoProposal(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, "staking") + govKeeper, bankKeeper := keepers.GovKeeper, keepers.BankKeeper + + exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) + contractAddr := exampleContract.Contract + _, _, anyAddr := keyPubAddr() + + // check balance + bal := bankKeeper.GetBalance(ctx, contractAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(100)) + bal = bankKeeper.GetBalance(ctx, anyAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(0)) + + type StealMsg struct { + Recipient string `json:"recipient"` + Amount []sdk.Coin `json:"amount"` + } + stealMsg := struct { + Steal StealMsg `json:"steal_funds"` + }{Steal: StealMsg{ + Recipient: anyAddr.String(), + Amount: []sdk.Coin{sdk.NewInt64Coin("denom", 75)}, + }} + stealMsgBz, err := json.Marshal(stealMsg) + require.NoError(t, err) + + // sudo can do anything + src := types.SudoContractProposal{ + Title: "Sudo", + Description: "Steal funds for the verifier", + Contract: contractAddr.String(), + Msg: stealMsgBz, + } + + em := sdk.NewEventManager() + + // when stored + storedProposal, err := govKeeper.SubmitProposal(ctx, &src) + require.NoError(t, err) + + // and proposal execute + handler := govKeeper.Router().GetRoute(storedProposal.ProposalRoute()) + err = handler(ctx.WithEventManager(em), storedProposal.GetContent()) + require.NoError(t, err) + + // balance should be empty (and verifier richer) + bal = bankKeeper.GetBalance(ctx, contractAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(25)) + bal = bankKeeper.GetBalance(ctx, anyAddr, "denom") + require.Equal(t, bal.Amount, sdk.NewInt(75)) +} + func TestAdminProposals(t *testing.T) { var ( otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, types.ContractAddrLen) From 0a96e26fbad8ff67cd130ad151c7f8e968c12d09 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 20:00:01 +0100 Subject: [PATCH 09/13] Remove RunAs from Migrate proposal --- docs/proto/proto-docs.md | 9 +- proto/cosmwasm/wasm/v1/proposal.proto | 9 +- x/wasm/client/cli/gov_tx.go | 9 -- x/wasm/client/rest/gov.go | 3 - x/wasm/keeper/proposal_handler.go | 4 +- x/wasm/types/proposal.go | 8 +- x/wasm/types/proposal.pb.go | 148 +++++++++----------------- x/wasm/types/test_fixtures.go | 1 - 8 files changed, 62 insertions(+), 129 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 41756a7a6f..77202e520a 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -673,7 +673,7 @@ contract. | `description` | [string](#string) | | Description is a human readable text | | `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | | `contract` | [string](#string) | | Contract is the address of the smart contract | -| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo | +| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as execute | @@ -712,10 +712,11 @@ MigrateContractProposal gov proposal content type to migrate a contract. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | `title` | [string](#string) | | Title is a short summary | -| `description` | [string](#string) | | Description is a human readable text | -| `run_as` | [string](#string) | | FIXME: I think this is unused? Migrate has no sender RunAs is the address that is passed to the contract's environment as sender | +| `description` | [string](#string) | | Description is a human readable text + +Note: skipping 3 as this was previously used for unneeded run_as | | `contract` | [string](#string) | | Contract is the address of the smart contract | -| `code_id` | [uint64](#uint64) | | CodeID references the new WASM code | +| `code_id` | [uint64](#uint64) | | CodeID references the new WASM codesudo | | `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on migration | diff --git a/proto/cosmwasm/wasm/v1/proposal.proto b/proto/cosmwasm/wasm/v1/proposal.proto index 56131199cb..58887f3823 100644 --- a/proto/cosmwasm/wasm/v1/proposal.proto +++ b/proto/cosmwasm/wasm/v1/proposal.proto @@ -56,12 +56,11 @@ message MigrateContractProposal { string title = 1; // Description is a human readable text string description = 2; - // FIXME: I think this is unused? Migrate has no sender - // RunAs is the address that is passed to the contract's environment as sender - string run_as = 3; + // Note: skipping 3 as this was previously used for unneeded run_as + // Contract is the address of the smart contract string contract = 4; - // CodeID references the new WASM code + // CodeID references the new WASM codesudo uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; // Msg json encoded message to be passed to the contract on migration bytes msg = 6 [ (gogoproto.casttype) = "RawContractMessage" ]; @@ -90,7 +89,7 @@ message ExecuteContractProposal { string run_as = 3; // Contract is the address of the smart contract string contract = 4; - // Msg json encoded message to be passed to the contract as sudo + // Msg json encoded message to be passed to the contract as execute bytes msg = 5 [ (gogoproto.casttype) = "RawContractMessage" ]; } diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 158f06327f..406d7ae9b4 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -181,13 +181,6 @@ func ProposalMigrateContractCmd() *cobra.Command { return err } - runAs, err := cmd.Flags().GetString(flagRunAs) - if err != nil { - return fmt.Errorf("run-as: %s", err) - } - if len(runAs) == 0 { - return errors.New("run-as address is required") - } proposalTitle, err := cmd.Flags().GetString(cli.FlagTitle) if err != nil { return fmt.Errorf("proposal title: %s", err) @@ -211,7 +204,6 @@ func ProposalMigrateContractCmd() *cobra.Command { Contract: src.Contract, CodeID: src.CodeID, Msg: src.Msg, - RunAs: runAs, } msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) @@ -225,7 +217,6 @@ func ProposalMigrateContractCmd() *cobra.Command { return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) }, } - cmd.Flags().String(flagRunAs, "", "The address that is passed as sender to the contract on proposal execution") // proposal flags cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") diff --git a/x/wasm/client/rest/gov.go b/x/wasm/client/rest/gov.go index ea17ddafb9..73419cf73f 100644 --- a/x/wasm/client/rest/gov.go +++ b/x/wasm/client/rest/gov.go @@ -126,8 +126,6 @@ type MigrateProposalJSONReq struct { Contract string `json:"contract" yaml:"contract"` Code uint64 `json:"code_id" yaml:"code_id"` Msg json.RawMessage `json:"msg" yaml:"msg"` - // RunAs is the role that is passed to the contract's environment - RunAs string `json:"run_as" yaml:"run_as"` } func (s MigrateProposalJSONReq) Content() govtypes.Content { @@ -137,7 +135,6 @@ func (s MigrateProposalJSONReq) Content() govtypes.Content { Contract: s.Contract, CodeID: s.Code, Msg: types.RawContractMessage(s.Msg), - RunAs: s.RunAs, } } func (s MigrateProposalJSONReq) GetProposer() string { diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index 9f44e3b81b..b1f4721479 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -103,11 +103,11 @@ func handleMigrateProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.M if err != nil { return sdkerrors.Wrap(err, "contract") } - runAsAddr, err := sdk.AccAddressFromBech32(p.RunAs) if err != nil { return sdkerrors.Wrap(err, "run as address") } - data, err := k.Migrate(ctx, contractAddr, runAsAddr, p.CodeID, p.Msg) + // runAs is not used if this is permissioned, so just put any valid address there (second contractAddr) + data, err := k.Migrate(ctx, contractAddr, contractAddr, p.CodeID, p.Msg) if err != nil { return err } diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index 97df3b4ae8..21de9cc471 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -245,9 +245,6 @@ func (p MigrateContractProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(p.Contract); err != nil { return sdkerrors.Wrap(err, "contract") } - if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { - return sdkerrors.Wrap(err, "run as") - } if err := p.Msg.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "payload msg") } @@ -261,9 +258,8 @@ func (p MigrateContractProposal) String() string { Description: %s Contract: %s Code id: %d - Run as: %s Msg %q -`, p.Title, p.Description, p.Contract, p.CodeID, p.RunAs, p.Msg) +`, p.Title, p.Description, p.Contract, p.CodeID, p.Msg) } // MarshalYAML pretty prints the migrate message @@ -274,14 +270,12 @@ func (p MigrateContractProposal) MarshalYAML() (interface{}, error) { Contract string `yaml:"contract"` CodeID uint64 `yaml:"code_id"` Msg string `yaml:"msg"` - RunAs string `yaml:"run_as"` }{ Title: p.Title, Description: p.Description, Contract: p.Contract, CodeID: p.CodeID, Msg: string(p.Msg), - RunAs: p.RunAs, }, nil } diff --git a/x/wasm/types/proposal.pb.go b/x/wasm/types/proposal.pb.go index a80392b383..677ce9267e 100644 --- a/x/wasm/types/proposal.pb.go +++ b/x/wasm/types/proposal.pb.go @@ -131,12 +131,9 @@ type MigrateContractProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` // Description is a human readable text Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` - // FIXME: I think this is unused? Migrate has no sender - // RunAs is the address that is passed to the contract's environment as sender - RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` // Contract is the address of the smart contract Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` - // CodeID references the new WASM code + // CodeID references the new WASM codesudo CodeID uint64 `protobuf:"varint,5,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` // Msg json encoded message to be passed to the contract on migration Msg RawContractMessage `protobuf:"bytes,6,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` @@ -229,7 +226,7 @@ type ExecuteContractProposal struct { RunAs string `protobuf:"bytes,3,opt,name=run_as,json=runAs,proto3" json:"run_as,omitempty"` // Contract is the address of the smart contract Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` - // Msg json encoded message to be passed to the contract as sudo + // Msg json encoded message to be passed to the contract as execute Msg RawContractMessage `protobuf:"bytes,5,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` } @@ -453,53 +450,54 @@ func init() { func init() { proto.RegisterFile("cosmwasm/wasm/v1/proposal.proto", fileDescriptor_be6422d717c730cb) } var fileDescriptor_be6422d717c730cb = []byte{ - // 732 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xcd, 0x36, 0x89, 0x93, 0x6e, 0x23, 0x08, 0x26, 0x6d, 0x43, 0x41, 0x76, 0x64, 0xa4, 0xca, - 0x17,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b, 0xd6, 0xde, 0x01, 0x58, 0xde, 0xf0, 0x02, 0x3e, 0x90, 0x74, 0x42, - 0xb4, 0x7c, 0x8a, 0xc8, 0x2a, 0x8f, 0x62, 0xb5, 0x24, 0x3a, 0x49, 0x6e, 0x6b, 0x63, 0xea, 0x07, - 0x3f, 0xa1, 0xb6, 0x16, 0x46, 0xb1, 0x2a, 0x0b, 0xf4, 0x54, 0x52, 0x3b, 0x2d, 0xe9, 0x21, 0x97, - 0x94, 0xac, 0x05, 0x7f, 0xbd, 0x59, 0x3d, 0x67, 0x29, 0xc3, 0x58, 0x2d, 0x88, 0xbd, 0xa0, 0xa3, - 0x58, 0xbd, 0x2a, 0x9e, 0x30, 0x06, 0x69, 0x76, 0x41, 0xec, 0x0a, 0xd5, 0xde, 0x03, 0x28, 0x6f, - 0x05, 0xe1, 0xff, 0xa4, 0xd9, 0x7a, 0x7a, 0x70, 0xac, 0x64, 0x8e, 0x8e, 0x95, 0xcc, 0xeb, 0xa1, - 0x02, 0x0e, 0x86, 0x0a, 0x38, 0x1c, 0x2a, 0xe0, 0xf3, 0x50, 0x01, 0x2f, 0x4e, 0x94, 0xcc, 0xe1, - 0x89, 0x92, 0x39, 0x3a, 0x51, 0x32, 0xcf, 0x96, 0xa7, 0xbe, 0x71, 0x4d, 0x42, 0xfd, 0xed, 0xf1, - 0x41, 0xe9, 0x9a, 0xfb, 0xe2, 0xc0, 0x4c, 0xbe, 0x73, 0x6d, 0x29, 0x39, 0x2e, 0xef, 0x7d, 0x0b, - 0x00, 0x00, 0xff, 0xff, 0x7a, 0x1d, 0x54, 0x9b, 0xb7, 0x07, 0x00, 0x00, + // 738 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0x41, 0x4f, 0xdb, 0x48, + 0x14, 0xce, 0x90, 0xc4, 0x09, 0x43, 0xb4, 0x9b, 0xf5, 0x06, 0xc8, 0xb2, 0x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8d, 0x18, 0x87, + 0x50, 0x6d, 0xf7, 0x31, 0x8a, 0x6f, 0x87, 0xdc, 0x35, 0xdf, 0xd8, 0x78, 0x05, 0x60, 0x75, 0x27, + 0x20, 0xc2, 0x90, 0x6c, 0x06, 0xb4, 0x7e, 0x09, 0xc8, 0xa9, 0x4e, 0x12, 0xbd, 0x22, 0x77, 0x92, + 0xbe, 0x36, 0xa6, 0xd0, 0xff, 0x7d, 0x05, 0xda, 0x59, 0x99, 0x24, 0xba, 0x2a, 0xab, 0xe7, 0x92, + 0xc6, 0x65, 0x4a, 0xff, 0x0b, 0x4a, 0xe9, 0x58, 0x88, 0xcf, 0x9b, 0x37, 0x0b, 0x8e, 0x36, 0x4e, + 0xf4, 0x92, 0x9c, 0x0b, 0x36, 0x49, 0xf4, 0x9f, 0xe5, 0x0a, 0xd3, 0x22, 0xc3, 0x2d, 0xc9, 0x59, + 0x61, 0xc6, 0x6b, 0x00, 0xd5, 0x3d, 0x12, 0xfd, 0x48, 0x9c, 0x9d, 0x87, 0x27, 0xe7, 0x5a, 0xee, + 0xec, 0x5c, 0xcb, 0x3d, 0x1f, 0x6b, 0xe0, 0x64, 0xac, 0x81, 0xd3, 0xb1, 0x06, 0xde, 0x8f, 0x35, + 0xf0, 0xe4, 0x42, 0xcb, 0x9d, 0x5e, 0x68, 0xb9, 0xb3, 0x0b, 0x2d, 0xf7, 0x68, 0x7d, 0xee, 0x30, + 0x6b, 0x53, 0x16, 0xee, 0x4f, 0x6f, 0x44, 0xdf, 0x3e, 0x96, 0x37, 0x63, 0x7a, 0xa0, 0x75, 0x95, + 0xf4, 0x5e, 0xfc, 0xe7, 0x53, 0x00, 0x00, 0x00, 0xff, 0xff, 0x34, 0xa1, 0x57, 0x17, 0xa0, 0x07, + 0x00, 0x00, } func (this *StoreCodeProposal) Equal(that interface{}) bool { @@ -613,9 +611,6 @@ func (this *MigrateContractProposal) Equal(that interface{}) bool { if this.Description != that1.Description { return false } - if this.RunAs != that1.RunAs { - return false - } if this.Contract != that1.Contract { return false } @@ -1015,13 +1010,6 @@ func (m *MigrateContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) i-- dAtA[i] = 0x22 } - if len(m.RunAs) > 0 { - i -= len(m.RunAs) - copy(dAtA[i:], m.RunAs) - i = encodeVarintProposal(dAtA, i, uint64(len(m.RunAs))) - i-- - dAtA[i] = 0x1a - } if len(m.Description) > 0 { i -= len(m.Description) copy(dAtA[i:], m.Description) @@ -1449,10 +1437,6 @@ func (m *MigrateContractProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } - l = len(m.RunAs) - if l > 0 { - n += 1 + l + sovProposal(uint64(l)) - } l = len(m.Contract) if l > 0 { n += 1 + l + sovProposal(uint64(l)) @@ -2227,38 +2211,6 @@ func (m *MigrateContractProposal) Unmarshal(dAtA []byte) error { } m.Description = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field RunAs", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowProposal - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthProposal - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthProposal - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.RunAs = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Contract", wireType) diff --git a/x/wasm/types/test_fixtures.go b/x/wasm/types/test_fixtures.go index 1c74771f31..568c4f7c91 100644 --- a/x/wasm/types/test_fixtures.go +++ b/x/wasm/types/test_fixtures.go @@ -249,7 +249,6 @@ func MigrateContractProposalFixture(mutators ...func(p *MigrateContractProposal) Contract: contractAddr, CodeID: 1, Msg: migMsgBz, - RunAs: anyAddress, } for _, m := range mutators { From 6a2a9d0bfa39e49d19e9ee4098c739424143c2ea Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 20:23:20 +0100 Subject: [PATCH 10/13] fix tests --- x/wasm/keeper/proposal_integration_test.go | 1 - x/wasm/types/proposal_test.go | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/x/wasm/keeper/proposal_integration_test.go b/x/wasm/keeper/proposal_integration_test.go index 92eed4fd73..a943003e55 100644 --- a/x/wasm/keeper/proposal_integration_test.go +++ b/x/wasm/keeper/proposal_integration_test.go @@ -166,7 +166,6 @@ func TestMigrateProposal(t *testing.T) { CodeID: 2, Contract: contractAddr.String(), Msg: migMsgBz, - RunAs: otherAddress.String(), } em := sdk.NewEventManager() diff --git a/x/wasm/types/proposal_test.go b/x/wasm/types/proposal_test.go index aac9c73d02..70f6bc76a0 100644 --- a/x/wasm/types/proposal_test.go +++ b/x/wasm/types/proposal_test.go @@ -304,18 +304,6 @@ func TestValidateMigrateContractProposal(t *testing.T) { }), expErr: true, }, - "run_as missing": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.RunAs = "" - }), - expErr: true, - }, - "run_as invalid": { - src: MigrateContractProposalFixture(func(p *MigrateContractProposal) { - p.RunAs = invalidAddress - }), - expErr: true, - }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { @@ -491,7 +479,6 @@ func TestProposalStrings(t *testing.T) { Description: Bar Contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr Code id: 1 - Run as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 Msg "{\"verifier\":\"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4\"}" `, }, @@ -609,7 +596,6 @@ description: Bar contract: cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr code_id: 1 msg: '{"verifier":"cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4"}' -run_as: cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs2m6sx4 `, }, "update admin": { @@ -733,7 +719,6 @@ func TestUnmarshalContentFromJson(t *testing.T) { exp: &MigrateContractProposal{ Title: "foo", Description: "bar", - RunAs: "myRunAsAddress", Contract: "myContractAddr", CodeID: 1, Msg: []byte("{}"), From fb568e3ef7099fabe61ac32e9e1258da10e583da Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 21:17:35 +0100 Subject: [PATCH 11/13] Allow sending tokens along with governance wasm_execute proposal --- docs/proto/proto-docs.md | 1 + proto/cosmwasm/wasm/v1/proposal.proto | 5 + x/wasm/client/cli/gov_tx.go | 12 +- x/wasm/client/rest/gov.go | 4 +- x/wasm/keeper/proposal_handler.go | 3 +- x/wasm/types/proposal.go | 20 ++-- x/wasm/types/proposal.pb.go | 160 ++++++++++++++++++-------- 7 files changed, 146 insertions(+), 59 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 77202e520a..dd8dc7f203 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -674,6 +674,7 @@ contract. | `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender | | `contract` | [string](#string) | | Contract is the address of the smart contract | | `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as execute | +| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation | diff --git a/proto/cosmwasm/wasm/v1/proposal.proto b/proto/cosmwasm/wasm/v1/proposal.proto index 58887f3823..2f36f87f94 100644 --- a/proto/cosmwasm/wasm/v1/proposal.proto +++ b/proto/cosmwasm/wasm/v1/proposal.proto @@ -91,6 +91,11 @@ message ExecuteContractProposal { string contract = 4; // Msg json encoded message to be passed to the contract as execute bytes msg = 5 [ (gogoproto.casttype) = "RawContractMessage" ]; + // Funds coins that are transferred to the contract on instantiation + repeated cosmos.base.v1beta1.Coin funds = 6 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; } // UpdateAdminProposal gov proposal content type to set an admin for a contract. diff --git a/x/wasm/client/cli/gov_tx.go b/x/wasm/client/cli/gov_tx.go index 406d7ae9b4..28f892ed1a 100644 --- a/x/wasm/client/cli/gov_tx.go +++ b/x/wasm/client/cli/gov_tx.go @@ -241,11 +241,19 @@ func ProposalExecuteContractCmd() *cobra.Command { contract := args[0] execMsg := []byte(args[1]) - + amountStr, err := cmd.Flags().GetString(flagAmount) + if err != nil { + return fmt.Errorf("amount: %s", err) + } + funds, err := sdk.ParseCoinsNormalized(amountStr) + if err != nil { + return fmt.Errorf("amount: %s", err) + } runAs, err := cmd.Flags().GetString(flagRunAs) if err != nil { return fmt.Errorf("run-as: %s", err) } + if len(runAs) == 0 { return errors.New("run-as address is required") } @@ -272,6 +280,7 @@ func ProposalExecuteContractCmd() *cobra.Command { Contract: contract, Msg: execMsg, RunAs: runAs, + Funds: funds, } msg, err := govtypes.NewMsgSubmitProposal(&content, deposit, clientCtx.GetFromAddress()) @@ -286,6 +295,7 @@ func ProposalExecuteContractCmd() *cobra.Command { }, } cmd.Flags().String(flagRunAs, "", "The address that is passed as sender to the contract on proposal execution") + cmd.Flags().String(flagAmount, "", "Coins to send to the contract during instantiation") // proposal flags cmd.Flags().String(cli.FlagTitle, "", "Title of proposal") diff --git a/x/wasm/client/rest/gov.go b/x/wasm/client/rest/gov.go index 73419cf73f..5178b29852 100644 --- a/x/wasm/client/rest/gov.go +++ b/x/wasm/client/rest/gov.go @@ -171,7 +171,8 @@ type ExecuteProposalJSONReq struct { Contract string `json:"contract" yaml:"contract"` Msg json.RawMessage `json:"msg" yaml:"msg"` // RunAs is the role that is passed to the contract's environment - RunAs string `json:"run_as" yaml:"run_as"` + RunAs string `json:"run_as" yaml:"run_as"` + Funds sdk.Coins `json:"funds" yaml:"funds"` } func (s ExecuteProposalJSONReq) Content() govtypes.Content { @@ -181,6 +182,7 @@ func (s ExecuteProposalJSONReq) Content() govtypes.Content { Contract: s.Contract, Msg: types.RawContractMessage(s.Msg), RunAs: s.RunAs, + Funds: s.Funds, } } func (s ExecuteProposalJSONReq) GetProposer() string { diff --git a/x/wasm/keeper/proposal_handler.go b/x/wasm/keeper/proposal_handler.go index b1f4721479..79f6a9fc30 100644 --- a/x/wasm/keeper/proposal_handler.go +++ b/x/wasm/keeper/proposal_handler.go @@ -153,8 +153,7 @@ func handleExecuteProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.E if err != nil { return sdkerrors.Wrap(err, "run as address") } - // we currently don't support sending tokens as part of an execute proposal. should we? from which account? - data, err := k.Execute(ctx, contractAddr, runAsAddr, p.Msg, nil) + data, err := k.Execute(ctx, contractAddr, runAsAddr, p.Msg, p.Funds) if err != nil { return err } diff --git a/x/wasm/types/proposal.go b/x/wasm/types/proposal.go index 21de9cc471..710193753b 100644 --- a/x/wasm/types/proposal.go +++ b/x/wasm/types/proposal.go @@ -353,6 +353,9 @@ func (p ExecuteContractProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(p.RunAs); err != nil { return sdkerrors.Wrap(err, "run as") } + if !p.Funds.IsValid() { + return sdkerrors.ErrInvalidCoins + } if err := p.Msg.ValidateBasic(); err != nil { return sdkerrors.Wrap(err, "payload msg") } @@ -366,24 +369,27 @@ func (p ExecuteContractProposal) String() string { Description: %s Contract: %s Run as: %s - Msg %q -`, p.Title, p.Description, p.Contract, p.RunAs, p.Msg) + Msg: %q + Funds: %s +`, p.Title, p.Description, p.Contract, p.RunAs, p.Msg, p.Funds) } // MarshalYAML pretty prints the migrate message func (p ExecuteContractProposal) MarshalYAML() (interface{}, error) { return struct { - Title string `yaml:"title"` - Description string `yaml:"description"` - Contract string `yaml:"contract"` - Msg string `yaml:"msg"` - RunAs string `yaml:"run_as"` + Title string `yaml:"title"` + Description string `yaml:"description"` + Contract string `yaml:"contract"` + Msg string `yaml:"msg"` + RunAs string `yaml:"run_as"` + Funds sdk.Coins `yaml:"funds"` }{ Title: p.Title, Description: p.Description, Contract: p.Contract, Msg: string(p.Msg), RunAs: p.RunAs, + Funds: p.Funds, }, nil } diff --git a/x/wasm/types/proposal.pb.go b/x/wasm/types/proposal.pb.go index 677ce9267e..2f075be4c6 100644 --- a/x/wasm/types/proposal.pb.go +++ b/x/wasm/types/proposal.pb.go @@ -228,6 +228,8 @@ type ExecuteContractProposal struct { Contract string `protobuf:"bytes,4,opt,name=contract,proto3" json:"contract,omitempty"` // Msg json encoded message to be passed to the contract as execute Msg RawContractMessage `protobuf:"bytes,5,opt,name=msg,proto3,casttype=RawContractMessage" json:"msg,omitempty"` + // Funds coins that are transferred to the contract on instantiation + Funds github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=funds,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"funds"` } func (m *ExecuteContractProposal) Reset() { *m = ExecuteContractProposal{} } @@ -450,54 +452,54 @@ func init() { func init() { proto.RegisterFile("cosmwasm/wasm/v1/proposal.proto", fileDescriptor_be6422d717c730cb) } var fileDescriptor_be6422d717c730cb = []byte{ - // 738 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0x41, 0x4f, 0xdb, 0x48, - 0x14, 0xce, 0x90, 0xc4, 0x09, 0x43, 0xb4, 0x9b, 0xf5, 0x06, 0xc8, 0xb2, 0x2b, 0x3b, 0xf2, 0x4a, - 0xc8, 0x97, 0xb5, 0x37, 0xac, 0xb4, 0xda, 0xed, 0x2d, 0x4e, 0x7b, 0x00, 0x15, 0x09, 0x19, 0x21, - 0xa4, 0x5e, 0xa2, 0x89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xb4, 0x7e, 0x09, 0xc8, 0xa9, 0x4e, 0x12, 0xbd, 0x22, 0x77, 0x92, - 0xbe, 0x36, 0xa6, 0xd0, 0xff, 0x7d, 0x05, 0xda, 0x59, 0x99, 0x24, 0xba, 0x2a, 0xab, 0xe7, 0x92, - 0xc6, 0x65, 0x4a, 0xff, 0x0b, 0x4a, 0xe9, 0x58, 0x88, 0xcf, 0x9b, 0x37, 0x0b, 0x8e, 0x36, 0x4e, - 0xf4, 0x92, 0x9c, 0x0b, 0x36, 0x49, 0xf4, 0x9f, 0xe5, 0x0a, 0xd3, 0x22, 0xc3, 0x2d, 0xc9, 0x59, - 0x61, 0xc6, 0x6b, 0x00, 0xd5, 0x3d, 0x12, 0xfd, 0x48, 0x9c, 0x9d, 0x87, 0x27, 0xe7, 0x5a, 0xee, - 0xec, 0x5c, 0xcb, 0x3d, 0x1f, 0x6b, 0xe0, 0x64, 0xac, 0x81, 0xd3, 0xb1, 0x06, 0xde, 0x8f, 0x35, - 0xf0, 0xe4, 0x42, 0xcb, 0x9d, 0x5e, 0x68, 0xb9, 0xb3, 0x0b, 0x2d, 0xf7, 0x68, 0x7d, 0xee, 0x30, - 0x6b, 0x53, 0x16, 0xee, 0x4f, 0x6f, 0x44, 0xdf, 0x3e, 0x96, 0x37, 0x63, 0x7a, 0xa0, 0x75, 0x95, - 0xf4, 0x5e, 0xfc, 0xe7, 0x53, 0x00, 0x00, 0x00, 0xff, 0xff, 0x34, 0xa1, 0x57, 0x17, 0xa0, 0x07, - 0x00, 0x00, + // 737 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xc1, 0x6e, 0xd3, 0x4a, + 0x14, 0x8d, 0x9b, 0xc4, 0x49, 0xa7, 0xd1, 0x7b, 0x79, 0x7e, 0x69, 0x1b, 0x0a, 0xb2, 0x23, 0x23, + 0x55, 0xde, 0x60, 0x93, 0x22, 0x21, 0x60, 0x17, 0x07, 0x16, 0xad, 0xa8, 0x54, 0xb9, 0xaa, 0x2a, + 0xb1, 0x89, 0x26, 0xf6, 0x34, 0xb5, 0x88, 0x67, 0x2c, 0xcf, 0xa4, 0x69, 0xfe, 0x02, 0x24, 0x96, + 0x7c, 0x00, 0x62, 0x83, 0xd8, 0xf3, 0x01, 0x15, 0xab, 0x2e, 0xbb, 0x32, 0x34, 0xfd, 0x83, 0x2c, + 0x91, 0x90, 0xd0, 0x78, 0x9c, 0x90, 0x16, 0xd4, 0x82, 0x68, 0x16, 0x6c, 0x9c, 0x5c, 0xdf, 0x73, + 0xe7, 0x1c, 0x1f, 0x9d, 0xab, 0x01, 0x9a, 0x4b, 0x68, 0xd0, 0x87, 0x34, 0xb0, 0x92, 0xc7, 0x41, + 0xdd, 0x0a, 0x23, 0x12, 0x12, 0x0a, 0xbb, 0x66, 0x18, 0x11, 0x46, 0x94, 0xf2, 0x18, 0x60, 0x26, + 0x8f, 0x83, 0xfa, 0x4a, 0xa5, 0x43, 0x3a, 0x24, 0x69, 0x5a, 0xfc, 0x9f, 0xc0, 0xad, 0xa8, 0x1c, + 0x47, 0xa8, 0xd5, 0x86, 0x14, 0x59, 0x07, 0xf5, 0x36, 0x62, 0xb0, 0x6e, 0xb9, 0xc4, 0xc7, 0x69, + 0xff, 0xd6, 0x0f, 0x44, 0x6c, 0x10, 0x22, 0x2a, 0xba, 0xfa, 0x57, 0x09, 0xfc, 0xb7, 0xcd, 0x48, + 0x84, 0x9a, 0xc4, 0x43, 0x5b, 0xa9, 0x02, 0xa5, 0x02, 0xf2, 0xcc, 0x67, 0x5d, 0x54, 0x95, 0x6a, + 0x92, 0x31, 0xef, 0x88, 0x42, 0xa9, 0x81, 0x05, 0x0f, 0x51, 0x37, 0xf2, 0x43, 0xe6, 0x13, 0x5c, + 0x9d, 0x4b, 0x7a, 0xd3, 0xaf, 0x94, 0x45, 0x20, 0x47, 0x3d, 0xdc, 0x82, 0xb4, 0x9a, 0x15, 0x83, + 0x51, 0x0f, 0x37, 0xa8, 0x72, 0x1f, 0xfc, 0xc3, 0xb9, 0x5b, 0xed, 0x01, 0x43, 0x2d, 0x97, 0x78, + 0xa8, 0x9a, 0xab, 0x49, 0x46, 0xc9, 0x2e, 0x0f, 0x63, 0xad, 0xb4, 0xdb, 0xd8, 0xde, 0xb4, 0x07, + 0x2c, 0x11, 0xe0, 0x94, 0x38, 0x6e, 0x5c, 0x29, 0x3b, 0x60, 0xc9, 0xc7, 0x94, 0x41, 0xcc, 0x7c, + 0xc8, 0x50, 0x2b, 0x44, 0x51, 0xe0, 0x53, 0xca, 0xb9, 0x0b, 0x35, 0xc9, 0x58, 0x58, 0x53, 0xcd, + 0x8b, 0x1e, 0x99, 0x0d, 0xd7, 0x45, 0x94, 0x36, 0x09, 0xde, 0xf3, 0x3b, 0xce, 0xe2, 0xd4, 0xf4, + 0xd6, 0x64, 0x78, 0x23, 0x57, 0xcc, 0x97, 0xe5, 0x8d, 0x5c, 0x51, 0x2e, 0x17, 0xf4, 0x8f, 0x73, + 0xe0, 0xe6, 0xfa, 0x77, 0x54, 0x93, 0x60, 0x16, 0x41, 0x97, 0xcd, 0xca, 0x89, 0x0a, 0xc8, 0x43, + 0x2f, 0xf0, 0x71, 0x62, 0xc0, 0xbc, 0x23, 0x0a, 0xe5, 0x36, 0x28, 0x70, 0x57, 0x5a, 0xbe, 0x57, + 0xcd, 0xd7, 0x24, 0x23, 0x67, 0x83, 0x61, 0xac, 0xc9, 0xdc, 0x82, 0xf5, 0xc7, 0x8e, 0xcc, 0x5b, + 0xeb, 0x1e, 0x1f, 0xed, 0xc2, 0x36, 0xea, 0x56, 0x65, 0x31, 0x9a, 0x14, 0x8a, 0x01, 0xb2, 0x01, + 0xed, 0x24, 0x7e, 0x94, 0xec, 0xa5, 0x2f, 0xb1, 0xa6, 0x38, 0xb0, 0x3f, 0xfe, 0x8a, 0x4d, 0x44, + 0x29, 0xec, 0x20, 0x87, 0x43, 0x14, 0x08, 0xf2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12, 0x28, 0x6f, + 0xf9, 0x98, 0x67, 0x9e, 0x4e, 0x88, 0x56, 0xcf, 0x11, 0xd9, 0xe5, 0x51, 0xac, 0x95, 0xc4, 0x97, + 0x24, 0xaf, 0xf5, 0x31, 0xf5, 0x83, 0x9f, 0x50, 0xdb, 0x4b, 0xa3, 0x58, 0x53, 0x04, 0x7a, 0xaa, + 0xa9, 0x9f, 0x97, 0xf4, 0x90, 0x4b, 0x4a, 0x36, 0x8f, 0x27, 0x28, 0x6b, 0xe4, 0x6c, 0x75, 0x18, + 0x6b, 0x05, 0xb1, 0x7a, 0x74, 0x14, 0x6b, 0xff, 0x8a, 0x13, 0xc6, 0x20, 0xdd, 0x29, 0x88, 0x75, + 0xa4, 0xfa, 0x7b, 0x09, 0x28, 0x3b, 0x38, 0xfc, 0x9b, 0x34, 0xdb, 0x4f, 0x8f, 0x4e, 0xd5, 0xcc, + 0xc9, 0xa9, 0x9a, 0x79, 0x33, 0x54, 0xa5, 0xa3, 0xa1, 0x2a, 0x1d, 0x0f, 0x55, 0xe9, 0xf3, 0x50, + 0x95, 0x5e, 0x9c, 0xa9, 0x99, 0xe3, 0x33, 0x35, 0x73, 0x72, 0xa6, 0x66, 0x9e, 0xad, 0x4e, 0xa5, + 0xb8, 0x49, 0x68, 0xb0, 0x3b, 0xbe, 0x74, 0x3d, 0xeb, 0x50, 0x5c, 0xbe, 0x49, 0x92, 0xdb, 0x72, + 0x72, 0xf5, 0xde, 0xfb, 0x16, 0x00, 0x00, 0xff, 0xff, 0x51, 0xe8, 0xe8, 0x8c, 0x03, 0x08, 0x00, + 0x00, } func (this *StoreCodeProposal) Equal(that interface{}) bool { @@ -689,6 +691,14 @@ func (this *ExecuteContractProposal) Equal(that interface{}) bool { if !bytes.Equal(this.Msg, that1.Msg) { return false } + if len(this.Funds) != len(that1.Funds) { + return false + } + for i := range this.Funds { + if !this.Funds[i].Equal(&that1.Funds[i]) { + return false + } + } return true } func (this *UpdateAdminProposal) Equal(that interface{}) bool { @@ -1098,6 +1108,20 @@ func (m *ExecuteContractProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.Funds) > 0 { + for iNdEx := len(m.Funds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Funds[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintProposal(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } if len(m.Msg) > 0 { i -= len(m.Msg) copy(dAtA[i:], m.Msg) @@ -1502,6 +1526,12 @@ func (m *ExecuteContractProposal) Size() (n int) { if l > 0 { n += 1 + l + sovProposal(uint64(l)) } + if len(m.Funds) > 0 { + for _, e := range m.Funds { + l = e.Size() + n += 1 + l + sovProposal(uint64(l)) + } + } return n } @@ -2688,6 +2718,40 @@ func (m *ExecuteContractProposal) Unmarshal(dAtA []byte) error { m.Msg = []byte{} } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowProposal + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthProposal + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthProposal + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Funds = append(m.Funds, types.Coin{}) + if err := m.Funds[len(m.Funds)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipProposal(dAtA[iNdEx:]) From 95ba0df0887a9090c0c7d6bb24484116f46df9ea Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 21:21:31 +0100 Subject: [PATCH 12/13] Update CHANGELOG --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c019fab6..932685b43a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,12 +20,13 @@ - Go 1.17 provides a much clearer go.mod file [\#679](https://github.com/CosmWasm/wasmd/pull/679) ([faddat](https://github.com/faddat)) - Autopin wasm code uploaded by gov proposal [\#726](https://github.com/CosmWasm/wasmd/pull/726) ([ethanfrey](https://github.com/ethanfrey)) - You must explicitly declare --no-admin on cli instantiate if that is what you want [\#727](https://github.com/CosmWasm/wasmd/pull/727) ([ethanfrey](https://github.com/ethanfrey)) - +- Add governance proposals for Wasm Execute and Sudo [\#730](https://github.com/CosmWasm/wasmd/pull/730) ([ethanfrey](https://github.com/ethanfrey)) +- Remove unused run-as flag from Wasm Migrate proposals [\#730](https://github.com/CosmWasm/wasmd/pull/730) ([ethanfrey](https://github.com/ethanfrey)) +- Expose wasm/Keeper.SetParams [\#732](https://github.com/CosmWasm/wasmd/pull/732) ([ethanfrey](https://github.com/ethanfrey)) [Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.22.0...v0.21.0) - ## [v0.21.0](https://github.com/CosmWasm/wasmd/tree/v0.21.0) (2021-11-17) [Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.21.0...v0.20.0) From 20ed020fa7ae63f931adb0bd30232f142f7e3b87 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 24 Jan 2022 21:25:48 +0100 Subject: [PATCH 13/13] Update documentation --- x/wasm/Governance.md | 9 +++++---- x/wasm/keeper/keeper.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x/wasm/Governance.md b/x/wasm/Governance.md index 39295a0d7b..f26c0c5a5a 100644 --- a/x/wasm/Governance.md +++ b/x/wasm/Governance.md @@ -6,19 +6,20 @@ a high-level, technical introduction meant to provide context before looking into the code, or constructing proposals. ## Proposal Types -We have added 5 new wasm specific proposal types that cover the contract's live cycle and authorization: +We have added 9 new wasm specific proposal types that cover the contract's live cycle and authorization: * `StoreCodeProposal` - upload a wasm binary * `InstantiateContractProposal` - instantiate a wasm contract * `MigrateContractProposal` - migrate a wasm contract to a new code version +* `SudoContractProposal` - call into the protected `sudo` entry point of a contract +* `ExecuteContractProposal` - execute a wasm contract as an arbitrary user * `UpdateAdminProposal` - set a new admin for a contract * `ClearAdminProposal` - clear admin for a contract to prevent further migrations +* `PinCodes` - pin the given code ids in cache. This trades memory for reduced startup time and lowers gas cost +* `UnpinCodes` - unpin the given code ids from the cache. This frees up memory and returns to standard speed and gas cost For details see the proposal type [implementation](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/proposal.go) -A wasm message but no proposal type: -* `ExecuteContract` - execute a command on a wasm contract - ### Unit tests [Proposal type validations](https://github.com/CosmWasm/wasmd/blob/master/x/wasm/types/proposal_test.go) diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index 5980782eec..b56faa1638 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -438,9 +438,9 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller return data, nil } -// Sudo allows priviledged access to a contract. This can never be called by governance or external tx, but only by -// another native Go module directly. Thus, the keeper doesn't place any access controls on it, that is the -// responsibility or the app developer (who passes the wasm.Keeper in app.go) +// Sudo allows priviledged access to a contract. This can never be called by an external tx, but only by +// another native Go module directly, or on-chain governance (if sudo proposals are enabled). Thus, the keeper doesn't +// place any access controls on it, that is the responsibility or the app developer (who passes the wasm.Keeper in app.go) func (k Keeper) Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error) { defer telemetry.MeasureSince(time.Now(), "wasm", "contract", "sudo") contractInfo, codeInfo, prefixStore, err := k.contractInstance(ctx, contractAddress)