From 460e0e6123f98bc08977f4b0c978d9b34efc8451 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 19 Oct 2023 12:12:28 +0530 Subject: [PATCH 01/20] adding x/authority proto files --- docs/proto/proto-docs.md | 279 +------- .../stargaze/authority/v1/authority.proto | 0 .../stargaze/authority/v1/genesis.proto | 8 + .../stargaze/authority/v1/tx.proto | 26 + x/authority/types/genesis.pb.go | 268 ++++++++ x/authority/types/tx.pb.go | 599 ++++++++++++++++++ 6 files changed, 927 insertions(+), 253 deletions(-) create mode 100644 proto/publicawesome/stargaze/authority/v1/authority.proto create mode 100644 proto/publicawesome/stargaze/authority/v1/genesis.proto create mode 100644 proto/publicawesome/stargaze/authority/v1/tx.proto create mode 100644 x/authority/types/genesis.pb.go create mode 100644 x/authority/types/tx.pb.go diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index bb766e02b..0936d9bcb 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,57 +4,24 @@ ## Table of Contents -- [publicawesome/stargaze/cron/v1/cron.proto](#publicawesome/stargaze/cron/v1/cron.proto) - - [Params](#publicawesome.stargaze.cron.v1.Params) +- [publicawesome/stargaze/authority/v1/authority.proto](#publicawesome/stargaze/authority/v1/authority.proto) +- [publicawesome/stargaze/authority/v1/genesis.proto](#publicawesome/stargaze/authority/v1/genesis.proto) + - [GenesisState](#publicawesome.stargaze.authority.v1.GenesisState) -- [publicawesome/stargaze/cron/v1/genesis.proto](#publicawesome/stargaze/cron/v1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.cron.v1.GenesisState) +- [publicawesome/stargaze/authority/v1/tx.proto](#publicawesome/stargaze/authority/v1/tx.proto) + - [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) + - [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) -- [publicawesome/stargaze/cron/v1/proposal.proto](#publicawesome/stargaze/cron/v1/proposal.proto) - - [DemotePrivilegedContractProposal](#publicawesome.stargaze.cron.v1.DemotePrivilegedContractProposal) - - [PromoteToPrivilegedContractProposal](#publicawesome.stargaze.cron.v1.PromoteToPrivilegedContractProposal) - -- [publicawesome/stargaze/cron/v1/query.proto](#publicawesome/stargaze/cron/v1/query.proto) - - [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) - - [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) - - [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) - - [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) - - - [Query](#publicawesome.stargaze.cron.v1.Query) - -- [publicawesome/stargaze/cron/v1/tx.proto](#publicawesome/stargaze/cron/v1/tx.proto) - - [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) - - [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) - - [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) - - [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) - - [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) - - [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) - - - [Msg](#publicawesome.stargaze.cron.v1.Msg) + - [Msg](#publicawesome.stargaze.authority.v1.Msg) - [Scalar Value Types](#scalar-value-types) - +
-## publicawesome/stargaze/cron/v1/cron.proto - - - - - -### Params -Params holds parameters for the cron module. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `admin_addresses` | [string](#string) | repeated | Addresses which act as admins of the module. They can promote and demote contracts without having to go via governance. | - - - +## publicawesome/stargaze/authority/v1/authority.proto @@ -67,252 +34,60 @@ Params holds parameters for the cron module. - + -## publicawesome/stargaze/cron/v1/genesis.proto +## publicawesome/stargaze/authority/v1/genesis.proto - + ### GenesisState -GenesisState defines the cron module's genesis state. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `privileged_contract_addresses` | [string](#string) | repeated | List of all the contracts that have been given the privilege status via governance. They can set up hooks to abci.EndBlocker | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | Module params | - - - - - - - - - - - - - - - - - - -## publicawesome/stargaze/cron/v1/proposal.proto - - - - - -### DemotePrivilegedContractProposal -Deprecated: Do not use. To demote a contract, a -MsgDemoteFromPrivilegedContract can be invoked from the x/gov module via a v1 -governance proposal - - -| 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 bech32 address of the smart contract | - - - - - - - - -### PromoteToPrivilegedContractProposal -Deprecated: Do not use. To promote a contract, a -MsgPromoteToPrivilegedContract can be invoked from the x/gov module via a v1 -governance proposal - - -| 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 bech32 address of the smart contract | - - - - - - - - - - - - - - - - - - -## publicawesome/stargaze/cron/v1/query.proto - - - - - -### QueryListPrivilegedRequest -QueryListPrivilegedRequest is request type for the Query/ListPrivileged RPC -method. - - -### QueryListPrivilegedResponse -QueryListPrivilegedResponse is response type for the Query/ListPrivileged RPC -method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `contract_addresses` | [string](#string) | repeated | contract_addresses holds all the smart contract addresses which have privilege status. | - - - - - - - - -### QueryParamsRequest -QueryParamsRequest is request type for the Query/Params RPC -method. - - - - - - - - -### QueryParamsResponse -QueryParamsResponse is response type for the Query/Params RPC -method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | | - - - - - - - - -### Query -Query defines the gRPC querier service. - -| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | -| ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `ListPrivileged` | [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) | [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) | ListPrivileged queries the contracts which have the priviledge status | GET|/stargaze/cron/v1/list-privileged| -| `Params` | [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) | | GET|/stargaze/cron/v1/params| - - + -## publicawesome/stargaze/cron/v1/tx.proto - - - - - -### MsgDemoteFromPrivilegedContract +## publicawesome/stargaze/authority/v1/tx.proto -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | -| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - - - - - - - - -### MsgDemoteFromPrivilegedContractResponse - - - - - - - - - -### MsgPromoteToPrivilegedContract - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | -| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - - - - - - - - -### MsgPromoteToPrivilegedContractResponse - - - - - - - - - -### MsgUpdateParams + +### MsgExecuteProposal +MsgExecuteProposal defines an sdk.Msg type that supports submitting arbitrary +proposal Content. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | NOTE: All parameters must be supplied. | - +| `authority` | [string](#string) | | | +| `messages` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | - -### MsgUpdateParamsResponse + +### MsgExecuteProposalResponse +MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. @@ -325,16 +100,14 @@ Query defines the gRPC querier service. - + ### Msg -Msg defines the alloc Msg service. +Msg defines the authority Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `PromoteToPrivilegedContract` | [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) | [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) | | | -| `DemoteFromPrivilegedContract` | [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) | [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) | | | -| `UpdateParams` | [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) | | | +| `ExecuteProposal` | [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) | [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) | | | diff --git a/proto/publicawesome/stargaze/authority/v1/authority.proto b/proto/publicawesome/stargaze/authority/v1/authority.proto new file mode 100644 index 000000000..e69de29bb diff --git a/proto/publicawesome/stargaze/authority/v1/genesis.proto b/proto/publicawesome/stargaze/authority/v1/genesis.proto new file mode 100644 index 000000000..336d3dcfb --- /dev/null +++ b/proto/publicawesome/stargaze/authority/v1/genesis.proto @@ -0,0 +1,8 @@ +syntax = "proto3"; +package publicawesome.stargaze.authority.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/public-awesome/stargaze/v13/x/authority/types"; + +message GenesisState {} \ No newline at end of file diff --git a/proto/publicawesome/stargaze/authority/v1/tx.proto b/proto/publicawesome/stargaze/authority/v1/tx.proto new file mode 100644 index 000000000..3d6dcaae9 --- /dev/null +++ b/proto/publicawesome/stargaze/authority/v1/tx.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package publicawesome.stargaze.authority.v1; + +import "gogoproto/gogo.proto"; +import "cosmos/msg/v1/msg.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/public-awesome/stargaze/v13/x/authority/types"; + +// Msg defines the authority Msg service. +service Msg { + rpc ExecuteProposal(MsgExecuteProposal) + returns (MsgExecuteProposalResponse); + } + +// MsgExecuteProposal defines an sdk.Msg type that supports submitting arbitrary +// proposal Content. +message MsgExecuteProposal { + option (cosmos.msg.v1.signer) = "authority"; + + string authority = 1; + repeated google.protobuf.Any messages = 2; + } + + // MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. + message MsgExecuteProposalResponse { } \ No newline at end of file diff --git a/x/authority/types/genesis.pb.go b/x/authority/types/genesis.pb.go new file mode 100644 index 000000000..023a19892 --- /dev/null +++ b/x/authority/types/genesis.pb.go @@ -0,0 +1,268 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: publicawesome/stargaze/authority/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type GenesisState struct { +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_f6ae0642d48c5a1e, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.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 *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "publicawesome.stargaze.authority.v1.GenesisState") +} + +func init() { + proto.RegisterFile("publicawesome/stargaze/authority/v1/genesis.proto", fileDescriptor_f6ae0642d48c5a1e) +} + +var fileDescriptor_f6ae0642d48c5a1e = []byte{ + // 177 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2c, 0x28, 0x4d, 0xca, + 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, + 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, + 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x46, + 0xd1, 0xa2, 0x07, 0xd3, 0xa2, 0x07, 0xd7, 0xa2, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, + 0x0f, 0x56, 0xaf, 0x0f, 0x62, 0x41, 0xb4, 0x2a, 0xf1, 0x71, 0xf1, 0xb8, 0x43, 0xcc, 0x0a, 0x2e, + 0x49, 0x2c, 0x49, 0x75, 0x0a, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, + 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, + 0x8b, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x88, 0x7d, 0xba, 0x18, + 0x6e, 0x2c, 0x33, 0x34, 0xd6, 0xaf, 0x40, 0x72, 0x69, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, + 0xd8, 0x2a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x33, 0x62, 0xe5, 0xae, 0xda, 0x00, 0x00, + 0x00, +} + +func (m *GenesisState) 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 *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) 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 ErrIntOverflowGenesis + } + 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: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authority/types/tx.pb.go b/x/authority/types/tx.pb.go new file mode 100644 index 000000000..2e554415a --- /dev/null +++ b/x/authority/types/tx.pb.go @@ -0,0 +1,599 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: publicawesome/stargaze/authority/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + types "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + 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. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgExecuteProposal defines an sdk.Msg type that supports submitting arbitrary +// proposal Content. +type MsgExecuteProposal struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Messages []*types.Any `protobuf:"bytes,2,rep,name=messages,proto3" json:"messages,omitempty"` +} + +func (m *MsgExecuteProposal) Reset() { *m = MsgExecuteProposal{} } +func (m *MsgExecuteProposal) String() string { return proto.CompactTextString(m) } +func (*MsgExecuteProposal) ProtoMessage() {} +func (*MsgExecuteProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_a59b6a5ac2f6d30b, []int{0} +} +func (m *MsgExecuteProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgExecuteProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgExecuteProposal.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 *MsgExecuteProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExecuteProposal.Merge(m, src) +} +func (m *MsgExecuteProposal) XXX_Size() int { + return m.Size() +} +func (m *MsgExecuteProposal) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExecuteProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgExecuteProposal proto.InternalMessageInfo + +func (m *MsgExecuteProposal) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgExecuteProposal) GetMessages() []*types.Any { + if m != nil { + return m.Messages + } + return nil +} + +// MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. +type MsgExecuteProposalResponse struct { +} + +func (m *MsgExecuteProposalResponse) Reset() { *m = MsgExecuteProposalResponse{} } +func (m *MsgExecuteProposalResponse) String() string { return proto.CompactTextString(m) } +func (*MsgExecuteProposalResponse) ProtoMessage() {} +func (*MsgExecuteProposalResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_a59b6a5ac2f6d30b, []int{1} +} +func (m *MsgExecuteProposalResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgExecuteProposalResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgExecuteProposalResponse.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 *MsgExecuteProposalResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgExecuteProposalResponse.Merge(m, src) +} +func (m *MsgExecuteProposalResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgExecuteProposalResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgExecuteProposalResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgExecuteProposalResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgExecuteProposal)(nil), "publicawesome.stargaze.authority.v1.MsgExecuteProposal") + proto.RegisterType((*MsgExecuteProposalResponse)(nil), "publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse") +} + +func init() { + proto.RegisterFile("publicawesome/stargaze/authority/v1/tx.proto", fileDescriptor_a59b6a5ac2f6d30b) +} + +var fileDescriptor_a59b6a5ac2f6d30b = []byte{ + // 321 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x29, 0x28, 0x4d, 0xca, + 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, + 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, + 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x46, 0x51, 0xad, 0x07, 0x53, 0xad, + 0x07, 0x57, 0xad, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, 0x0f, 0x56, 0xaf, 0x0f, 0x62, + 0x41, 0xb4, 0x4a, 0x89, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, 0xeb, 0xe7, 0x16, 0xa7, 0x83, 0x8c, + 0xcc, 0x2d, 0x4e, 0x87, 0x4a, 0x48, 0xa6, 0xe7, 0xe7, 0xa7, 0xe7, 0xa4, 0xea, 0x83, 0x79, 0x49, + 0xa5, 0x69, 0xfa, 0x89, 0x79, 0x95, 0x10, 0x29, 0xa5, 0x12, 0x2e, 0x21, 0xdf, 0xe2, 0x74, 0xd7, + 0x8a, 0xd4, 0xe4, 0xd2, 0x92, 0xd4, 0x80, 0xa2, 0xfc, 0x82, 0xfc, 0xe2, 0xc4, 0x1c, 0x21, 0x19, + 0x2e, 0x4e, 0xb8, 0x7d, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x9c, 0x41, 0x08, 0x01, 0x21, 0x03, 0x2e, + 0x8e, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0xf4, 0xd4, 0x62, 0x09, 0x26, 0x05, 0x66, 0x0d, 0x6e, 0x23, + 0x11, 0x3d, 0x88, 0x0d, 0x7a, 0x30, 0x1b, 0xf4, 0x1c, 0xf3, 0x2a, 0x83, 0xe0, 0xaa, 0xac, 0xf8, + 0x9a, 0x9e, 0x6f, 0xd0, 0x42, 0x98, 0xa0, 0x24, 0xc3, 0x25, 0x85, 0x69, 0x6b, 0x50, 0x6a, 0x71, + 0x41, 0x7e, 0x5e, 0x71, 0xaa, 0xd1, 0x64, 0x46, 0x2e, 0x66, 0xdf, 0xe2, 0x74, 0xa1, 0x6e, 0x46, + 0x2e, 0x7e, 0x74, 0x97, 0x99, 0xeb, 0x11, 0x11, 0x3e, 0x7a, 0x98, 0x86, 0x4b, 0xd9, 0x93, 0xa9, + 0x11, 0xe6, 0x2a, 0xa7, 0xa0, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, + 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, + 0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x58, 0xa2, 0x8b, 0x11, + 0xd9, 0x65, 0x86, 0xc6, 0xfa, 0x15, 0x48, 0x51, 0x5e, 0x52, 0x59, 0x90, 0x5a, 0x9c, 0xc4, 0x06, + 0x0e, 0x2f, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf6, 0x1d, 0x1b, 0x44, 0x23, 0x02, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + ExecuteProposal(ctx context.Context, in *MsgExecuteProposal, opts ...grpc.CallOption) (*MsgExecuteProposalResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) ExecuteProposal(ctx context.Context, in *MsgExecuteProposal, opts ...grpc.CallOption) (*MsgExecuteProposalResponse, error) { + out := new(MsgExecuteProposalResponse) + err := c.cc.Invoke(ctx, "/publicawesome.stargaze.authority.v1.Msg/ExecuteProposal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + ExecuteProposal(context.Context, *MsgExecuteProposal) (*MsgExecuteProposalResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) ExecuteProposal(ctx context.Context, req *MsgExecuteProposal) (*MsgExecuteProposalResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ExecuteProposal not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_ExecuteProposal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgExecuteProposal) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).ExecuteProposal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/publicawesome.stargaze.authority.v1.Msg/ExecuteProposal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).ExecuteProposal(ctx, req.(*MsgExecuteProposal)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "publicawesome.stargaze.authority.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "ExecuteProposal", + Handler: _Msg_ExecuteProposal_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "publicawesome/stargaze/authority/v1/tx.proto", +} + +func (m *MsgExecuteProposal) 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 *MsgExecuteProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Messages) > 0 { + for iNdEx := len(m.Messages) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Messages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgExecuteProposalResponse) 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 *MsgExecuteProposalResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgExecuteProposalResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgExecuteProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Messages) > 0 { + for _, e := range m.Messages { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgExecuteProposalResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgExecuteProposal) 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 ErrIntOverflowTx + } + 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: MsgExecuteProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgExecuteProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Messages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Messages = append(m.Messages, &types.Any{}) + if err := m.Messages[len(m.Messages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgExecuteProposalResponse) 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 ErrIntOverflowTx + } + 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: MsgExecuteProposalResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgExecuteProposalResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) From 155d57fbf06e1fb2dda0c0149f2ca732a2fff719 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:14:29 +0530 Subject: [PATCH 02/20] adding basic authority features --- app/app.go | 25 +- docs/proto/proto-docs.md | 468 +++++++++++++++++++++++++++++-- x/authority/abci.go | 78 ++++++ x/authority/client/cli/tx.go | 93 ++++++ x/authority/genesis.go | 17 ++ x/authority/keeper/keeper.go | 57 ++++ x/authority/keeper/msg_server.go | 55 ++++ x/authority/keeper/proposal.go | 147 ++++++++++ x/authority/module.go | 148 ++++++++++ x/authority/types/codec.go | 35 +++ x/authority/types/genesis.go | 11 + x/authority/types/keys.go | 15 + x/authority/types/msgs.go | 100 +++++++ x/authority/types/types.go | 1 + 14 files changed, 1222 insertions(+), 28 deletions(-) create mode 100644 x/authority/abci.go create mode 100644 x/authority/client/cli/tx.go create mode 100644 x/authority/genesis.go create mode 100644 x/authority/keeper/keeper.go create mode 100644 x/authority/keeper/msg_server.go create mode 100644 x/authority/keeper/proposal.go create mode 100644 x/authority/module.go create mode 100644 x/authority/types/codec.go create mode 100644 x/authority/types/genesis.go create mode 100644 x/authority/types/keys.go create mode 100644 x/authority/types/msgs.go create mode 100644 x/authority/types/types.go diff --git a/app/app.go b/app/app.go index 7d3fc9be8..061bbadf1 100644 --- a/app/app.go +++ b/app/app.go @@ -118,6 +118,10 @@ import ( allocmoduletypes "github.com/public-awesome/stargaze/v13/x/alloc/types" allocwasm "github.com/public-awesome/stargaze/v13/x/alloc/wasm" + authoritymodule "github.com/public-awesome/stargaze/v13/x/authority" + authoritykeeper "github.com/public-awesome/stargaze/v13/x/authority/keeper" + authoritytypes "github.com/public-awesome/stargaze/v13/x/authority/types" + cronmodule "github.com/public-awesome/stargaze/v13/x/cron" cronmodulekeeper "github.com/public-awesome/stargaze/v13/x/cron/keeper" cronmoduletypes "github.com/public-awesome/stargaze/v13/x/cron/types" @@ -207,6 +211,7 @@ var ( transfer.AppModuleBasic{}, vesting.AppModuleBasic{}, allocmodule.AppModuleBasic{}, + authoritymodule.AppModuleBasic{}, cronmodule.AppModuleBasic{}, globalfeemodule.AppModuleBasic{}, tokenfactory.AppModuleBasic{}, @@ -228,6 +233,7 @@ var ( allocmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner, authtypes.Staking}, allocmoduletypes.FairburnPoolName: nil, allocmoduletypes.SupplementPoolName: nil, + authoritytypes.ModuleName: {authtypes.Burner}, wasmtypes.ModuleName: {authtypes.Burner}, icatypes.ModuleName: nil, cronmoduletypes.ModuleName: nil, @@ -299,6 +305,7 @@ type App struct { // stargaze modules AllocKeeper allocmodulekeeper.Keeper + AuthorityKeeper authoritykeeper.Keeper CronKeeper cronmodulekeeper.Keeper GlobalFeeKeeper globalfeemodulekeeper.Keeper IBCHooksKeeper ibchookskeeper.Keeper @@ -346,6 +353,7 @@ func NewStargazeApp( govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, allocmoduletypes.StoreKey, + authoritytypes.StoreKey, authzkeeper.StoreKey, wasmtypes.StoreKey, cronmoduletypes.StoreKey, @@ -427,7 +435,7 @@ func NewStargazeApp( app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authtypes.NewModuleAddress(authoritytypes.ModuleName).String(), ) app.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, @@ -583,6 +591,14 @@ func NewStargazeApp( ) // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper + app.AuthorityKeeper = authoritykeeper.NewKeeper( + appCodec, + keys[authoritytypes.StoreKey], + app.GetSubspace(authoritytypes.ModuleName), + bApp.MsgServiceRouter(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + authoritymodule := authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper) // wasm configuration @@ -621,7 +637,7 @@ func NewStargazeApp( wasmDir, wasmConfig, GetWasmCapabilities(), - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authtypes.NewModuleAddress(authoritytypes.ModuleName).String(), wasmOpts..., ) @@ -716,6 +732,7 @@ func NewStargazeApp( params.NewAppModule(app.ParamsKeeper), transfer.NewAppModule(app.TransferKeeper), allocModule, + authoritymodule, wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)), cronModule, globalfeeModule, @@ -743,6 +760,7 @@ func NewStargazeApp( group.ModuleName, authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName, + authoritytypes.ModuleName, wasmtypes.ModuleName, cronmoduletypes.ModuleName, globalfeemoduletypes.ModuleName, @@ -762,6 +780,7 @@ func NewStargazeApp( ibcexported.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, allocmoduletypes.ModuleName, + authoritytypes.ModuleName, wasmtypes.ModuleName, cronmoduletypes.ModuleName, globalfeemoduletypes.ModuleName, @@ -795,6 +814,7 @@ func NewStargazeApp( authz.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, vestingtypes.ModuleName, consensusparamtypes.ModuleName, + authoritytypes.ModuleName, allocmoduletypes.ModuleName, tokenfactorytypes.ModuleName, // wasm after ibc transfer @@ -1056,6 +1076,7 @@ func initParamsKeeper( paramsKeeper.Subspace(cronmoduletypes.ModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) paramsKeeper.Subspace(globalfeemoduletypes.ModuleName) + paramsKeeper.Subspace(authoritytypes.ModuleName) paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) // this line is used by starport scaffolding # stargate/app/paramSubspace diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 0936d9bcb..15ffa2c82 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,24 +4,102 @@ ## Table of Contents -- [publicawesome/stargaze/authority/v1/authority.proto](#publicawesome/stargaze/authority/v1/authority.proto) -- [publicawesome/stargaze/authority/v1/genesis.proto](#publicawesome/stargaze/authority/v1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.authority.v1.GenesisState) +- [publicawesome/stargaze/globalfee/v1/globalfee.proto](#publicawesome/stargaze/globalfee/v1/globalfee.proto) + - [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) + - [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) + - [Params](#publicawesome.stargaze.globalfee.v1.Params) -- [publicawesome/stargaze/authority/v1/tx.proto](#publicawesome/stargaze/authority/v1/tx.proto) - - [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) - - [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) +- [publicawesome/stargaze/globalfee/v1/genesis.proto](#publicawesome/stargaze/globalfee/v1/genesis.proto) + - [GenesisState](#publicawesome.stargaze.globalfee.v1.GenesisState) - - [Msg](#publicawesome.stargaze.authority.v1.Msg) +- [publicawesome/stargaze/globalfee/v1/proposal.proto](#publicawesome/stargaze/globalfee/v1/proposal.proto) + - [RemoveCodeAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.RemoveCodeAuthorizationProposal) + - [RemoveContractAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.RemoveContractAuthorizationProposal) + - [SetCodeAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.SetCodeAuthorizationProposal) + - [SetContractAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.SetContractAuthorizationProposal) + +- [publicawesome/stargaze/globalfee/v1/query.proto](#publicawesome/stargaze/globalfee/v1/query.proto) + - [QueryAuthorizationsRequest](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsRequest) + - [QueryAuthorizationsResponse](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsResponse) + - [QueryCodeAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationRequest) + - [QueryCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationResponse) + - [QueryContractAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationRequest) + - [QueryContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationResponse) + - [QueryParamsRequest](#publicawesome.stargaze.globalfee.v1.QueryParamsRequest) + - [QueryParamsResponse](#publicawesome.stargaze.globalfee.v1.QueryParamsResponse) + + - [Query](#publicawesome.stargaze.globalfee.v1.Query) + +- [publicawesome/stargaze/globalfee/v1/tx.proto](#publicawesome/stargaze/globalfee/v1/tx.proto) + - [MsgRemoveCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorization) + - [MsgRemoveCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorizationResponse) + - [MsgRemoveContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorization) + - [MsgRemoveContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorizationResponse) + - [MsgSetCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorization) + - [MsgSetCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorizationResponse) + - [MsgSetContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorization) + - [MsgSetContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorizationResponse) + - [MsgUpdateParams](#publicawesome.stargaze.globalfee.v1.MsgUpdateParams) + - [MsgUpdateParamsResponse](#publicawesome.stargaze.globalfee.v1.MsgUpdateParamsResponse) + + - [Msg](#publicawesome.stargaze.globalfee.v1.Msg) - [Scalar Value Types](#scalar-value-types) - + -## publicawesome/stargaze/authority/v1/authority.proto +## publicawesome/stargaze/globalfee/v1/globalfee.proto + + + + + +### CodeAuthorization +Configuration for code Ids which can have zero gas operations + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `code_id` | [uint64](#uint64) | | authorized code ids | +| `methods` | [string](#string) | repeated | authorized contract operation methods | + + + + + + + + +### ContractAuthorization +Configuration for contract addresses which can have zero gas operations + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `contract_address` | [string](#string) | | authorized contract addresses | +| `methods` | [string](#string) | repeated | authorized contract operation methods | + + + + + + + + +### Params +Params holds parameters for the globalfee module. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `privileged_addresses` | [string](#string) | repeated | Addresses which are whitelisted to modify the gas free operations | +| `minimum_gas_prices` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | repeated | Minimum stores the minimum gas price(s) for all TX on the chain. | + + + @@ -34,18 +112,236 @@ - + -## publicawesome/stargaze/authority/v1/genesis.proto +## publicawesome/stargaze/globalfee/v1/genesis.proto - + ### GenesisState +GenesisState defines the globalfee module's genesis state. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | Module params | +| `code_authorizations` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | repeated | Authorizations configured by code id | +| `contract_authorizations` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | repeated | Authorizations configured by contract addresses | + + + + + + + + + + + + + + + + + + +## publicawesome/stargaze/globalfee/v1/proposal.proto + + + + + +### RemoveCodeAuthorizationProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | | +| `description` | [string](#string) | | | +| `code_id` | [uint64](#uint64) | | | + + + + + + + + +### RemoveContractAuthorizationProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | | +| `description` | [string](#string) | | | +| `contract_address` | [string](#string) | | | + + + + + + + + +### SetCodeAuthorizationProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | | +| `description` | [string](#string) | | | +| `code_authorization` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | | | + + + + + + + + +### SetContractAuthorizationProposal + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `title` | [string](#string) | | | +| `description` | [string](#string) | | | +| `contract_authorization` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | | | + + + + + + + + + + + + + + + + + + +## publicawesome/stargaze/globalfee/v1/query.proto + + + + + +### QueryAuthorizationsRequest + + + + + + + + + +### QueryAuthorizationsResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `code_authorizations` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | repeated | | +| `contract_authorizations` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | repeated | | + + + + + + + + +### QueryCodeAuthorizationRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `code_id` | [uint64](#uint64) | | | + + + + + + + + +### QueryCodeAuthorizationResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `methods` | [string](#string) | repeated | | + + + + + + +### QueryContractAuthorizationRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `contract_address` | [string](#string) | | | + + + + + + + + +### QueryContractAuthorizationResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `methods` | [string](#string) | repeated | | + + + + + + + + +### QueryParamsRequest + + + + + + + + + +### QueryParamsResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | | + @@ -56,38 +352,154 @@ + + + +### Query +Query defines the gRPC querier service. + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `CodeAuthorization` | [QueryCodeAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationRequest) | [QueryCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationResponse) | | GET|/stargaze/globalfee/v1/code_authorization/{code_id}| +| `ContractAuthorization` | [QueryContractAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationRequest) | [QueryContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationResponse) | | GET|/stargaze/globalfee/v1/contract_authorization/{contract_address}| +| `Params` | [QueryParamsRequest](#publicawesome.stargaze.globalfee.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.globalfee.v1.QueryParamsResponse) | | GET|/stargaze/globalfee/v1/params| +| `Authorizations` | [QueryAuthorizationsRequest](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsRequest) | [QueryAuthorizationsResponse](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsResponse) | | GET|/stargaze/globalfee/v1/authorizations| + - + -## publicawesome/stargaze/authority/v1/tx.proto +## publicawesome/stargaze/globalfee/v1/tx.proto + + + + + +### MsgRemoveCodeAuthorization + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `code_id` | [uint64](#uint64) | | | + + + + + + + + +### MsgRemoveCodeAuthorizationResponse + + + - -### MsgExecuteProposal -MsgExecuteProposal defines an sdk.Msg type that supports submitting arbitrary -proposal Content. + + +### MsgRemoveContractAuthorization + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | | -| `messages` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | +| `sender` | [string](#string) | | | +| `contract_address` | [string](#string) | | | + + + + + + + + +### MsgRemoveContractAuthorizationResponse + + + + + + + + + +### MsgSetCodeAuthorization + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `code_authorization` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | | | + + + + + + + + +### MsgSetCodeAuthorizationResponse + + + + + + + + + +### MsgSetContractAuthorization + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `contract_authorization` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | | | + + + + + + + + +### MsgSetContractAuthorizationResponse + + + + + + + + + +### MsgUpdateParams + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | NOTE: All parameters must be supplied. | + + - +### MsgUpdateParamsResponse -### MsgExecuteProposalResponse -MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. @@ -100,14 +512,18 @@ MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. - + ### Msg -Msg defines the authority Msg service. +Msg defines the alloc Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `ExecuteProposal` | [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) | [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) | | | +| `SetCodeAuthorization` | [MsgSetCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorization) | [MsgSetCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorizationResponse) | | | +| `RemoveCodeAuthorization` | [MsgRemoveCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorization) | [MsgRemoveCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorizationResponse) | | | +| `SetContractAuthorization` | [MsgSetContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorization) | [MsgSetContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorizationResponse) | | | +| `RemoveContractAuthorization` | [MsgRemoveContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorization) | [MsgRemoveContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorizationResponse) | | | +| `UpdateParams` | [MsgUpdateParams](#publicawesome.stargaze.globalfee.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#publicawesome.stargaze.globalfee.v1.MsgUpdateParamsResponse) | | | diff --git a/x/authority/abci.go b/x/authority/abci.go new file mode 100644 index 000000000..2e9a87156 --- /dev/null +++ b/x/authority/abci.go @@ -0,0 +1,78 @@ +package authority + +import ( + "fmt" + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/public-awesome/stargaze/v13/x/authority/keeper" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +// EndBlocker called every block, process inflation, update validator set. +func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + logger := keeper.Logger(ctx) + + keeper.IterateActiveProposalsQueue(ctx, func(proposal govV1.Proposal) bool { + var logMsg, tagValue string + + var ( + idx int + events sdk.Events + msg sdk.Msg + ) + + cacheCtx, writeCache := ctx.CacheContext() + messages, err := proposal.GetMsgs() + if err == nil { + for idx, msg = range messages { + handler := keeper.Router().Handler(msg) + + var res *sdk.Result + res, err = handler(cacheCtx, msg) + if err != nil { + break + } + + events = append(events, res.GetEvents()...) + } + } + + if err == nil { + proposal.Status = govV1.StatusPassed + tagValue = govtypes.AttributeValueProposalPassed + logMsg = "passed" + + // write state to the underlying multi-store + writeCache() + + // propagate the msg events to the current context + ctx.EventManager().EmitEvents(events) + } else { + proposal.Status = govV1.StatusFailed + tagValue = govtypes.AttributeValueProposalFailed + logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err) + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + govtypes.EventTypeActiveProposal, + sdk.NewAttribute(govtypes.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.Id)), + sdk.NewAttribute(govtypes.AttributeKeyProposalResult, tagValue), + ), + ) + + logger.Info( + "proposal tallied", + "proposal", proposal.Id, + "title", proposal.GetTitle(), + "result", logMsg, + ) + + return false + }) +} diff --git a/x/authority/client/cli/tx.go b/x/authority/client/cli/tx.go new file mode 100644 index 000000000..4a483d65d --- /dev/null +++ b/x/authority/client/cli/tx.go @@ -0,0 +1,93 @@ +package cli + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v13/x/authority/types" + "github.com/spf13/cobra" +) + +// GetTxCmd builds tx command group for the module. +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdSubmitProposal()) + return cmd +} + +func CmdSubmitProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "submit-proposal [path/to/proposal.json]", + Short: "Submit a proposal along with some messages", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msgs, err := parseSubmitProposal(clientCtx.Codec, args[0]) + if err != nil { + return err + } + + msg, err := types.NewMsgExecuteProposal(msgs, clientCtx.GetFromAddress().String()) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +// proposal defines the new Msg-based proposal. +type proposal struct { + // Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. + Messages []json.RawMessage `json:"messages,omitempty"` +} + +// parseSubmitProposal reads and parses the proposal. +func parseSubmitProposal(cdc codec.Codec, path string) ([]sdk.Msg, error) { + var proposal proposal + + contents, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + err = json.Unmarshal(contents, &proposal) + if err != nil { + return nil, err + } + + msgs := make([]sdk.Msg, len(proposal.Messages)) + for i, anyJSON := range proposal.Messages { + var msg sdk.Msg + err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) + if err != nil { + return nil, err + } + + msgs[i] = msg + } + + return msgs, nil +} diff --git a/x/authority/genesis.go b/x/authority/genesis.go new file mode 100644 index 000000000..4e4030112 --- /dev/null +++ b/x/authority/genesis.go @@ -0,0 +1,17 @@ +package authority + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v13/x/authority/keeper" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +// InitGenesis initializes the capability module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { +} + +// ExportGenesis returns the capability module's exported genesis. +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + return &types.GenesisState{} +} diff --git a/x/authority/keeper/keeper.go b/x/authority/keeper/keeper.go new file mode 100644 index 000000000..a013350db --- /dev/null +++ b/x/authority/keeper/keeper.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "fmt" + + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + paramstore paramtypes.Subspace + router *baseapp.MsgServiceRouter + authority string // this should be the x/gov module account + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + storeKey storetypes.StoreKey, + ps paramtypes.Subspace, + router *baseapp.MsgServiceRouter, + authority string, +) Keeper { + return Keeper{ + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + router: router, + authority: authority, + } +} + +// GetAuthority returns the x/wasm module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} + +// Router returns the adminmodule Keeper's Router +func (k Keeper) Router() *baseapp.MsgServiceRouter { + return k.router +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ModuleLogger(ctx) +} + +func ModuleLogger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go new file mode 100644 index 000000000..b691bc273 --- /dev/null +++ b/x/authority/keeper/msg_server.go @@ -0,0 +1,55 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +type msgServer struct { + Keeper +} + +// NewMsgServerImpl returns an implementation of the MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +var _ types.MsgServer = msgServer{} + +// ExecuteProposal implements types.MsgServer. +func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteProposal) (*types.MsgExecuteProposalResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + proposalMsgs, err := msg.GetMsgs() + if err != nil { + return nil, err + } + + proposer, err := sdk.AccAddressFromBech32(msg.GetAuthority()) + if err != nil { + return nil, err + } + + IsAuthorized(ctx, proposalMsgs) + + _, err = m.Keeper.SubmitProposal(ctx, proposalMsgs, proposer) + if err != nil { + return nil, err + } + + return &types.MsgExecuteProposalResponse{}, nil +} + +func IsAuthorized(ctx sdk.Context, msgs []sdk.Msg) bool { + // loop through msgs + for _, msg := range msgs { + test := sdk.MsgTypeURL(msg) + panic(test) + } + return false +} + +// /cosmos.distribution.v1beta1.MsgCommunityPoolSpend diff --git a/x/authority/keeper/proposal.go b/x/authority/keeper/proposal.go new file mode 100644 index 000000000..2a91b1e9f --- /dev/null +++ b/x/authority/keeper/proposal.go @@ -0,0 +1,147 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/gov/types" + govV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" +) + +// IterateActiveProposalsQueue iterates over the proposals in the active proposal queue +// and performs a callback function +func (k Keeper) IterateActiveProposalsQueue(ctx sdk.Context, cb func(proposal govV1.Proposal) (stop bool)) { + iterator := k.ActiveProposalQueueIterator(ctx) + + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + proposalID := types.GetProposalIDFromBytes(iterator.Value()) + proposal, found := k.GetProposal(ctx, proposalID) + if !found { + panic(fmt.Sprintf("proposal %d does not exist", proposalID)) + } + + if cb(proposal) { + break + } + } +} + +// ActiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Active Queue +func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context) sdk.Iterator { + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ActiveProposalQueuePrefix) + return prefixStore.Iterator(nil, nil) +} + +// GetProposal get proposal from store by ProposalID +func (k Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (govV1.Proposal, bool) { + store := ctx.KVStore(k.storeKey) + + bz := store.Get(types.ProposalKey(proposalID)) + if bz == nil { + return govV1.Proposal{}, false + } + + var proposal govV1.Proposal + k.MustUnmarshalProposal(bz, &proposal) + + return proposal, true +} + +func (k Keeper) MustUnmarshalProposal(bz []byte, proposal *govV1.Proposal) { + err := k.UnmarshalProposal(bz, proposal) + if err != nil { + panic(err) + } +} + +func (k Keeper) UnmarshalProposal(bz []byte, proposal *govV1.Proposal) error { + err := k.cdc.Unmarshal(bz, proposal) + if err != nil { + return err + } + return nil +} + +// SubmitProposal creates a new proposal given an array of messages +func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, proposer sdk.AccAddress) (uint64, error) { + // Will hold a comma-separated string of all Msg type URLs. + msgsStr := "" + + var ( + events sdk.Events + ) + + // Loop through all messages and confirm that each has a handler and the gov module account + // as the only signer + for _, msg := range messages { + msgsStr += fmt.Sprintf(",%s", sdk.MsgTypeURL(msg)) + + // perform a basic validation of the message + if err := msg.ValidateBasic(); err != nil { + return 0, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) + } + + signers := msg.GetSigners() + if len(signers) != 1 { + return 0, types.ErrInvalidSigner + } + + // // assert that the governance module account is the only signer of the messages + // if !signers[0].Equals(keeper.GetGovernanceAccount(ctx).GetAddress()) { + // return v1.Proposal{}, sdkerrors.Wrapf(types.ErrInvalidSigner, signers[0].String()) + // } + + // use the msg service router to see that there is a valid route for that message. + handler := keeper.router.Handler(msg) + if handler == nil { + return 0, errorsmod.Wrap(types.ErrUnroutableProposalMsg, sdk.MsgTypeURL(msg)) + } + + var res *sdk.Result + res, err := handler(ctx, msg) + if err != nil { + return 0, err + } + + events = append(events, res.GetEvents()...) + + } + + return 0, nil +} + +// // SetProposal set a proposal to store +// func (k Keeper) SetProposal(ctx sdk.Context, proposal govV1.Proposal) { +// store := ctx.KVStore(k.storeKey) + +// bz := k.MustMarshalProposal(proposal) + +// store.Set(types.ProposalKey(proposal.Id), bz) +// } + +// // GetProposalID gets the highest proposal ID +// func (k Keeper) GetProposalID(ctx sdk.Context) (proposalID uint64, err error) { +// store := ctx.KVStore(k.storeKey) +// bz := store.Get(types.ProposalIDKey) +// if bz == nil { +// return 0, errorsmod.Wrap(types.ErrInvalidGenesis, "initial proposal ID hasn't been set") +// } + +// proposalID = types.GetProposalIDFromBytes(bz) +// return proposalID, nil +// } + +// // SetProposalID sets the new proposal ID to the store +// func (k Keeper) SetProposalID(ctx sdk.Context, proposalID uint64) { +// store := ctx.KVStore(k.storeKey) +// store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID)) +// } + +// // InsertActiveProposalQueue inserts a ProposalID into the active proposal queue +// func (k Keeper) InsertActiveProposalQueue(ctx sdk.Context, proposalID uint64) { +// store := ctx.KVStore(k.storeKey) +// store.Set(types.ActiveProposalQueueKey(proposalID), types.GetProposalIDBytes(proposalID)) +// } diff --git a/x/authority/module.go b/x/authority/module.go new file mode 100644 index 000000000..693eaa1c9 --- /dev/null +++ b/x/authority/module.go @@ -0,0 +1,148 @@ +package authority + +import ( + "encoding/json" + "fmt" + + // this line is used by starport scaffolding # 1 + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/public-awesome/stargaze/v13/x/authority/client/cli" + "github.com/public-awesome/stargaze/v13/x/authority/keeper" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + return cdc.MustMarshalJSON(types.DefaultGenesis()) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + // err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + // if err != nil { + // panic(err) + // } +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil //cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + //types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return 1 } + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + EndBlocker(ctx, am.keeper) + return []abci.ValidatorUpdate{} +} diff --git a/x/authority/types/codec.go b/x/authority/types/codec.go new file mode 100644 index 000000000..9c83443af --- /dev/null +++ b/x/authority/types/codec.go @@ -0,0 +1,35 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptoCodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterLegacyAminoCodec registers the necessary interfaces and concrete types on the provided LegacyAmino codec. +// These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgExecuteProposal{}, "authority/MsgExecuteProposal", nil) +} + +// RegisterInterfaces registers interfaces types with the interface registry. +func RegisterInterfaces(registry types.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgExecuteProposal{}, + ) + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + ModuleCdc = codec.NewAminoCodec(Amino) + Amino = codec.NewLegacyAmino() +) + +func init() { + RegisterLegacyAminoCodec(Amino) + cryptoCodec.RegisterCrypto(Amino) + sdk.RegisterLegacyAminoCodec(Amino) + Amino.Seal() +} diff --git a/x/authority/types/genesis.go b/x/authority/types/genesis.go new file mode 100644 index 000000000..1f25c6546 --- /dev/null +++ b/x/authority/types/genesis.go @@ -0,0 +1,11 @@ +package types + +// DefaultGenesisState returns a default genesis state. +func DefaultGenesis() *GenesisState { + return &GenesisState{} +} + +// Validate perform object fields validation. +func (m GenesisState) Validate() error { + return nil +} diff --git a/x/authority/types/keys.go b/x/authority/types/keys.go new file mode 100644 index 000000000..487fedde6 --- /dev/null +++ b/x/authority/types/keys.go @@ -0,0 +1,15 @@ +package types + +const ( + // ModuleName defines the module name + ModuleName = "authority" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_authority" +) diff --git a/x/authority/types/msgs.go b/x/authority/types/msgs.go new file mode 100644 index 000000000..f789b8c28 --- /dev/null +++ b/x/authority/types/msgs.go @@ -0,0 +1,100 @@ +package types + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/gov/codec" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" +) + +var ( + _ sdk.Msg = &MsgExecuteProposal{} + _ codectypes.UnpackInterfacesMessage = &MsgExecuteProposal{} +) + +// NewMsgExecuteProposal creates a new MsgExecuteProposal. +// +//nolint:interfacer +func NewMsgExecuteProposal(messages []sdk.Msg, authority string) (*MsgExecuteProposal, error) { + m := &MsgExecuteProposal{ + Authority: authority, + } + + anys, err := sdktx.SetMsgs(messages) + if err != nil { + return nil, err + } + + m.Messages = anys + + return m, nil +} + +// GetMsgs unpacks m.Messages Any's into sdk.Msg's +func (m *MsgExecuteProposal) GetMsgs() ([]sdk.Msg, error) { + return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") +} + +// SetMsgs packs sdk.Msg's into m.Messages Any's +// NOTE: this will overwrite any existing messages +func (m *MsgExecuteProposal) SetMsgs(msgs []sdk.Msg) error { + anys, err := sdktx.SetMsgs(msgs) + if err != nil { + return err + } + + m.Messages = anys + return nil +} + +// Type implements the sdk.Msg interface. +func (m MsgExecuteProposal) Type() string { return sdk.MsgTypeURL(&m) } + +// ValidateBasic implements the sdk.Msg interface. +func (m MsgExecuteProposal) ValidateBasic() error { + + if _, err := sdk.AccAddressFromBech32(m.GetAuthority()); err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("invalid proposer address: %s", err) + } + + // Check that either metadata or Msgs length is non nil. + if len(m.Messages) == 0 { + return errorsmod.Wrap(govtypes.ErrNoProposalMsgs, "Msgs length must be non-nil") + } + + msgs, err := m.GetMsgs() + if err != nil { + return err + } + + for idx, msg := range msgs { + if err := msg.ValidateBasic(); err != nil { + return errorsmod.Wrap(govtypes.ErrInvalidProposalMsg, + fmt.Sprintf("msg: %d, err: %s", idx, err.Error())) + } + } + + return nil +} + +// GetSignBytes returns the message bytes to sign over. +func (m MsgExecuteProposal) GetSignBytes() []byte { + bz := codec.ModuleCdc.MustMarshalJSON(&m) + return sdk.MustSortJSON(bz) +} + +// GetSigners returns the expected signers for a MsgExecuteProposal. +func (m MsgExecuteProposal) GetSigners() []sdk.AccAddress { + proposer, _ := sdk.AccAddressFromBech32(m.GetAuthority()) + return []sdk.AccAddress{proposer} +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (m MsgExecuteProposal) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + return sdktx.UnpackInterfaces(unpacker, m.Messages) +} diff --git a/x/authority/types/types.go b/x/authority/types/types.go new file mode 100644 index 000000000..ab1254f4c --- /dev/null +++ b/x/authority/types/types.go @@ -0,0 +1 @@ +package types From e0607a86759c88c81815572c8f4ec6075ff6b40b Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:14:47 +0530 Subject: [PATCH 03/20] adding params proto --- .../stargaze/authority/v1/authority.proto | 17 + x/authority/types/authority.pb.go | 555 ++++++++++++++++++ 2 files changed, 572 insertions(+) create mode 100644 x/authority/types/authority.pb.go diff --git a/proto/publicawesome/stargaze/authority/v1/authority.proto b/proto/publicawesome/stargaze/authority/v1/authority.proto index e69de29bb..29f96b3df 100644 --- a/proto/publicawesome/stargaze/authority/v1/authority.proto +++ b/proto/publicawesome/stargaze/authority/v1/authority.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package publicawesome.stargaze.authority.v1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/public-awesome/stargaze/v13/x/authority/types"; + +// Params holds parameters for the authority module. +message Params { + option (gogoproto.goproto_stringer) = false; + repeated Authorization authorizations = 1; +} + +message Authorization { + string msgTypeUrl = 1; // The type url of a proposal sdk.Msg + string address = 2; // The address who is allowed to execute that proposal +} \ No newline at end of file diff --git a/x/authority/types/authority.pb.go b/x/authority/types/authority.pb.go new file mode 100644 index 000000000..7226106f5 --- /dev/null +++ b/x/authority/types/authority.pb.go @@ -0,0 +1,555 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: publicawesome/stargaze/authority/v1/authority.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params holds parameters for the authority module. +type Params struct { + Authorizations []*Authorization `protobuf:"bytes,1,rep,name=authorizations,proto3" json:"authorizations,omitempty"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_6e13d9034052c38a, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetAuthorizations() []*Authorization { + if m != nil { + return m.Authorizations + } + return nil +} + +type Authorization struct { + MsgTypeUrl string `protobuf:"bytes,1,opt,name=msgTypeUrl,proto3" json:"msgTypeUrl,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *Authorization) Reset() { *m = Authorization{} } +func (m *Authorization) String() string { return proto.CompactTextString(m) } +func (*Authorization) ProtoMessage() {} +func (*Authorization) Descriptor() ([]byte, []int) { + return fileDescriptor_6e13d9034052c38a, []int{1} +} +func (m *Authorization) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Authorization) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Authorization.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 *Authorization) XXX_Merge(src proto.Message) { + xxx_messageInfo_Authorization.Merge(m, src) +} +func (m *Authorization) XXX_Size() int { + return m.Size() +} +func (m *Authorization) XXX_DiscardUnknown() { + xxx_messageInfo_Authorization.DiscardUnknown(m) +} + +var xxx_messageInfo_Authorization proto.InternalMessageInfo + +func (m *Authorization) GetMsgTypeUrl() string { + if m != nil { + return m.MsgTypeUrl + } + return "" +} + +func (m *Authorization) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func init() { + proto.RegisterType((*Params)(nil), "publicawesome.stargaze.authority.v1.Params") + proto.RegisterType((*Authorization)(nil), "publicawesome.stargaze.authority.v1.Authorization") +} + +func init() { + proto.RegisterFile("publicawesome/stargaze/authority/v1/authority.proto", fileDescriptor_6e13d9034052c38a) +} + +var fileDescriptor_6e13d9034052c38a = []byte{ + // 252 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2e, 0x28, 0x4d, 0xca, + 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, + 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0x44, + 0x70, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, 0x94, 0x51, 0x34, 0xe9, 0xc1, 0x34, 0xe9, 0x21, + 0xd4, 0x95, 0x19, 0x4a, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0xd5, 0xeb, 0x83, 0x58, 0x10, 0xad, + 0x4a, 0x59, 0x5c, 0x6c, 0x01, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x42, 0x51, 0x5c, 0x7c, 0x50, 0xf5, + 0x55, 0x89, 0x25, 0x99, 0xf9, 0x79, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x46, 0x7a, + 0x44, 0x98, 0xae, 0xe7, 0x88, 0xac, 0x35, 0x08, 0xcd, 0x24, 0x2b, 0x96, 0x19, 0x0b, 0xe4, 0x19, + 0x94, 0x3c, 0xb9, 0x78, 0x51, 0x94, 0x09, 0xc9, 0x71, 0x71, 0xe5, 0x16, 0xa7, 0x87, 0x54, 0x16, + 0xa4, 0x86, 0x16, 0xe5, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x89, 0x08, 0x49, 0x70, + 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x81, 0x25, 0x61, 0x5c, 0xa7, 0xa0, + 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, + 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x48, 0xcf, 0x2c, 0xc9, 0x28, + 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x38, 0x5c, 0x17, 0x23, 0x30, 0xcb, 0x0c, 0x8d, 0xf5, + 0x2b, 0x90, 0x82, 0xb4, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x22, 0xc6, 0x80, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x9a, 0x2e, 0xd2, 0x5a, 0x83, 0x01, 0x00, 0x00, +} + +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Authorizations) > 0 { + for iNdEx := len(m.Authorizations) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Authorizations[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAuthority(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *Authorization) 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 *Authorization) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Authorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintAuthority(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if len(m.MsgTypeUrl) > 0 { + i -= len(m.MsgTypeUrl) + copy(dAtA[i:], m.MsgTypeUrl) + i = encodeVarintAuthority(dAtA, i, uint64(len(m.MsgTypeUrl))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAuthority(dAtA []byte, offset int, v uint64) int { + offset -= sovAuthority(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Authorizations) > 0 { + for _, e := range m.Authorizations { + l = e.Size() + n += 1 + l + sovAuthority(uint64(l)) + } + } + return n +} + +func (m *Authorization) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.MsgTypeUrl) + if l > 0 { + n += 1 + l + sovAuthority(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovAuthority(uint64(l)) + } + return n +} + +func sovAuthority(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAuthority(x uint64) (n int) { + return sovAuthority(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowAuthority + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authorizations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthority + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthAuthority + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAuthority + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authorizations = append(m.Authorizations, &Authorization{}) + if err := m.Authorizations[len(m.Authorizations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuthority(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuthority + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Authorization) 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 ErrIntOverflowAuthority + } + 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: Authorization: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Authorization: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MsgTypeUrl", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthority + } + 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 ErrInvalidLengthAuthority + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthority + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MsgTypeUrl = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthority + } + 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 ErrInvalidLengthAuthority + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthority + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAuthority(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAuthority + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAuthority(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuthority + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuthority + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAuthority + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAuthority + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAuthority + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAuthority + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAuthority = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAuthority = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAuthority = fmt.Errorf("proto: unexpected end of group") +) From 4a2084278dcea4d9b37f6eaf3697af5e041912d4 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:56:44 +0530 Subject: [PATCH 04/20] adding params --- docs/proto/proto-docs.md | 375 +++++------------- .../stargaze/authority/v1/authority.proto | 2 +- x/authority/keeper/msg_server.go | 28 +- x/authority/keeper/params.go | 29 ++ x/authority/types/authority.pb.go | 44 +- x/authority/types/authorization.go | 41 ++ x/authority/types/errors.go | 13 + x/authority/types/keys.go | 4 + x/authority/types/params.go | 32 ++ x/authority/types/params_test.go | 93 +++++ 10 files changed, 349 insertions(+), 312 deletions(-) create mode 100644 x/authority/keeper/params.go create mode 100644 x/authority/types/authorization.go create mode 100644 x/authority/types/errors.go create mode 100644 x/authority/types/params.go create mode 100644 x/authority/types/params_test.go diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 15ffa2c82..bb766e02b 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,99 +4,54 @@ ## Table of Contents -- [publicawesome/stargaze/globalfee/v1/globalfee.proto](#publicawesome/stargaze/globalfee/v1/globalfee.proto) - - [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) - - [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) - - [Params](#publicawesome.stargaze.globalfee.v1.Params) +- [publicawesome/stargaze/cron/v1/cron.proto](#publicawesome/stargaze/cron/v1/cron.proto) + - [Params](#publicawesome.stargaze.cron.v1.Params) -- [publicawesome/stargaze/globalfee/v1/genesis.proto](#publicawesome/stargaze/globalfee/v1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.globalfee.v1.GenesisState) +- [publicawesome/stargaze/cron/v1/genesis.proto](#publicawesome/stargaze/cron/v1/genesis.proto) + - [GenesisState](#publicawesome.stargaze.cron.v1.GenesisState) -- [publicawesome/stargaze/globalfee/v1/proposal.proto](#publicawesome/stargaze/globalfee/v1/proposal.proto) - - [RemoveCodeAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.RemoveCodeAuthorizationProposal) - - [RemoveContractAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.RemoveContractAuthorizationProposal) - - [SetCodeAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.SetCodeAuthorizationProposal) - - [SetContractAuthorizationProposal](#publicawesome.stargaze.globalfee.v1.SetContractAuthorizationProposal) +- [publicawesome/stargaze/cron/v1/proposal.proto](#publicawesome/stargaze/cron/v1/proposal.proto) + - [DemotePrivilegedContractProposal](#publicawesome.stargaze.cron.v1.DemotePrivilegedContractProposal) + - [PromoteToPrivilegedContractProposal](#publicawesome.stargaze.cron.v1.PromoteToPrivilegedContractProposal) -- [publicawesome/stargaze/globalfee/v1/query.proto](#publicawesome/stargaze/globalfee/v1/query.proto) - - [QueryAuthorizationsRequest](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsRequest) - - [QueryAuthorizationsResponse](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsResponse) - - [QueryCodeAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationRequest) - - [QueryCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationResponse) - - [QueryContractAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationRequest) - - [QueryContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationResponse) - - [QueryParamsRequest](#publicawesome.stargaze.globalfee.v1.QueryParamsRequest) - - [QueryParamsResponse](#publicawesome.stargaze.globalfee.v1.QueryParamsResponse) +- [publicawesome/stargaze/cron/v1/query.proto](#publicawesome/stargaze/cron/v1/query.proto) + - [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) + - [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) + - [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) + - [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) - - [Query](#publicawesome.stargaze.globalfee.v1.Query) + - [Query](#publicawesome.stargaze.cron.v1.Query) -- [publicawesome/stargaze/globalfee/v1/tx.proto](#publicawesome/stargaze/globalfee/v1/tx.proto) - - [MsgRemoveCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorization) - - [MsgRemoveCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorizationResponse) - - [MsgRemoveContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorization) - - [MsgRemoveContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorizationResponse) - - [MsgSetCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorization) - - [MsgSetCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorizationResponse) - - [MsgSetContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorization) - - [MsgSetContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorizationResponse) - - [MsgUpdateParams](#publicawesome.stargaze.globalfee.v1.MsgUpdateParams) - - [MsgUpdateParamsResponse](#publicawesome.stargaze.globalfee.v1.MsgUpdateParamsResponse) +- [publicawesome/stargaze/cron/v1/tx.proto](#publicawesome/stargaze/cron/v1/tx.proto) + - [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) + - [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) + - [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) + - [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) + - [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) + - [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) - - [Msg](#publicawesome.stargaze.globalfee.v1.Msg) + - [Msg](#publicawesome.stargaze.cron.v1.Msg) - [Scalar Value Types](#scalar-value-types) - + -## publicawesome/stargaze/globalfee/v1/globalfee.proto +## publicawesome/stargaze/cron/v1/cron.proto - - -### CodeAuthorization -Configuration for code Ids which can have zero gas operations - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `code_id` | [uint64](#uint64) | | authorized code ids | -| `methods` | [string](#string) | repeated | authorized contract operation methods | - - - - - - - - -### ContractAuthorization -Configuration for contract addresses which can have zero gas operations - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `contract_address` | [string](#string) | | authorized contract addresses | -| `methods` | [string](#string) | repeated | authorized contract operation methods | - - - - - - - + ### Params -Params holds parameters for the globalfee module. +Params holds parameters for the cron module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `privileged_addresses` | [string](#string) | repeated | Addresses which are whitelisted to modify the gas free operations | -| `minimum_gas_prices` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | repeated | Minimum stores the minimum gas price(s) for all TX on the chain. | +| `admin_addresses` | [string](#string) | repeated | Addresses which act as admins of the module. They can promote and demote contracts without having to go via governance. | @@ -112,24 +67,23 @@ Params holds parameters for the globalfee module. - + -## publicawesome/stargaze/globalfee/v1/genesis.proto +## publicawesome/stargaze/cron/v1/genesis.proto - + ### GenesisState -GenesisState defines the globalfee module's genesis state. +GenesisState defines the cron module's genesis state. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | Module params | -| `code_authorizations` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | repeated | Authorizations configured by code id | -| `contract_authorizations` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | repeated | Authorizations configured by contract addresses | +| `privileged_contract_addresses` | [string](#string) | repeated | List of all the contracts that have been given the privilege status via governance. They can set up hooks to abci.EndBlocker | +| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | Module params | @@ -145,75 +99,45 @@ GenesisState defines the globalfee module's genesis state. - + -## publicawesome/stargaze/globalfee/v1/proposal.proto - - - - - -### RemoveCodeAuthorizationProposal - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | | -| `description` | [string](#string) | | | -| `code_id` | [uint64](#uint64) | | | - - - - +## publicawesome/stargaze/cron/v1/proposal.proto - -### RemoveContractAuthorizationProposal + +### DemotePrivilegedContractProposal +Deprecated: Do not use. To demote a contract, a +MsgDemoteFromPrivilegedContract can be invoked from the x/gov module via a v1 +governance proposal | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | | -| `description` | [string](#string) | | | -| `contract_address` | [string](#string) | | | +| `title` | [string](#string) | | Title is a short summary | +| `description` | [string](#string) | | Description is a human readable text | +| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - - -### SetCodeAuthorizationProposal - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | | -| `description` | [string](#string) | | | -| `code_authorization` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | | | - - - - - - - - -### SetContractAuthorizationProposal + +### PromoteToPrivilegedContractProposal +Deprecated: Do not use. To promote a contract, a +MsgPromoteToPrivilegedContract can be invoked from the x/gov module via a v1 +governance proposal | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `title` | [string](#string) | | | -| `description` | [string](#string) | | | -| `contract_authorization` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | | | +| `title` | [string](#string) | | Title is a short summary | +| `description` | [string](#string) | | Description is a human readable text | +| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | @@ -229,118 +153,61 @@ GenesisState defines the globalfee module's genesis state. - + -## publicawesome/stargaze/globalfee/v1/query.proto - - - - - -### QueryAuthorizationsRequest - - - - - - - - - -### QueryAuthorizationsResponse - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `code_authorizations` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | repeated | | -| `contract_authorizations` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | repeated | | - - - - - +## publicawesome/stargaze/cron/v1/query.proto - -### QueryCodeAuthorizationRequest + +### QueryListPrivilegedRequest +QueryListPrivilegedRequest is request type for the Query/ListPrivileged RPC +method. -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `code_id` | [uint64](#uint64) | | | - - - - - - - - -### QueryCodeAuthorizationResponse - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `methods` | [string](#string) | repeated | | + - - -### QueryContractAuthorizationRequest - +### QueryListPrivilegedResponse +QueryListPrivilegedResponse is response type for the Query/ListPrivileged RPC +method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `contract_address` | [string](#string) | | | - - +| `contract_addresses` | [string](#string) | repeated | contract_addresses holds all the smart contract addresses which have privilege status. | - -### QueryContractAuthorizationResponse - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `methods` | [string](#string) | repeated | | - - - - - - - + ### QueryParamsRequest +QueryParamsRequest is request type for the Query/Params RPC +method. - - + ### QueryParamsResponse - +QueryParamsResponse is response type for the Query/Params RPC +method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | | +| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | | @@ -353,100 +220,46 @@ GenesisState defines the globalfee module's genesis state. - + ### Query Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `CodeAuthorization` | [QueryCodeAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationRequest) | [QueryCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryCodeAuthorizationResponse) | | GET|/stargaze/globalfee/v1/code_authorization/{code_id}| -| `ContractAuthorization` | [QueryContractAuthorizationRequest](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationRequest) | [QueryContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.QueryContractAuthorizationResponse) | | GET|/stargaze/globalfee/v1/contract_authorization/{contract_address}| -| `Params` | [QueryParamsRequest](#publicawesome.stargaze.globalfee.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.globalfee.v1.QueryParamsResponse) | | GET|/stargaze/globalfee/v1/params| -| `Authorizations` | [QueryAuthorizationsRequest](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsRequest) | [QueryAuthorizationsResponse](#publicawesome.stargaze.globalfee.v1.QueryAuthorizationsResponse) | | GET|/stargaze/globalfee/v1/authorizations| +| `ListPrivileged` | [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) | [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) | ListPrivileged queries the contracts which have the priviledge status | GET|/stargaze/cron/v1/list-privileged| +| `Params` | [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) | | GET|/stargaze/cron/v1/params| - + -## publicawesome/stargaze/globalfee/v1/tx.proto - - - - - -### MsgRemoveCodeAuthorization - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `code_id` | [uint64](#uint64) | | | - - - - - - - - -### MsgRemoveCodeAuthorizationResponse - - - - - - - - - -### MsgRemoveContractAuthorization - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `contract_address` | [string](#string) | | | - - - - - - - - -### MsgRemoveContractAuthorizationResponse - - - - +## publicawesome/stargaze/cron/v1/tx.proto - + -### MsgSetCodeAuthorization +### MsgDemoteFromPrivilegedContract | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `code_authorization` | [CodeAuthorization](#publicawesome.stargaze.globalfee.v1.CodeAuthorization) | | | +| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | +| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - + -### MsgSetCodeAuthorizationResponse +### MsgDemoteFromPrivilegedContractResponse @@ -454,25 +267,25 @@ Query defines the gRPC querier service. - + -### MsgSetContractAuthorization +### MsgPromoteToPrivilegedContract | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `contract_authorization` | [ContractAuthorization](#publicawesome.stargaze.globalfee.v1.ContractAuthorization) | | | +| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | +| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - + -### MsgSetContractAuthorizationResponse +### MsgPromoteToPrivilegedContractResponse @@ -480,7 +293,7 @@ Query defines the gRPC querier service. - + ### MsgUpdateParams @@ -488,15 +301,15 @@ Query defines the gRPC querier service. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `params` | [Params](#publicawesome.stargaze.globalfee.v1.Params) | | NOTE: All parameters must be supplied. | +| `authority` | [string](#string) | | Authority is the address of the governance account. | +| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | NOTE: All parameters must be supplied. | - + ### MsgUpdateParamsResponse @@ -512,18 +325,16 @@ Query defines the gRPC querier service. - + ### Msg Msg defines the alloc Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `SetCodeAuthorization` | [MsgSetCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorization) | [MsgSetCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetCodeAuthorizationResponse) | | | -| `RemoveCodeAuthorization` | [MsgRemoveCodeAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorization) | [MsgRemoveCodeAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveCodeAuthorizationResponse) | | | -| `SetContractAuthorization` | [MsgSetContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorization) | [MsgSetContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgSetContractAuthorizationResponse) | | | -| `RemoveContractAuthorization` | [MsgRemoveContractAuthorization](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorization) | [MsgRemoveContractAuthorizationResponse](#publicawesome.stargaze.globalfee.v1.MsgRemoveContractAuthorizationResponse) | | | -| `UpdateParams` | [MsgUpdateParams](#publicawesome.stargaze.globalfee.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#publicawesome.stargaze.globalfee.v1.MsgUpdateParamsResponse) | | | +| `PromoteToPrivilegedContract` | [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) | [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) | | | +| `DemoteFromPrivilegedContract` | [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) | [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) | | | +| `UpdateParams` | [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) | | | diff --git a/proto/publicawesome/stargaze/authority/v1/authority.proto b/proto/publicawesome/stargaze/authority/v1/authority.proto index 29f96b3df..3ae1b7499 100644 --- a/proto/publicawesome/stargaze/authority/v1/authority.proto +++ b/proto/publicawesome/stargaze/authority/v1/authority.proto @@ -13,5 +13,5 @@ message Params { message Authorization { string msgTypeUrl = 1; // The type url of a proposal sdk.Msg - string address = 2; // The address who is allowed to execute that proposal + repeated string addresses = 2; // The addresses who are allowed to execute that proposal } \ No newline at end of file diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index b691bc273..cf468e469 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -3,6 +3,7 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/public-awesome/stargaze/v13/x/authority/types" ) @@ -33,7 +34,10 @@ func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteP return nil, err } - IsAuthorized(ctx, proposalMsgs) + valid, err := m.Keeper.IsAuthorized(ctx, proposalMsgs, msg.GetAuthority()) + if !valid { + return nil, err + } _, err = m.Keeper.SubmitProposal(ctx, proposalMsgs, proposer) if err != nil { @@ -43,13 +47,19 @@ func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteP return &types.MsgExecuteProposalResponse{}, nil } -func IsAuthorized(ctx sdk.Context, msgs []sdk.Msg) bool { - // loop through msgs - for _, msg := range msgs { - test := sdk.MsgTypeURL(msg) - panic(test) +func (keeper Keeper) IsAuthorized(ctx sdk.Context, msgs []sdk.Msg, proposer string) (bool, error) { + authorizations := keeper.GetParams(ctx).Authorizations + for _, msg := range msgs { // Checking authorizations for all the msgs in the proposal + msgType := sdk.MsgTypeURL(msg) + auth, found := types.GetMsgAuthorization(msgType, authorizations) + if !found { + return false, errorsmod.Wrap(types.ErrAuthorizationNotFound, "authorization not found for given msg type: "+msgType) + } + + if !auth.IsAuthorized(proposer) { + return false, errorsmod.Wrap(types.ErrUnauthorized, "authority address is not authorized address to ") + } + } - return false + return true, nil } - -// /cosmos.distribution.v1beta1.MsgCommunityPoolSpend diff --git a/x/authority/keeper/params.go b/x/authority/keeper/params.go new file mode 100644 index 000000000..3001df218 --- /dev/null +++ b/x/authority/keeper/params.go @@ -0,0 +1,29 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +// SetParams sets the total set of minting parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := ctx.KVStore(k.storeKey) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + store.Set(types.ParamsKey, bz) + return nil +} + +// GetParams returns the total set of minting parameters. +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return params + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} diff --git a/x/authority/types/authority.pb.go b/x/authority/types/authority.pb.go index 7226106f5..6ec041330 100644 --- a/x/authority/types/authority.pb.go +++ b/x/authority/types/authority.pb.go @@ -68,8 +68,8 @@ func (m *Params) GetAuthorizations() []*Authorization { } type Authorization struct { - MsgTypeUrl string `protobuf:"bytes,1,opt,name=msgTypeUrl,proto3" json:"msgTypeUrl,omitempty"` - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + MsgTypeUrl string `protobuf:"bytes,1,opt,name=msgTypeUrl,proto3" json:"msgTypeUrl,omitempty"` + Address []string `protobuf:"bytes,2,rep,name=address,proto3" json:"address,omitempty"` } func (m *Authorization) Reset() { *m = Authorization{} } @@ -112,11 +112,11 @@ func (m *Authorization) GetMsgTypeUrl() string { return "" } -func (m *Authorization) GetAddress() string { +func (m *Authorization) GetAddress() []string { if m != nil { return m.Address } - return "" + return nil } func init() { @@ -129,7 +129,7 @@ func init() { } var fileDescriptor_6e13d9034052c38a = []byte{ - // 252 bytes of a gzipped FileDescriptorProto + // 255 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2e, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0x44, @@ -140,12 +140,12 @@ var fileDescriptor_6e13d9034052c38a = []byte{ 0x44, 0x98, 0xae, 0xe7, 0x88, 0xac, 0x35, 0x08, 0xcd, 0x24, 0x2b, 0x96, 0x19, 0x0b, 0xe4, 0x19, 0x94, 0x3c, 0xb9, 0x78, 0x51, 0x94, 0x09, 0xc9, 0x71, 0x71, 0xe5, 0x16, 0xa7, 0x87, 0x54, 0x16, 0xa4, 0x86, 0x16, 0xe5, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x89, 0x08, 0x49, 0x70, - 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x81, 0x25, 0x61, 0x5c, 0xa7, 0xa0, - 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, - 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xb2, 0x48, 0xcf, 0x2c, 0xc9, 0x28, - 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x38, 0x5c, 0x17, 0x23, 0x30, 0xcb, 0x0c, 0x8d, 0xf5, - 0x2b, 0x90, 0x82, 0xb4, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0x1c, 0x22, 0xc6, 0x80, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x9a, 0x2e, 0xd2, 0x5a, 0x83, 0x01, 0x00, 0x00, + 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6b, 0x70, 0x06, 0xc1, + 0xb8, 0x4e, 0x41, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, + 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x91, 0x9e, + 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x71, 0xb8, 0x2e, 0x46, 0x60, 0x96, + 0x19, 0x1a, 0xeb, 0x57, 0x20, 0x05, 0x69, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0x44, + 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0xaf, 0xaf, 0x43, 0x83, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -206,11 +206,13 @@ func (m *Authorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) - i = encodeVarintAuthority(dAtA, i, uint64(len(m.Address))) - i-- - dAtA[i] = 0x12 + for iNdEx := len(m.Address) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Address[iNdEx]) + copy(dAtA[i:], m.Address[iNdEx]) + i = encodeVarintAuthority(dAtA, i, uint64(len(m.Address[iNdEx]))) + i-- + dAtA[i] = 0x12 + } } if len(m.MsgTypeUrl) > 0 { i -= len(m.MsgTypeUrl) @@ -258,9 +260,11 @@ func (m *Authorization) Size() (n int) { if l > 0 { n += 1 + l + sovAuthority(uint64(l)) } - l = len(m.Address) - if l > 0 { - n += 1 + l + sovAuthority(uint64(l)) + if len(m.Address) > 0 { + for _, s := range m.Address { + l = len(s) + n += 1 + l + sovAuthority(uint64(l)) + } } return n } @@ -446,7 +450,7 @@ func (m *Authorization) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = string(dAtA[iNdEx:postIndex]) + m.Address = append(m.Address, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/authority/types/authorization.go b/x/authority/types/authorization.go new file mode 100644 index 000000000..4b1415417 --- /dev/null +++ b/x/authority/types/authorization.go @@ -0,0 +1,41 @@ +package types + +import ( + fmt "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func GetMsgAuthorization(msgTypeUrl string, authorizations []*Authorization) (*Authorization, bool) { + for _, auth := range authorizations { + if auth.MsgTypeUrl == msgTypeUrl { + return auth, true + } + } + return &Authorization{}, false +} + +func (a Authorization) IsAuthorized(proposer string) bool { + for _, addr := range a.Address { + if addr == proposer { + return true + } + } + return false +} + +func (a Authorization) Validate() error { + if len(a.Address) == 0 { + return fmt.Errorf("addresses cannot be empty") + } + for _, addr := range a.Address { + _, err := sdk.AccAddressFromBech32(addr) + if err != nil { + return err + } + } + if len(a.MsgTypeUrl) == 0 { + return fmt.Errorf("msg type url cannot be empty") + } + return nil +} diff --git a/x/authority/types/errors.go b/x/authority/types/errors.go new file mode 100644 index 000000000..db9a3fff8 --- /dev/null +++ b/x/authority/types/errors.go @@ -0,0 +1,13 @@ +package types + +// DONTCOVER + +import ( + errorsmod "cosmossdk.io/errors" +) + +// x/cron module sentinel errors +var ( + ErrUnauthorized = errorsmod.Register(ModuleName, 2, "sender is unauthorized to perform the operation") + ErrAuthorizationNotFound = errorsmod.Register(ModuleName, 3, "") +) diff --git a/x/authority/types/keys.go b/x/authority/types/keys.go index 487fedde6..7ea00103c 100644 --- a/x/authority/types/keys.go +++ b/x/authority/types/keys.go @@ -13,3 +13,7 @@ const ( // MemStoreKey defines the in-memory store key MemStoreKey = "mem_authority" ) + +var ( + ParamsKey = []byte{0x01} +) diff --git a/x/authority/types/params.go b/x/authority/types/params.go new file mode 100644 index 000000000..6d69672e5 --- /dev/null +++ b/x/authority/types/params.go @@ -0,0 +1,32 @@ +package types + +import ( + "gopkg.in/yaml.v2" +) + +// default module parameters +func DefaultParams() Params { + return Params{ + Authorizations: []*Authorization{}, + } +} + +func NewParams(authorizations []*Authorization) Params { + return Params{ + Authorizations: authorizations, + } +} + +func (p Params) Validate() error { + for _, auth := range p.GetAuthorizations() { + if err := auth.Validate(); err != nil { + return err + } + } + return nil +} + +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} diff --git a/x/authority/types/params_test.go b/x/authority/types/params_test.go new file mode 100644 index 000000000..3a7269704 --- /dev/null +++ b/x/authority/types/params_test.go @@ -0,0 +1,93 @@ +package types_test + +import ( + "testing" + + "github.com/public-awesome/stargaze/v13/x/authority/types" + "github.com/stretchr/testify/require" +) + +func TestParamsValidate(t *testing.T) { + testCases := []struct { + testCase string + p types.Params + expectError bool + }{ + { + "ok: empty params", + types.Params{}, + false, + }, + { + "fail: no addrs", + types.Params{ + Authorizations: []*types.Authorization{ + { + Address: []string{}, + MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + }, + }, + }, + true, + }, + { + "fail: invalid addr", + types.Params{ + Authorizations: []*types.Authorization{ + { + Address: []string{ + "👻", + }, + MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + }, + }, + }, + true, + }, + { + "fail: valid addr but empty msg type url", + types.Params{ + Authorizations: []*types.Authorization{ + { + Address: []string{ + "cosmos1c4k24jzduc365kywrsvf5ujz4ya6mwymy8vq4q", + }, + MsgTypeUrl: "", + }, + }, + }, + true, + }, + { + "ok: all valid input", + types.Params{ + Authorizations: []*types.Authorization{ + { + Address: []string{ + "cosmos1c4k24jzduc365kywrsvf5ujz4ya6mwymy8vq4q", + }, + MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + }, + }, + }, + false, + }, + { + "ok: default params", + types.DefaultParams(), + false, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.testCase, func(t *testing.T) { + err := tc.p.Validate() + if tc.expectError { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} From cc225c72830f249582c459610acb205d4086bc3b Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Fri, 20 Oct 2023 21:31:41 +0530 Subject: [PATCH 05/20] adding params and query --- docs/proto/proto-docs.md | 238 +++----- .../stargaze/authority/v1/query.proto | 18 + x/authority/client/cli/query.go | 56 ++ x/authority/keeper/grpc_query.go | 27 + x/authority/keeper/msg_server.go | 23 - x/authority/keeper/params.go | 15 +- x/authority/keeper/proposal.go | 38 +- x/authority/module.go | 13 +- x/authority/types/authority.pb.go | 43 +- x/authority/types/authorization.go | 6 +- x/authority/types/params.go | 11 +- x/authority/types/params_test.go | 8 +- x/authority/types/query.pb.go | 538 ++++++++++++++++++ x/authority/types/query.pb.gw.go | 153 +++++ 14 files changed, 957 insertions(+), 230 deletions(-) create mode 100644 proto/publicawesome/stargaze/authority/v1/query.proto create mode 100644 x/authority/client/cli/query.go create mode 100644 x/authority/keeper/grpc_query.go create mode 100644 x/authority/types/query.pb.go create mode 100644 x/authority/types/query.pb.gw.go diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index bb766e02b..f0e20217d 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,86 +4,84 @@ ## Table of Contents -- [publicawesome/stargaze/cron/v1/cron.proto](#publicawesome/stargaze/cron/v1/cron.proto) - - [Params](#publicawesome.stargaze.cron.v1.Params) +- [publicawesome/stargaze/alloc/v1beta1/params.proto](#publicawesome/stargaze/alloc/v1beta1/params.proto) + - [DistributionProportions](#publicawesome.stargaze.alloc.v1beta1.DistributionProportions) + - [Params](#publicawesome.stargaze.alloc.v1beta1.Params) + - [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) -- [publicawesome/stargaze/cron/v1/genesis.proto](#publicawesome/stargaze/cron/v1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.cron.v1.GenesisState) +- [publicawesome/stargaze/alloc/v1beta1/genesis.proto](#publicawesome/stargaze/alloc/v1beta1/genesis.proto) + - [GenesisState](#publicawesome.stargaze.alloc.v1beta1.GenesisState) -- [publicawesome/stargaze/cron/v1/proposal.proto](#publicawesome/stargaze/cron/v1/proposal.proto) - - [DemotePrivilegedContractProposal](#publicawesome.stargaze.cron.v1.DemotePrivilegedContractProposal) - - [PromoteToPrivilegedContractProposal](#publicawesome.stargaze.cron.v1.PromoteToPrivilegedContractProposal) +- [publicawesome/stargaze/alloc/v1beta1/query.proto](#publicawesome/stargaze/alloc/v1beta1/query.proto) + - [QueryParamsRequest](#publicawesome.stargaze.alloc.v1beta1.QueryParamsRequest) + - [QueryParamsResponse](#publicawesome.stargaze.alloc.v1beta1.QueryParamsResponse) -- [publicawesome/stargaze/cron/v1/query.proto](#publicawesome/stargaze/cron/v1/query.proto) - - [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) - - [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) - - [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) - - [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) + - [Query](#publicawesome.stargaze.alloc.v1beta1.Query) - - [Query](#publicawesome.stargaze.cron.v1.Query) +- [publicawesome/stargaze/alloc/v1beta1/tx.proto](#publicawesome/stargaze/alloc/v1beta1/tx.proto) + - [MsgCreateVestingAccount](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccount) + - [MsgCreateVestingAccountResponse](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccountResponse) + - [MsgFundFairburnPool](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPool) + - [MsgFundFairburnPoolResponse](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPoolResponse) -- [publicawesome/stargaze/cron/v1/tx.proto](#publicawesome/stargaze/cron/v1/tx.proto) - - [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) - - [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) - - [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) - - [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) - - [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) - - [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) - - - [Msg](#publicawesome.stargaze.cron.v1.Msg) + - [Msg](#publicawesome.stargaze.alloc.v1beta1.Msg) - [Scalar Value Types](#scalar-value-types) - + -## publicawesome/stargaze/cron/v1/cron.proto +## publicawesome/stargaze/alloc/v1beta1/params.proto - + + +### DistributionProportions -### Params -Params holds parameters for the cron module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `admin_addresses` | [string](#string) | repeated | Addresses which act as admins of the module. They can promote and demote contracts without having to go via governance. | +| `nft_incentives` | [string](#string) | | | +| `developer_rewards` | [string](#string) | | | +| `community_pool` | [string](#string) | | | - - + - +### Params - +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `distribution_proportions` | [DistributionProportions](#publicawesome.stargaze.alloc.v1beta1.DistributionProportions) | | distribution_proportions defines the proportion of the minted denom | +| `weighted_developer_rewards_receivers` | [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) | repeated | addresses to receive developer rewards | +| `weighted_incentives_rewards_receivers` | [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) | repeated | addresses to receive incentive rewards | +| `supplement_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | SupplementAmount is the amount to be supplemented from the pool on top of newly minted coins. | - - -## publicawesome/stargaze/cron/v1/genesis.proto - -### GenesisState -GenesisState defines the cron module's genesis state. + + +### WeightedAddress + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `privileged_contract_addresses` | [string](#string) | repeated | List of all the contracts that have been given the privilege status via governance. They can set up hooks to abci.EndBlocker | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | Module params | +| `address` | [string](#string) | | | +| `weight` | [string](#string) | | | @@ -99,45 +97,22 @@ GenesisState defines the cron module's genesis state. - + -## publicawesome/stargaze/cron/v1/proposal.proto - - - - - -### DemotePrivilegedContractProposal -Deprecated: Do not use. To demote a contract, a -MsgDemoteFromPrivilegedContract can be invoked from the x/gov module via a v1 -governance proposal - - -| 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 bech32 address of the smart contract | +## publicawesome/stargaze/alloc/v1beta1/genesis.proto + - - - - -### PromoteToPrivilegedContractProposal -Deprecated: Do not use. To promote a contract, a -MsgPromoteToPrivilegedContract can be invoked from the x/gov module via a v1 -governance proposal +### GenesisState +GenesisState defines the alloc module's genesis state. | 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 bech32 address of the smart contract | +| `params` | [Params](#publicawesome.stargaze.alloc.v1beta1.Params) | | this line is used by starport scaffolding # genesis/proto/state | @@ -153,61 +128,32 @@ governance proposal - + -## publicawesome/stargaze/cron/v1/query.proto - - - - - -### QueryListPrivilegedRequest -QueryListPrivilegedRequest is request type for the Query/ListPrivileged RPC -method. - - - - +## publicawesome/stargaze/alloc/v1beta1/query.proto - -### QueryListPrivilegedResponse -QueryListPrivilegedResponse is response type for the Query/ListPrivileged RPC -method. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `contract_addresses` | [string](#string) | repeated | contract_addresses holds all the smart contract addresses which have privilege status. | - - - - - - - + ### QueryParamsRequest -QueryParamsRequest is request type for the Query/Params RPC -method. +QueryParamsRequest is the request type for the Query/Params RPC method. - + ### QueryParamsResponse -QueryParamsResponse is response type for the Query/Params RPC -method. +QueryParamsResponse is the response type for the Query/Params RPC method. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | | +| `params` | [Params](#publicawesome.stargaze.alloc.v1beta1.Params) | | params defines the parameters of the module. | @@ -220,99 +166,80 @@ method. - + ### Query Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `ListPrivileged` | [QueryListPrivilegedRequest](#publicawesome.stargaze.cron.v1.QueryListPrivilegedRequest) | [QueryListPrivilegedResponse](#publicawesome.stargaze.cron.v1.QueryListPrivilegedResponse) | ListPrivileged queries the contracts which have the priviledge status | GET|/stargaze/cron/v1/list-privileged| -| `Params` | [QueryParamsRequest](#publicawesome.stargaze.cron.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.cron.v1.QueryParamsResponse) | | GET|/stargaze/cron/v1/params| +| `Params` | [QueryParamsRequest](#publicawesome.stargaze.alloc.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.alloc.v1beta1.QueryParamsResponse) | this line is used by starport scaffolding # 2 | GET|/stargaze/alloc/v1beta1/params| - + -## publicawesome/stargaze/cron/v1/tx.proto - - - - - -### MsgDemoteFromPrivilegedContract - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | -| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - - - - - - - - -### MsgDemoteFromPrivilegedContractResponse +## publicawesome/stargaze/alloc/v1beta1/tx.proto + - - - - - -### MsgPromoteToPrivilegedContract - +### MsgCreateVestingAccount +MsgCreateVestingAccount defines a message that enables creating a vesting +account. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account or any whitelisted address | -| `contract` | [string](#string) | | Contract is the bech32 address of the smart contract | - +| `from_address` | [string](#string) | | | +| `to_address` | [string](#string) | | | +| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `start_time` | [int64](#int64) | | | +| `end_time` | [int64](#int64) | | | +| `delayed` | [bool](#bool) | | | - -### MsgPromoteToPrivilegedContractResponse + +### MsgCreateVestingAccountResponse +MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response +type. - - -### MsgUpdateParams + +### MsgFundFairburnPool +MsgFundFairburnPool allows an account to directly +fund the fee collector pool. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authority` | [string](#string) | | Authority is the address of the governance account. | -| `params` | [Params](#publicawesome.stargaze.cron.v1.Params) | | NOTE: All parameters must be supplied. | - +| `sender` | [string](#string) | | | +| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | - -### MsgUpdateParamsResponse + +### MsgFundFairburnPoolResponse +MsgFundFairburnPoolResponse defines the Msg/MsgFundFairburnPool response +type. @@ -325,16 +252,15 @@ Query defines the gRPC querier service. - + ### Msg Msg defines the alloc Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `PromoteToPrivilegedContract` | [MsgPromoteToPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContract) | [MsgPromoteToPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgPromoteToPrivilegedContractResponse) | | | -| `DemoteFromPrivilegedContract` | [MsgDemoteFromPrivilegedContract](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContract) | [MsgDemoteFromPrivilegedContractResponse](#publicawesome.stargaze.cron.v1.MsgDemoteFromPrivilegedContractResponse) | | | -| `UpdateParams` | [MsgUpdateParams](#publicawesome.stargaze.cron.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#publicawesome.stargaze.cron.v1.MsgUpdateParamsResponse) | | | +| `CreateVestingAccount` | [MsgCreateVestingAccount](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | | +| `FundFairburnPool` | [MsgFundFairburnPool](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPool) | [MsgFundFairburnPoolResponse](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPoolResponse) | FundFairburnPool defines a method to allow an account to directly fund the fee collector module account. | | diff --git a/proto/publicawesome/stargaze/authority/v1/query.proto b/proto/publicawesome/stargaze/authority/v1/query.proto new file mode 100644 index 000000000..9671a4770 --- /dev/null +++ b/proto/publicawesome/stargaze/authority/v1/query.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; +package publicawesome.stargaze.authority.v1; + +import "google/api/annotations.proto"; +import "publicawesome/stargaze/authority/v1/authority.proto"; + +option go_package = "github.com/public-awesome/stargaze/v13/x/authority/types"; + +// Query defines the gRPC querier service. +service Query { + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/stargaze/authority/v1/params"; + } +} + +message QueryParamsRequest {} + +message QueryParamsResponse { Params params = 1; } \ No newline at end of file diff --git a/x/authority/client/cli/query.go b/x/authority/client/cli/query.go new file mode 100644 index 000000000..21c7eab77 --- /dev/null +++ b/x/authority/client/cli/query.go @@ -0,0 +1,56 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(_ string) *cobra.Command { + // Group cron queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(GetCmdParams()) + // this line is used by starport scaffolding # 1 + + return cmd +} + +// GetCmdParams displays the module params +func GetCmdParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "Query the module params", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Params( + cmd.Context(), + &types.QueryParamsRequest{}, + ) + if err != nil { + return err + } + return clientCtx.PrintProto(res) + }, + } + flags.AddQueryFlagsToCmd(cmd) + return cmd +} diff --git a/x/authority/keeper/grpc_query.go b/x/authority/keeper/grpc_query.go new file mode 100644 index 000000000..d0d54651d --- /dev/null +++ b/x/authority/keeper/grpc_query.go @@ -0,0 +1,27 @@ +package keeper + +import ( + "context" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/public-awesome/stargaze/v13/x/authority/types" +) + +var _ types.QueryServer = Keeper{} + +// Params fetches all the params of x/authority module +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + params := k.GetParams(ctx) + + return &types.QueryParamsResponse{ + Params: ¶ms, + }, nil +} diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index cf468e469..f579edf4c 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -3,7 +3,6 @@ package keeper import ( "context" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/public-awesome/stargaze/v13/x/authority/types" ) @@ -34,11 +33,6 @@ func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteP return nil, err } - valid, err := m.Keeper.IsAuthorized(ctx, proposalMsgs, msg.GetAuthority()) - if !valid { - return nil, err - } - _, err = m.Keeper.SubmitProposal(ctx, proposalMsgs, proposer) if err != nil { return nil, err @@ -46,20 +40,3 @@ func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteP return &types.MsgExecuteProposalResponse{}, nil } - -func (keeper Keeper) IsAuthorized(ctx sdk.Context, msgs []sdk.Msg, proposer string) (bool, error) { - authorizations := keeper.GetParams(ctx).Authorizations - for _, msg := range msgs { // Checking authorizations for all the msgs in the proposal - msgType := sdk.MsgTypeURL(msg) - auth, found := types.GetMsgAuthorization(msgType, authorizations) - if !found { - return false, errorsmod.Wrap(types.ErrAuthorizationNotFound, "authorization not found for given msg type: "+msgType) - } - - if !auth.IsAuthorized(proposer) { - return false, errorsmod.Wrap(types.ErrUnauthorized, "authority address is not authorized address to ") - } - - } - return true, nil -} diff --git a/x/authority/keeper/params.go b/x/authority/keeper/params.go index 3001df218..84510af40 100644 --- a/x/authority/keeper/params.go +++ b/x/authority/keeper/params.go @@ -18,12 +18,13 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { // GetParams returns the total set of minting parameters. func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) - if bz == nil { - return params - } + // store := ctx.KVStore(k.storeKey) + // bz := store.Get(types.ParamsKey) + // if bz == nil { + // return params + // } - k.cdc.MustUnmarshal(bz, ¶ms) - return params + // k.cdc.MustUnmarshal(bz, ¶ms) + //return params + return types.DefaultParams() } diff --git a/x/authority/keeper/proposal.go b/x/authority/keeper/proposal.go index 2a91b1e9f..8ce60167d 100644 --- a/x/authority/keeper/proposal.go +++ b/x/authority/keeper/proposal.go @@ -6,8 +6,9 @@ import ( errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/gov/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + "github.com/public-awesome/stargaze/v13/x/authority/types" ) // IterateActiveProposalsQueue iterates over the proposals in the active proposal queue @@ -17,7 +18,7 @@ func (k Keeper) IterateActiveProposalsQueue(ctx sdk.Context, cb func(proposal go defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - proposalID := types.GetProposalIDFromBytes(iterator.Value()) + proposalID := govtypes.GetProposalIDFromBytes(iterator.Value()) proposal, found := k.GetProposal(ctx, proposalID) if !found { panic(fmt.Sprintf("proposal %d does not exist", proposalID)) @@ -31,7 +32,7 @@ func (k Keeper) IterateActiveProposalsQueue(ctx sdk.Context, cb func(proposal go // ActiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Active Queue func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context) sdk.Iterator { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ActiveProposalQueuePrefix) + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), govtypes.ActiveProposalQueuePrefix) return prefixStore.Iterator(nil, nil) } @@ -39,7 +40,7 @@ func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context) sdk.Iterator { func (k Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (govV1.Proposal, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ProposalKey(proposalID)) + bz := store.Get(govtypes.ProposalKey(proposalID)) if bz == nil { return govV1.Proposal{}, false } @@ -81,27 +82,32 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, propose // perform a basic validation of the message if err := msg.ValidateBasic(); err != nil { - return 0, errorsmod.Wrap(types.ErrInvalidProposalMsg, err.Error()) + return 0, errorsmod.Wrap(govtypes.ErrInvalidProposalMsg, err.Error()) } signers := msg.GetSigners() if len(signers) != 1 { - return 0, types.ErrInvalidSigner + return 0, govtypes.ErrInvalidSigner } - // // assert that the governance module account is the only signer of the messages + // // assert that the authority module account is the only signer of the messages // if !signers[0].Equals(keeper.GetGovernanceAccount(ctx).GetAddress()) { // return v1.Proposal{}, sdkerrors.Wrapf(types.ErrInvalidSigner, signers[0].String()) // } + valid, err := keeper.IsAuthorized(ctx, msg, proposer.String()) + if !valid { + return 0, err + } + // use the msg service router to see that there is a valid route for that message. handler := keeper.router.Handler(msg) if handler == nil { - return 0, errorsmod.Wrap(types.ErrUnroutableProposalMsg, sdk.MsgTypeURL(msg)) + return 0, errorsmod.Wrap(govtypes.ErrUnroutableProposalMsg, sdk.MsgTypeURL(msg)) } var res *sdk.Result - res, err := handler(ctx, msg) + res, err = handler(ctx, msg) if err != nil { return 0, err } @@ -113,6 +119,20 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, propose return 0, nil } +func (keeper Keeper) IsAuthorized(ctx sdk.Context, msg sdk.Msg, proposer string) (bool, error) { + authorizations := keeper.GetParams(ctx).Authorizations + msgType := sdk.MsgTypeURL(msg) + auth, found := types.GetMsgAuthorization(msgType, authorizations) + if !found { + return false, errorsmod.Wrap(types.ErrAuthorizationNotFound, "authorization not found for given msg type: "+msgType) + } + + if !auth.IsAuthorized(proposer) { + return false, errorsmod.Wrap(govtypes.ErrInvalidSigner, "sender address"+proposer+" is not authorized address to execute"+msgType) + } + return true, nil +} + // // SetProposal set a proposal to store // func (k Keeper) SetProposal(ctx sdk.Context, proposal govV1.Proposal) { // store := ctx.KVStore(k.storeKey) diff --git a/x/authority/module.go b/x/authority/module.go index 693eaa1c9..27f4a376e 100644 --- a/x/authority/module.go +++ b/x/authority/module.go @@ -1,6 +1,7 @@ package authority import ( + "context" "encoding/json" "fmt" @@ -70,10 +71,10 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - // err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) - // if err != nil { - // panic(err) - // } + err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) + if err != nil { + panic(err) + } } // GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module @@ -83,7 +84,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil //cli.GetQueryCmd(types.StoreKey) + return cli.GetQueryCmd(types.StoreKey) } // ---------------------------------------------------------------------------- @@ -111,7 +112,7 @@ func (AppModule) QuerierRoute() string { return types.RouterKey } // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries func (am AppModule) RegisterServices(cfg module.Configurator) { - //types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) } diff --git a/x/authority/types/authority.pb.go b/x/authority/types/authority.pb.go index 6ec041330..62bdf05e4 100644 --- a/x/authority/types/authority.pb.go +++ b/x/authority/types/authority.pb.go @@ -69,7 +69,7 @@ func (m *Params) GetAuthorizations() []*Authorization { type Authorization struct { MsgTypeUrl string `protobuf:"bytes,1,opt,name=msgTypeUrl,proto3" json:"msgTypeUrl,omitempty"` - Address []string `protobuf:"bytes,2,rep,name=address,proto3" json:"address,omitempty"` + Addresses []string `protobuf:"bytes,2,rep,name=addresses,proto3" json:"addresses,omitempty"` } func (m *Authorization) Reset() { *m = Authorization{} } @@ -112,9 +112,9 @@ func (m *Authorization) GetMsgTypeUrl() string { return "" } -func (m *Authorization) GetAddress() []string { +func (m *Authorization) GetAddresses() []string { if m != nil { - return m.Address + return m.Addresses } return nil } @@ -129,7 +129,7 @@ func init() { } var fileDescriptor_6e13d9034052c38a = []byte{ - // 255 bytes of a gzipped FileDescriptorProto + // 257 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2e, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0x44, @@ -138,14 +138,15 @@ var fileDescriptor_6e13d9034052c38a = []byte{ 0x4a, 0x59, 0x5c, 0x6c, 0x01, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x42, 0x51, 0x5c, 0x7c, 0x50, 0xf5, 0x55, 0x89, 0x25, 0x99, 0xf9, 0x79, 0xc5, 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x46, 0x7a, 0x44, 0x98, 0xae, 0xe7, 0x88, 0xac, 0x35, 0x08, 0xcd, 0x24, 0x2b, 0x96, 0x19, 0x0b, 0xe4, 0x19, - 0x94, 0x3c, 0xb9, 0x78, 0x51, 0x94, 0x09, 0xc9, 0x71, 0x71, 0xe5, 0x16, 0xa7, 0x87, 0x54, 0x16, - 0xa4, 0x86, 0x16, 0xe5, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x89, 0x08, 0x49, 0x70, - 0xb1, 0x27, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0x4b, 0x30, 0x29, 0x30, 0x6b, 0x70, 0x06, 0xc1, - 0xb8, 0x4e, 0x41, 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, - 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0x65, 0x91, 0x9e, - 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x71, 0xb8, 0x2e, 0x46, 0x60, 0x96, - 0x19, 0x1a, 0xeb, 0x57, 0x20, 0x05, 0x69, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0x44, - 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x40, 0xaf, 0xaf, 0x43, 0x83, 0x01, 0x00, 0x00, + 0x94, 0x7c, 0xb9, 0x78, 0x51, 0x94, 0x09, 0xc9, 0x71, 0x71, 0xe5, 0x16, 0xa7, 0x87, 0x54, 0x16, + 0xa4, 0x86, 0x16, 0xe5, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x21, 0x89, 0x08, 0xc9, 0x70, + 0x71, 0x26, 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x17, 0xa7, 0x16, 0x4b, 0x30, 0x29, 0x30, 0x6b, 0x70, + 0x06, 0x21, 0x04, 0x9c, 0x82, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, + 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, + 0x22, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0x1f, 0xe2, 0x78, 0x5d, 0x8c, + 0x00, 0x2d, 0x33, 0x34, 0xd6, 0xaf, 0x40, 0x0a, 0xd6, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, + 0x70, 0xa8, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xad, 0x2e, 0x16, 0xa1, 0x87, 0x01, 0x00, + 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -205,11 +206,11 @@ func (m *Authorization) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Address) > 0 { - for iNdEx := len(m.Address) - 1; iNdEx >= 0; iNdEx-- { - i -= len(m.Address[iNdEx]) - copy(dAtA[i:], m.Address[iNdEx]) - i = encodeVarintAuthority(dAtA, i, uint64(len(m.Address[iNdEx]))) + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintAuthority(dAtA, i, uint64(len(m.Addresses[iNdEx]))) i-- dAtA[i] = 0x12 } @@ -260,8 +261,8 @@ func (m *Authorization) Size() (n int) { if l > 0 { n += 1 + l + sovAuthority(uint64(l)) } - if len(m.Address) > 0 { - for _, s := range m.Address { + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { l = len(s) n += 1 + l + sovAuthority(uint64(l)) } @@ -422,7 +423,7 @@ func (m *Authorization) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -450,7 +451,7 @@ func (m *Authorization) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Address = append(m.Address, string(dAtA[iNdEx:postIndex])) + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex default: iNdEx = preIndex diff --git a/x/authority/types/authorization.go b/x/authority/types/authorization.go index 4b1415417..1df854b5f 100644 --- a/x/authority/types/authorization.go +++ b/x/authority/types/authorization.go @@ -16,7 +16,7 @@ func GetMsgAuthorization(msgTypeUrl string, authorizations []*Authorization) (*A } func (a Authorization) IsAuthorized(proposer string) bool { - for _, addr := range a.Address { + for _, addr := range a.GetAddresses() { if addr == proposer { return true } @@ -25,10 +25,10 @@ func (a Authorization) IsAuthorized(proposer string) bool { } func (a Authorization) Validate() error { - if len(a.Address) == 0 { + if len(a.GetAddresses()) == 0 { return fmt.Errorf("addresses cannot be empty") } - for _, addr := range a.Address { + for _, addr := range a.GetAddresses() { _, err := sdk.AccAddressFromBech32(addr) if err != nil { return err diff --git a/x/authority/types/params.go b/x/authority/types/params.go index 6d69672e5..5b7be16ed 100644 --- a/x/authority/types/params.go +++ b/x/authority/types/params.go @@ -7,7 +7,16 @@ import ( // default module parameters func DefaultParams() Params { return Params{ - Authorizations: []*Authorization{}, + Authorizations: []*Authorization{ + { + MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", + Addresses: []string{"stars1x394ype3x8nt9wz0j78m8c8kcezpslrcjmmrc0"}, + }, + { + MsgTypeUrl: "/cosmwasm.wasm.v1.MsgUpdateParams", + Addresses: []string{"stars1mzgucqnfr2l8cj5apvdpllhzt4zeuh2cyt4fdd"}, + }, + }, } } diff --git a/x/authority/types/params_test.go b/x/authority/types/params_test.go index 3a7269704..05b9f5397 100644 --- a/x/authority/types/params_test.go +++ b/x/authority/types/params_test.go @@ -23,7 +23,7 @@ func TestParamsValidate(t *testing.T) { types.Params{ Authorizations: []*types.Authorization{ { - Address: []string{}, + Addresses: []string{}, MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", }, }, @@ -35,7 +35,7 @@ func TestParamsValidate(t *testing.T) { types.Params{ Authorizations: []*types.Authorization{ { - Address: []string{ + Addresses: []string{ "👻", }, MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", @@ -49,7 +49,7 @@ func TestParamsValidate(t *testing.T) { types.Params{ Authorizations: []*types.Authorization{ { - Address: []string{ + Addresses: []string{ "cosmos1c4k24jzduc365kywrsvf5ujz4ya6mwymy8vq4q", }, MsgTypeUrl: "", @@ -63,7 +63,7 @@ func TestParamsValidate(t *testing.T) { types.Params{ Authorizations: []*types.Authorization{ { - Address: []string{ + Addresses: []string{ "cosmos1c4k24jzduc365kywrsvf5ujz4ya6mwymy8vq4q", }, MsgTypeUrl: "/cosmos.distribution.v1beta1.MsgCommunityPoolSpend", diff --git a/x/authority/types/query.pb.go b/x/authority/types/query.pb.go new file mode 100644 index 000000000..f84dedbe3 --- /dev/null +++ b/x/authority/types/query.pb.go @@ -0,0 +1,538 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: publicawesome/stargaze/authority/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + 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. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_fabfb73dd8f1f863, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +type QueryParamsResponse struct { + Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fabfb73dd8f1f863, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *Params { + if m != nil { + return m.Params + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "publicawesome.stargaze.authority.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "publicawesome.stargaze.authority.v1.QueryParamsResponse") +} + +func init() { + proto.RegisterFile("publicawesome/stargaze/authority/v1/query.proto", fileDescriptor_fabfb73dd8f1f863) +} + +var fileDescriptor_fabfb73dd8f1f863 = []byte{ + // 283 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x2f, 0x28, 0x4d, 0xca, + 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, + 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, + 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x46, 0xd1, 0xa0, + 0x07, 0xd3, 0xa0, 0x07, 0xd7, 0xa0, 0x57, 0x66, 0x28, 0x25, 0x93, 0x9e, 0x9f, 0x9f, 0x9e, 0x93, + 0xaa, 0x9f, 0x58, 0x90, 0xa9, 0x9f, 0x98, 0x97, 0x97, 0x5f, 0x92, 0x58, 0x92, 0x99, 0x9f, 0x57, + 0x0c, 0x31, 0x42, 0xca, 0x98, 0x18, 0x3b, 0x11, 0xe6, 0x81, 0x35, 0x29, 0x89, 0x70, 0x09, 0x05, + 0x82, 0x9c, 0x11, 0x90, 0x58, 0x94, 0x98, 0x5b, 0x1c, 0x94, 0x5a, 0x58, 0x9a, 0x5a, 0x5c, 0xa2, + 0x14, 0xc5, 0x25, 0x8c, 0x22, 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x2a, 0xe4, 0xcc, 0xc5, 0x56, + 0x00, 0x16, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0xd2, 0xd6, 0x23, 0xc2, 0xd5, 0x7a, 0x50, + 0x43, 0xa0, 0x5a, 0x8d, 0xd6, 0x30, 0x72, 0xb1, 0x82, 0x0d, 0x17, 0x5a, 0xc4, 0xc8, 0xc5, 0x06, + 0x91, 0x14, 0x32, 0x27, 0xca, 0x24, 0x4c, 0x97, 0x4a, 0x59, 0x90, 0xae, 0x11, 0xe2, 0x19, 0x25, + 0xd5, 0xa6, 0xcb, 0x4f, 0x26, 0x33, 0xc9, 0x0b, 0xc9, 0xe2, 0x08, 0x29, 0x88, 0x73, 0x9d, 0x82, + 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, + 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0xca, 0x22, 0x3d, 0xb3, 0x24, 0xa3, + 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x17, 0x1a, 0xdd, 0xba, 0x18, 0x61, 0x5f, 0x66, 0x68, 0xac, 0x5f, + 0x81, 0x64, 0x6e, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0xec, 0x8d, 0x01, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x59, 0xf5, 0xcf, 0xa5, 0x26, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/publicawesome.stargaze.authority.v1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/publicawesome.stargaze.authority.v1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "publicawesome.stargaze.authority.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "publicawesome/stargaze/authority/v1/query.proto", +} + +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Params != nil { + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Params == nil { + m.Params = &Params{} + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/authority/types/query.pb.gw.go b/x/authority/types/query.pb.gw.go new file mode 100644 index 000000000..49c32c073 --- /dev/null +++ b/x/authority/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: publicawesome/stargaze/authority/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"stargaze", "authority", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +) From c6d85185d24a614d328b951226e45e0fcca80353 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:19:40 +0000 Subject: [PATCH 06/20] adding genesis --- docs/proto/proto-docs.md | 157 ++++++------------ .../stargaze/authority/v1/genesis.proto | 8 +- x/authority/client/cli/query.go | 1 - x/authority/types/genesis.pb.go | 72 +++++++- 4 files changed, 121 insertions(+), 117 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index f0e20217d..89de7a7b2 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,84 +4,61 @@ ## Table of Contents -- [publicawesome/stargaze/alloc/v1beta1/params.proto](#publicawesome/stargaze/alloc/v1beta1/params.proto) - - [DistributionProportions](#publicawesome.stargaze.alloc.v1beta1.DistributionProportions) - - [Params](#publicawesome.stargaze.alloc.v1beta1.Params) - - [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) +- [publicawesome/stargaze/authority/v1/authority.proto](#publicawesome/stargaze/authority/v1/authority.proto) + - [Authorization](#publicawesome.stargaze.authority.v1.Authorization) + - [Params](#publicawesome.stargaze.authority.v1.Params) -- [publicawesome/stargaze/alloc/v1beta1/genesis.proto](#publicawesome/stargaze/alloc/v1beta1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.alloc.v1beta1.GenesisState) +- [publicawesome/stargaze/authority/v1/genesis.proto](#publicawesome/stargaze/authority/v1/genesis.proto) + - [GenesisState](#publicawesome.stargaze.authority.v1.GenesisState) -- [publicawesome/stargaze/alloc/v1beta1/query.proto](#publicawesome/stargaze/alloc/v1beta1/query.proto) - - [QueryParamsRequest](#publicawesome.stargaze.alloc.v1beta1.QueryParamsRequest) - - [QueryParamsResponse](#publicawesome.stargaze.alloc.v1beta1.QueryParamsResponse) +- [publicawesome/stargaze/authority/v1/query.proto](#publicawesome/stargaze/authority/v1/query.proto) + - [QueryParamsRequest](#publicawesome.stargaze.authority.v1.QueryParamsRequest) + - [QueryParamsResponse](#publicawesome.stargaze.authority.v1.QueryParamsResponse) - - [Query](#publicawesome.stargaze.alloc.v1beta1.Query) + - [Query](#publicawesome.stargaze.authority.v1.Query) -- [publicawesome/stargaze/alloc/v1beta1/tx.proto](#publicawesome/stargaze/alloc/v1beta1/tx.proto) - - [MsgCreateVestingAccount](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccount) - - [MsgCreateVestingAccountResponse](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccountResponse) - - [MsgFundFairburnPool](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPool) - - [MsgFundFairburnPoolResponse](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPoolResponse) +- [publicawesome/stargaze/authority/v1/tx.proto](#publicawesome/stargaze/authority/v1/tx.proto) + - [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) + - [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) - - [Msg](#publicawesome.stargaze.alloc.v1beta1.Msg) + - [Msg](#publicawesome.stargaze.authority.v1.Msg) - [Scalar Value Types](#scalar-value-types) - + -## publicawesome/stargaze/alloc/v1beta1/params.proto +## publicawesome/stargaze/authority/v1/authority.proto - + -### DistributionProportions +### Authorization | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `nft_incentives` | [string](#string) | | | -| `developer_rewards` | [string](#string) | | | -| `community_pool` | [string](#string) | | | +| `msgTypeUrl` | [string](#string) | | The type url of a proposal sdk.Msg | +| `addresses` | [string](#string) | repeated | The addresses who are allowed to execute that proposal | - + ### Params - +Params holds parameters for the authority module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `distribution_proportions` | [DistributionProportions](#publicawesome.stargaze.alloc.v1beta1.DistributionProportions) | | distribution_proportions defines the proportion of the minted denom | -| `weighted_developer_rewards_receivers` | [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) | repeated | addresses to receive developer rewards | -| `weighted_incentives_rewards_receivers` | [WeightedAddress](#publicawesome.stargaze.alloc.v1beta1.WeightedAddress) | repeated | addresses to receive incentive rewards | -| `supplement_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | SupplementAmount is the amount to be supplemented from the pool on top of newly minted coins. | - - - - - - - - -### WeightedAddress - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `address` | [string](#string) | | | -| `weight` | [string](#string) | | | +| `authorizations` | [Authorization](#publicawesome.stargaze.authority.v1.Authorization) | repeated | | @@ -97,22 +74,22 @@ - + -## publicawesome/stargaze/alloc/v1beta1/genesis.proto +## publicawesome/stargaze/authority/v1/genesis.proto - + ### GenesisState -GenesisState defines the alloc module's genesis state. + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.alloc.v1beta1.Params) | | this line is used by starport scaffolding # genesis/proto/state | +| `params` | [Params](#publicawesome.stargaze.authority.v1.Params) | | | @@ -128,32 +105,32 @@ GenesisState defines the alloc module's genesis state. - + -## publicawesome/stargaze/alloc/v1beta1/query.proto +## publicawesome/stargaze/authority/v1/query.proto - + ### QueryParamsRequest -QueryParamsRequest is the request type for the Query/Params RPC method. - + + ### QueryParamsResponse -QueryParamsResponse is the response type for the Query/Params RPC method. + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.alloc.v1beta1.Params) | | params defines the parameters of the module. | +| `params` | [Params](#publicawesome.stargaze.authority.v1.Params) | | | @@ -166,80 +143,47 @@ QueryParamsResponse is the response type for the Query/Params RPC method. - + ### Query Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Params` | [QueryParamsRequest](#publicawesome.stargaze.alloc.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.alloc.v1beta1.QueryParamsResponse) | this line is used by starport scaffolding # 2 | GET|/stargaze/alloc/v1beta1/params| +| `Params` | [QueryParamsRequest](#publicawesome.stargaze.authority.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.authority.v1.QueryParamsResponse) | | GET|/stargaze/authority/v1/params| - + -## publicawesome/stargaze/alloc/v1beta1/tx.proto - - - - - -### MsgCreateVestingAccount -MsgCreateVestingAccount defines a message that enables creating a vesting -account. - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| `from_address` | [string](#string) | | | -| `to_address` | [string](#string) | | | -| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | -| `start_time` | [int64](#int64) | | | -| `end_time` | [int64](#int64) | | | -| `delayed` | [bool](#bool) | | | - - - - - - - - -### MsgCreateVestingAccountResponse -MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response -type. - - - +## publicawesome/stargaze/authority/v1/tx.proto - + -### MsgFundFairburnPool -MsgFundFairburnPool allows an account to directly -fund the fee collector pool. +### MsgExecuteProposal +MsgExecuteProposal defines an sdk.Msg type that supports submitting arbitrary +proposal Content. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `sender` | [string](#string) | | | -| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | | +| `authority` | [string](#string) | | | +| `messages` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | - + -### MsgFundFairburnPoolResponse -MsgFundFairburnPoolResponse defines the Msg/MsgFundFairburnPool response -type. +### MsgExecuteProposalResponse +MsgExecuteProposalResponse defines the Msg/ExecuteProposal response type. @@ -252,15 +196,14 @@ type. - + ### Msg -Msg defines the alloc Msg service. +Msg defines the authority Msg service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `CreateVestingAccount` | [MsgCreateVestingAccount](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#publicawesome.stargaze.alloc.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | | -| `FundFairburnPool` | [MsgFundFairburnPool](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPool) | [MsgFundFairburnPoolResponse](#publicawesome.stargaze.alloc.v1beta1.MsgFundFairburnPoolResponse) | FundFairburnPool defines a method to allow an account to directly fund the fee collector module account. | | +| `ExecuteProposal` | [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) | [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) | | | diff --git a/proto/publicawesome/stargaze/authority/v1/genesis.proto b/proto/publicawesome/stargaze/authority/v1/genesis.proto index 336d3dcfb..57674db2c 100644 --- a/proto/publicawesome/stargaze/authority/v1/genesis.proto +++ b/proto/publicawesome/stargaze/authority/v1/genesis.proto @@ -2,7 +2,13 @@ syntax = "proto3"; package publicawesome.stargaze.authority.v1; import "gogoproto/gogo.proto"; +import "publicawesome/stargaze/authority/v1/authority.proto"; option go_package = "github.com/public-awesome/stargaze/v13/x/authority/types"; -message GenesisState {} \ No newline at end of file +message GenesisState { + Params params = 1 [ + (gogoproto.jsontag) = "params,omitempty", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/x/authority/client/cli/query.go b/x/authority/client/cli/query.go index 21c7eab77..e1e802ba4 100644 --- a/x/authority/client/cli/query.go +++ b/x/authority/client/cli/query.go @@ -23,7 +23,6 @@ func GetQueryCmd(_ string) *cobra.Command { } cmd.AddCommand(GetCmdParams()) - // this line is used by starport scaffolding # 1 return cmd } diff --git a/x/authority/types/genesis.pb.go b/x/authority/types/genesis.pb.go index 023a19892..53f979f30 100644 --- a/x/authority/types/genesis.pb.go +++ b/x/authority/types/genesis.pb.go @@ -24,6 +24,7 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -59,6 +60,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func init() { proto.RegisterType((*GenesisState)(nil), "publicawesome.stargaze.authority.v1.GenesisState") } @@ -68,19 +76,22 @@ func init() { } var fileDescriptor_f6ae0642d48c5a1e = []byte{ - // 177 bytes of a gzipped FileDescriptorProto + // 237 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x2c, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0x4e, 0x2c, 0x4f, 0x2d, 0xce, 0xcf, 0x4d, 0xd5, 0x2f, 0x2e, 0x49, 0x2c, 0x4a, 0x4f, 0xac, 0x4a, 0xd5, 0x4f, 0x2c, 0x2d, 0xc9, 0xc8, 0x2f, 0xca, 0x2c, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x46, 0xd1, 0xa2, 0x07, 0xd3, 0xa2, 0x07, 0xd7, 0xa2, 0x57, 0x66, 0x28, 0x25, 0x92, 0x9e, 0x9f, 0x9e, - 0x0f, 0x56, 0xaf, 0x0f, 0x62, 0x41, 0xb4, 0x2a, 0xf1, 0x71, 0xf1, 0xb8, 0x43, 0xcc, 0x0a, 0x2e, - 0x49, 0x2c, 0x49, 0x75, 0x0a, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, - 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, - 0x8b, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0x88, 0x7d, 0xba, 0x18, - 0x6e, 0x2c, 0x33, 0x34, 0xd6, 0xaf, 0x40, 0x72, 0x69, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, - 0xd8, 0x2a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x33, 0x62, 0xe5, 0xae, 0xda, 0x00, 0x00, - 0x00, + 0x0f, 0x56, 0xaf, 0x0f, 0x62, 0x41, 0xb4, 0x4a, 0x19, 0x13, 0x63, 0x1b, 0xc2, 0x1c, 0xb0, 0x26, + 0xa5, 0x5c, 0x2e, 0x1e, 0x77, 0x88, 0x03, 0x82, 0x4b, 0x12, 0x4b, 0x52, 0x85, 0x62, 0xb9, 0xd8, + 0x0a, 0x12, 0x8b, 0x12, 0x73, 0x8b, 0x25, 0x18, 0x15, 0x18, 0x35, 0xb8, 0x8d, 0xb4, 0xf5, 0x88, + 0x70, 0x90, 0x5e, 0x00, 0x58, 0x8b, 0x93, 0xc4, 0x89, 0x7b, 0xf2, 0x0c, 0xaf, 0xee, 0xc9, 0x0b, + 0x40, 0x8c, 0xd0, 0xc9, 0xcf, 0xcd, 0x2c, 0x49, 0xcd, 0x2d, 0x28, 0xa9, 0x0c, 0x82, 0x1a, 0xea, + 0x14, 0x74, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, + 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x16, 0xe9, 0x99, 0x25, + 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x10, 0x2b, 0x75, 0x31, 0x7c, 0x52, 0x66, 0x68, + 0xac, 0x5f, 0x81, 0xe4, 0x9f, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x4f, 0x8c, 0x01, + 0x01, 0x00, 0x00, 0xff, 0xff, 0x0e, 0xa5, 0xee, 0xe8, 0x6e, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -103,6 +114,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -123,6 +144,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -161,6 +184,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) From 753446d703c7f09e39259404a2b42b9916671475 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:23:23 +0000 Subject: [PATCH 07/20] implement init/export genesis --- x/authority/genesis.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/x/authority/genesis.go b/x/authority/genesis.go index 4e4030112..50b5d9ce7 100644 --- a/x/authority/genesis.go +++ b/x/authority/genesis.go @@ -6,12 +6,20 @@ import ( "github.com/public-awesome/stargaze/v13/x/authority/types" ) -// InitGenesis initializes the capability module's state from a provided genesis +// InitGenesis initializes the authority module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + params := genState.Params + err := k.SetParams(ctx, params) + if err != nil { + panic(err) + } } -// ExportGenesis returns the capability module's exported genesis. +// ExportGenesis returns the authority module's exported genesis. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { - return &types.GenesisState{} + params := k.GetParams(ctx) + return &types.GenesisState{ + Params: params, + } } From 4eba7016102eb5acc03ad8835a45e9e7fa30ae2b Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Thu, 2 Nov 2023 21:03:48 +0000 Subject: [PATCH 08/20] cleaning up unused code --- x/authority/abci.go | 78 --------------------- x/authority/keeper/msg_server.go | 2 +- x/authority/keeper/proposal.go | 117 ++----------------------------- x/authority/module.go | 1 - 4 files changed, 7 insertions(+), 191 deletions(-) delete mode 100644 x/authority/abci.go diff --git a/x/authority/abci.go b/x/authority/abci.go deleted file mode 100644 index 2e9a87156..000000000 --- a/x/authority/abci.go +++ /dev/null @@ -1,78 +0,0 @@ -package authority - -import ( - "fmt" - "time" - - "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - "github.com/public-awesome/stargaze/v13/x/authority/keeper" - "github.com/public-awesome/stargaze/v13/x/authority/types" -) - -// EndBlocker called every block, process inflation, update validator set. -func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) - logger := keeper.Logger(ctx) - - keeper.IterateActiveProposalsQueue(ctx, func(proposal govV1.Proposal) bool { - var logMsg, tagValue string - - var ( - idx int - events sdk.Events - msg sdk.Msg - ) - - cacheCtx, writeCache := ctx.CacheContext() - messages, err := proposal.GetMsgs() - if err == nil { - for idx, msg = range messages { - handler := keeper.Router().Handler(msg) - - var res *sdk.Result - res, err = handler(cacheCtx, msg) - if err != nil { - break - } - - events = append(events, res.GetEvents()...) - } - } - - if err == nil { - proposal.Status = govV1.StatusPassed - tagValue = govtypes.AttributeValueProposalPassed - logMsg = "passed" - - // write state to the underlying multi-store - writeCache() - - // propagate the msg events to the current context - ctx.EventManager().EmitEvents(events) - } else { - proposal.Status = govV1.StatusFailed - tagValue = govtypes.AttributeValueProposalFailed - logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err) - } - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - govtypes.EventTypeActiveProposal, - sdk.NewAttribute(govtypes.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.Id)), - sdk.NewAttribute(govtypes.AttributeKeyProposalResult, tagValue), - ), - ) - - logger.Info( - "proposal tallied", - "proposal", proposal.Id, - "title", proposal.GetTitle(), - "result", logMsg, - ) - - return false - }) -} diff --git a/x/authority/keeper/msg_server.go b/x/authority/keeper/msg_server.go index f579edf4c..cbabcaa9f 100644 --- a/x/authority/keeper/msg_server.go +++ b/x/authority/keeper/msg_server.go @@ -33,7 +33,7 @@ func (m msgServer) ExecuteProposal(goCtx context.Context, msg *types.MsgExecuteP return nil, err } - _, err = m.Keeper.SubmitProposal(ctx, proposalMsgs, proposer) + _, err = m.Keeper.ExecuteProposalMessages(ctx, proposalMsgs, proposer) if err != nil { return nil, err } diff --git a/x/authority/keeper/proposal.go b/x/authority/keeper/proposal.go index 8ce60167d..7a41f13a7 100644 --- a/x/authority/keeper/proposal.go +++ b/x/authority/keeper/proposal.go @@ -1,85 +1,18 @@ package keeper import ( - "fmt" - errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/public-awesome/stargaze/v13/x/authority/types" ) -// IterateActiveProposalsQueue iterates over the proposals in the active proposal queue -// and performs a callback function -func (k Keeper) IterateActiveProposalsQueue(ctx sdk.Context, cb func(proposal govV1.Proposal) (stop bool)) { - iterator := k.ActiveProposalQueueIterator(ctx) - - defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { - proposalID := govtypes.GetProposalIDFromBytes(iterator.Value()) - proposal, found := k.GetProposal(ctx, proposalID) - if !found { - panic(fmt.Sprintf("proposal %d does not exist", proposalID)) - } - - if cb(proposal) { - break - } - } -} - -// ActiveProposalQueueIterator returns an sdk.Iterator for all the proposals in the Active Queue -func (k Keeper) ActiveProposalQueueIterator(ctx sdk.Context) sdk.Iterator { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), govtypes.ActiveProposalQueuePrefix) - return prefixStore.Iterator(nil, nil) -} +// ExecuteProposalMessages executes the array of messages in the proposal if their authorization matches +func (keeper Keeper) ExecuteProposalMessages(ctx sdk.Context, messages []sdk.Msg, proposer sdk.AccAddress) (uint64, error) { + var events sdk.Events -// GetProposal get proposal from store by ProposalID -func (k Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (govV1.Proposal, bool) { - store := ctx.KVStore(k.storeKey) - - bz := store.Get(govtypes.ProposalKey(proposalID)) - if bz == nil { - return govV1.Proposal{}, false - } - - var proposal govV1.Proposal - k.MustUnmarshalProposal(bz, &proposal) - - return proposal, true -} - -func (k Keeper) MustUnmarshalProposal(bz []byte, proposal *govV1.Proposal) { - err := k.UnmarshalProposal(bz, proposal) - if err != nil { - panic(err) - } -} - -func (k Keeper) UnmarshalProposal(bz []byte, proposal *govV1.Proposal) error { - err := k.cdc.Unmarshal(bz, proposal) - if err != nil { - return err - } - return nil -} - -// SubmitProposal creates a new proposal given an array of messages -func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, proposer sdk.AccAddress) (uint64, error) { - // Will hold a comma-separated string of all Msg type URLs. - msgsStr := "" - - var ( - events sdk.Events - ) - - // Loop through all messages and confirm that each has a handler and the gov module account - // as the only signer + // Loop through all messages and confirm that each has a handler and the authorizations for the msg are valid for _, msg := range messages { - msgsStr += fmt.Sprintf(",%s", sdk.MsgTypeURL(msg)) - // perform a basic validation of the message if err := msg.ValidateBasic(); err != nil { return 0, errorsmod.Wrap(govtypes.ErrInvalidProposalMsg, err.Error()) @@ -90,11 +23,6 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, propose return 0, govtypes.ErrInvalidSigner } - // // assert that the authority module account is the only signer of the messages - // if !signers[0].Equals(keeper.GetGovernanceAccount(ctx).GetAddress()) { - // return v1.Proposal{}, sdkerrors.Wrapf(types.ErrInvalidSigner, signers[0].String()) - // } - valid, err := keeper.IsAuthorized(ctx, msg, proposer.String()) if !valid { return 0, err @@ -113,9 +41,9 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, propose } events = append(events, res.GetEvents()...) - } + ctx.EventManager().EmitEvents(events) return 0, nil } @@ -128,40 +56,7 @@ func (keeper Keeper) IsAuthorized(ctx sdk.Context, msg sdk.Msg, proposer string) } if !auth.IsAuthorized(proposer) { - return false, errorsmod.Wrap(govtypes.ErrInvalidSigner, "sender address"+proposer+" is not authorized address to execute"+msgType) + return false, errorsmod.Wrap(govtypes.ErrInvalidSigner, "sender address "+proposer+" is not authorized to execute this proposal"+msgType) } return true, nil } - -// // SetProposal set a proposal to store -// func (k Keeper) SetProposal(ctx sdk.Context, proposal govV1.Proposal) { -// store := ctx.KVStore(k.storeKey) - -// bz := k.MustMarshalProposal(proposal) - -// store.Set(types.ProposalKey(proposal.Id), bz) -// } - -// // GetProposalID gets the highest proposal ID -// func (k Keeper) GetProposalID(ctx sdk.Context) (proposalID uint64, err error) { -// store := ctx.KVStore(k.storeKey) -// bz := store.Get(types.ProposalIDKey) -// if bz == nil { -// return 0, errorsmod.Wrap(types.ErrInvalidGenesis, "initial proposal ID hasn't been set") -// } - -// proposalID = types.GetProposalIDFromBytes(bz) -// return proposalID, nil -// } - -// // SetProposalID sets the new proposal ID to the store -// func (k Keeper) SetProposalID(ctx sdk.Context, proposalID uint64) { -// store := ctx.KVStore(k.storeKey) -// store.Set(types.ProposalIDKey, types.GetProposalIDBytes(proposalID)) -// } - -// // InsertActiveProposalQueue inserts a ProposalID into the active proposal queue -// func (k Keeper) InsertActiveProposalQueue(ctx sdk.Context, proposalID uint64) { -// store := ctx.KVStore(k.storeKey) -// store.Set(types.ActiveProposalQueueKey(proposalID), types.GetProposalIDBytes(proposalID)) -// } diff --git a/x/authority/module.go b/x/authority/module.go index 27f4a376e..837e9a4b6 100644 --- a/x/authority/module.go +++ b/x/authority/module.go @@ -144,6 +144,5 @@ func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {} // EndBlock contains the logic that is automatically triggered at the end of each block func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - EndBlocker(ctx, am.keeper) return []abci.ValidatorUpdate{} } From 09af932032d5dad72e98a120c909295b5adc6212 Mon Sep 17 00:00:00 2001 From: Spoorthi Satheesha <9302666+spoo-bar@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:43:59 +0000 Subject: [PATCH 09/20] adding MsgUpdateParams --- docs/proto/proto-docs.md | 334 +++++++++++--- .../stargaze/authority/v1/tx.proto | 20 +- x/authority/keeper/msg_server.go | 29 ++ x/authority/keeper/params.go | 19 +- x/authority/module.go | 2 - x/authority/types/errors.go | 2 +- x/authority/types/msgs.go | 40 ++ x/authority/types/tx.pb.go | 430 +++++++++++++++++- 8 files changed, 787 insertions(+), 89 deletions(-) diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 89de7a7b2..24f67b25c 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -4,61 +4,78 @@ ## Table of Contents -- [publicawesome/stargaze/authority/v1/authority.proto](#publicawesome/stargaze/authority/v1/authority.proto) - - [Authorization](#publicawesome.stargaze.authority.v1.Authorization) - - [Params](#publicawesome.stargaze.authority.v1.Params) +- [osmosis/tokenfactory/v1beta1/tokenfactory.proto](#osmosis/tokenfactory/v1beta1/tokenfactory.proto) + - [DenomAuthorityMetadata](#osmosis.tokenfactory.v1beta1.DenomAuthorityMetadata) + - [Params](#osmosis.tokenfactory.v1beta1.Params) -- [publicawesome/stargaze/authority/v1/genesis.proto](#publicawesome/stargaze/authority/v1/genesis.proto) - - [GenesisState](#publicawesome.stargaze.authority.v1.GenesisState) +- [osmosis/tokenfactory/v1beta1/genesis.proto](#osmosis/tokenfactory/v1beta1/genesis.proto) + - [GenesisDenom](#osmosis.tokenfactory.v1beta1.GenesisDenom) + - [GenesisState](#osmosis.tokenfactory.v1beta1.GenesisState) -- [publicawesome/stargaze/authority/v1/query.proto](#publicawesome/stargaze/authority/v1/query.proto) - - [QueryParamsRequest](#publicawesome.stargaze.authority.v1.QueryParamsRequest) - - [QueryParamsResponse](#publicawesome.stargaze.authority.v1.QueryParamsResponse) +- [osmosis/tokenfactory/v1beta1/query.proto](#osmosis/tokenfactory/v1beta1/query.proto) + - [QueryDenomAuthorityMetadataRequest](#osmosis.tokenfactory.v1beta1.QueryDenomAuthorityMetadataRequest) + - [QueryDenomAuthorityMetadataResponse](#osmosis.tokenfactory.v1beta1.QueryDenomAuthorityMetadataResponse) + - [QueryDenomsFromCreatorRequest](#osmosis.tokenfactory.v1beta1.QueryDenomsFromCreatorRequest) + - [QueryDenomsFromCreatorResponse](#osmosis.tokenfactory.v1beta1.QueryDenomsFromCreatorResponse) + - [QueryParamsRequest](#osmosis.tokenfactory.v1beta1.QueryParamsRequest) + - [QueryParamsResponse](#osmosis.tokenfactory.v1beta1.QueryParamsResponse) - - [Query](#publicawesome.stargaze.authority.v1.Query) + - [Query](#osmosis.tokenfactory.v1beta1.Query) -- [publicawesome/stargaze/authority/v1/tx.proto](#publicawesome/stargaze/authority/v1/tx.proto) - - [MsgExecuteProposal](#publicawesome.stargaze.authority.v1.MsgExecuteProposal) - - [MsgExecuteProposalResponse](#publicawesome.stargaze.authority.v1.MsgExecuteProposalResponse) +- [osmosis/tokenfactory/v1beta1/tx.proto](#osmosis/tokenfactory/v1beta1/tx.proto) + - [MsgBurn](#osmosis.tokenfactory.v1beta1.MsgBurn) + - [MsgBurnResponse](#osmosis.tokenfactory.v1beta1.MsgBurnResponse) + - [MsgChangeAdmin](#osmosis.tokenfactory.v1beta1.MsgChangeAdmin) + - [MsgChangeAdminResponse](#osmosis.tokenfactory.v1beta1.MsgChangeAdminResponse) + - [MsgCreateDenom](#osmosis.tokenfactory.v1beta1.MsgCreateDenom) + - [MsgCreateDenomResponse](#osmosis.tokenfactory.v1beta1.MsgCreateDenomResponse) + - [MsgMint](#osmosis.tokenfactory.v1beta1.MsgMint) + - [MsgMintResponse](#osmosis.tokenfactory.v1beta1.MsgMintResponse) + - [MsgSetDenomMetadata](#osmosis.tokenfactory.v1beta1.MsgSetDenomMetadata) + - [MsgSetDenomMetadataResponse](#osmosis.tokenfactory.v1beta1.MsgSetDenomMetadataResponse) - - [Msg](#publicawesome.stargaze.authority.v1.Msg) + - [Msg](#osmosis.tokenfactory.v1beta1.Msg) - [Scalar Value Types](#scalar-value-types) - + -## publicawesome/stargaze/authority/v1/authority.proto +## osmosis/tokenfactory/v1beta1/tokenfactory.proto - - -### Authorization + +### DenomAuthorityMetadata +DenomAuthorityMetadata specifies metadata for addresses that have specific +capabilities over a token factory denom. Right now there is only one Admin +permission, but is planned to be extended to the future. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `msgTypeUrl` | [string](#string) | | The type url of a proposal sdk.Msg | -| `addresses` | [string](#string) | repeated | The addresses who are allowed to execute that proposal | +| `admin` | [string](#string) | | Can be empty for no admin, or a valid stargaze address | - + ### Params -Params holds parameters for the authority module. +Params defines the parameters for the tokenfactory module. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `authorizations` | [Authorization](#publicawesome.stargaze.authority.v1.Authorization) | repeated | | +| `denom_creation_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | DenomCreationFee defines the fee to be charged on the creation of a new denom. The fee is drawn from the MsgCreateDenom's sender account, and transferred to the community pool. | +| `denom_creation_gas_consume` | [uint64](#uint64) | | DenomCreationGasConsume defines the gas cost for creating a new denom. This is intended as a spam deterrence mechanism. + +See: https://github.com/CosmWasm/token-factory/issues/11 | @@ -74,22 +91,41 @@ Params holds parameters for the authority module. - + -## publicawesome/stargaze/authority/v1/genesis.proto +## osmosis/tokenfactory/v1beta1/genesis.proto - + + +### GenesisDenom +GenesisDenom defines a tokenfactory denom that is defined within genesis +state. The structure contains DenomAuthorityMetadata which defines the +denom's admin. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | | +| `authority_metadata` | [DenomAuthorityMetadata](#osmosis.tokenfactory.v1beta1.DenomAuthorityMetadata) | | | + -### GenesisState + + + +### GenesisState +GenesisState defines the tokenfactory module's genesis state. + + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.authority.v1.Params) | | | +| `params` | [Params](#osmosis.tokenfactory.v1beta1.Params) | | params defines the paramaters of the module. | +| `factory_denoms` | [GenesisDenom](#osmosis.tokenfactory.v1beta1.GenesisDenom) | repeated | | @@ -105,32 +141,96 @@ Params holds parameters for the authority module. - + -## publicawesome/stargaze/authority/v1/query.proto +## osmosis/tokenfactory/v1beta1/query.proto - + -### QueryParamsRequest +### QueryDenomAuthorityMetadataRequest +QueryDenomAuthorityMetadataRequest defines the request structure for the +DenomAuthorityMetadata gRPC query. +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `denom` | [string](#string) | | | - -### QueryParamsResponse + + +### QueryDenomAuthorityMetadataResponse +QueryDenomAuthorityMetadataResponse defines the response structure for the +DenomAuthorityMetadata gRPC query. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `authority_metadata` | [DenomAuthorityMetadata](#osmosis.tokenfactory.v1beta1.DenomAuthorityMetadata) | | | + + + + + + + + +### QueryDenomsFromCreatorRequest +QueryDenomsFromCreatorRequest defines the request structure for the +DenomsFromCreator gRPC query. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `creator` | [string](#string) | | | + + + + + +### QueryDenomsFromCreatorResponse +QueryDenomsFromCreatorRequest defines the response structure for the +DenomsFromCreator gRPC query. + + | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| `params` | [Params](#publicawesome.stargaze.authority.v1.Params) | | | +| `denoms` | [string](#string) | repeated | | + + + + + + + + +### QueryParamsRequest +QueryParamsRequest is the request type for the Query/Params RPC method. + + + + + + + + +### QueryParamsResponse +QueryParamsResponse is the response type for the Query/Params RPC method. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `params` | [Params](#osmosis.tokenfactory.v1beta1.Params) | | params defines the parameters of the module. | @@ -143,47 +243,175 @@ Params holds parameters for the authority module. - + ### Query Query defines the gRPC querier service. | Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | | ----------- | ------------ | ------------- | ------------| ------- | -------- | -| `Params` | [QueryParamsRequest](#publicawesome.stargaze.authority.v1.QueryParamsRequest) | [QueryParamsResponse](#publicawesome.stargaze.authority.v1.QueryParamsResponse) | | GET|/stargaze/authority/v1/params| +| `Params` | [QueryParamsRequest](#osmosis.tokenfactory.v1beta1.QueryParamsRequest) | [QueryParamsResponse](#osmosis.tokenfactory.v1beta1.QueryParamsResponse) | Params defines a gRPC query method that returns the tokenfactory module's parameters. | GET|/stargaze/tokenfactory/v1/params| +| `DenomAuthorityMetadata` | [QueryDenomAuthorityMetadataRequest](#osmosis.tokenfactory.v1beta1.QueryDenomAuthorityMetadataRequest) | [QueryDenomAuthorityMetadataResponse](#osmosis.tokenfactory.v1beta1.QueryDenomAuthorityMetadataResponse) | DenomAuthorityMetadata defines a gRPC query method for fetching DenomAuthorityMetadata for a particular denom. | GET|/stargaze/tokenfactory/v1/denoms/{denom}/authority_metadata| +| `DenomsFromCreator` | [QueryDenomsFromCreatorRequest](#osmosis.tokenfactory.v1beta1.QueryDenomsFromCreatorRequest) | [QueryDenomsFromCreatorResponse](#osmosis.tokenfactory.v1beta1.QueryDenomsFromCreatorResponse) | DenomsFromCreator defines a gRPC query method for fetching all denominations created by a specific admin/creator. | GET|/stargaze/tokenfactory/v1/denoms_from_creator/{creator}| - + -## publicawesome/stargaze/authority/v1/tx.proto +## osmosis/tokenfactory/v1beta1/tx.proto + + + + + +### MsgBurn +MsgBurn is the sdk.Msg type for allowing an admin account to burn +a token. For now, we only support burning from the sender account. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | | +| `burnFromAddress` | [string](#string) | | | + + + + + + + + +### MsgBurnResponse + + + + + + + + + +### MsgChangeAdmin +MsgChangeAdmin is the sdk.Msg type for allowing an admin account to reassign +adminship of a denom to a new account + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [string](#string) | | | +| `denom` | [string](#string) | | | +| `new_admin` | [string](#string) | | | + + + + + + + + +### MsgChangeAdminResponse +MsgChangeAdminResponse defines the response structure for an executed +MsgChangeAdmin message. + + + + + + + + +### MsgCreateDenom +MsgCreateDenom defines the message structure for the CreateDenom gRPC service +method. It allows an account to create a new denom. It requires a sender +address and a sub denomination. The (sender_address, sub_denomination) tuple +must be unique and cannot be re-used. + +The resulting denom created is defined as +