diff --git a/proto/dymensionxyz/dymension/rollapp/metadata.proto b/proto/dymensionxyz/dymension/rollapp/metadata.proto index 728a5d9db..1ee66c95e 100644 --- a/proto/dymensionxyz/dymension/rollapp/metadata.proto +++ b/proto/dymensionxyz/dymension/rollapp/metadata.proto @@ -24,6 +24,8 @@ message RollappMetadata { string explorer_url = 9; // fee_denom is the base denom for fees DenomMetadata fee_denom = 10; + // Tags is a list of tags that can be used to filter rollapps. + repeated string tags = 11; } message DenomMetadata { diff --git a/x/rollapp/keeper/msg_server_create_rollapp_test.go b/x/rollapp/keeper/msg_server_create_rollapp_test.go index 3012b8706..86a3b2b66 100644 --- a/x/rollapp/keeper/msg_server_create_rollapp_test.go +++ b/x/rollapp/keeper/msg_server_create_rollapp_test.go @@ -236,6 +236,7 @@ var mockRollappMetadata = types.RollappMetadata{ LogoUrl: "https://dymension.xyz/logo.png", Telegram: "https://t.me/rolly", X: "https://x.dymension.xyz", + Tags: []string{"AI", "DeFI", "NFT"}, } var mockGenesisInfo = &types.GenesisInfo{ diff --git a/x/rollapp/types/errors.go b/x/rollapp/types/errors.go index df24a33f5..5e898d233 100644 --- a/x/rollapp/types/errors.go +++ b/x/rollapp/types/errors.go @@ -46,6 +46,9 @@ var ( ErrInvalidBlockDescriptorTimestamp = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid block descriptor timestamp") ErrInvalidNativeDenom = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid native denom") ErrInvalidFeeDenom = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid fee denom") + ErrInvalidTag = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid tag") + ErrTooManyTags = errorsmod.Wrap(gerrc.ErrInvalidArgument, "too many tags") + ErrDuplicateTag = errorsmod.Wrap(gerrc.ErrInvalidArgument, "duplicate tag") ErrInvalidInitialSupply = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid initial supply") ErrInvalidBech32Prefix = errorsmod.Wrap(gerrc.ErrInvalidArgument, "invalid bech32 prefix") ErrRollappNotFound = errorsmod.Wrap(gerrc.ErrNotFound, "rollapp") diff --git a/x/rollapp/types/message_update_rollapp_test.go b/x/rollapp/types/message_update_rollapp_test.go index ffe1ba35e..5f6ecfda7 100644 --- a/x/rollapp/types/message_update_rollapp_test.go +++ b/x/rollapp/types/message_update_rollapp_test.go @@ -1,7 +1,7 @@ package types import ( - fmt "fmt" + "fmt" "strings" "testing" @@ -92,6 +92,66 @@ func TestMsgUpdateRollappInformation_ValidateBasic(t *testing.T) { }, err: ErrInvalidURL, }, + { + name: "invalid metadata: too many tags", + msg: MsgUpdateRollappInformation{ + Owner: sample.AccAddress(), + InitialSequencer: sample.AccAddress(), + RollappId: "dym_100-1", + GenesisInfo: &GenesisInfo{ + Bech32Prefix: bech32Prefix, + GenesisChecksum: "checksum", + NativeDenom: DenomMetadata{Display: "DEN", Base: "aden", Exponent: 18}, + InitialSupply: sdk.NewInt(1000), + }, + Metadata: &RollappMetadata{ + Website: "https://dymension.xyz", + Description: "Sample description", + Tags: []string{"tag1", "tag2", "tag3", "tag4"}, + }, + }, + err: ErrTooManyTags, + }, + { + name: "invalid metadata: invalid tag", + msg: MsgUpdateRollappInformation{ + Owner: sample.AccAddress(), + InitialSequencer: sample.AccAddress(), + RollappId: "dym_100-1", + GenesisInfo: &GenesisInfo{ + Bech32Prefix: bech32Prefix, + GenesisChecksum: "checksum", + NativeDenom: DenomMetadata{Display: "DEN", Base: "aden", Exponent: 18}, + InitialSupply: sdk.NewInt(1000), + }, + Metadata: &RollappMetadata{ + Website: "https://dymension.xyz", + Description: "Sample description", + Tags: []string{"invalid"}, + }, + }, + err: ErrInvalidTag, + }, + { + name: "invalid metadata: duplicate tag", + msg: MsgUpdateRollappInformation{ + Owner: sample.AccAddress(), + InitialSequencer: sample.AccAddress(), + RollappId: "dym_100-1", + GenesisInfo: &GenesisInfo{ + Bech32Prefix: bech32Prefix, + GenesisChecksum: "checksum", + NativeDenom: DenomMetadata{Display: "DEN", Base: "aden", Exponent: 18}, + InitialSupply: sdk.NewInt(1000), + }, + Metadata: &RollappMetadata{ + Website: "https://dymension.xyz", + Description: "Sample description", + Tags: []string{"AI", "DeFI", "AI"}, + }, + }, + err: ErrDuplicateTag, + }, { name: "invalid genesis checksum: too long", msg: MsgUpdateRollappInformation{ diff --git a/x/rollapp/types/metadata.pb.go b/x/rollapp/types/metadata.pb.go index 4dc9996bd..2857c5792 100644 --- a/x/rollapp/types/metadata.pb.go +++ b/x/rollapp/types/metadata.pb.go @@ -43,6 +43,8 @@ type RollappMetadata struct { ExplorerUrl string `protobuf:"bytes,9,opt,name=explorer_url,json=explorerUrl,proto3" json:"explorer_url,omitempty"` // fee_denom is the base denom for fees FeeDenom *DenomMetadata `protobuf:"bytes,10,opt,name=fee_denom,json=feeDenom,proto3" json:"fee_denom,omitempty"` + // Tags is a list of tags that can be used to filter rollapps. + Tags []string `protobuf:"bytes,11,rep,name=tags,proto3" json:"tags,omitempty"` } func (m *RollappMetadata) Reset() { *m = RollappMetadata{} } @@ -148,6 +150,13 @@ func (m *RollappMetadata) GetFeeDenom() *DenomMetadata { return nil } +func (m *RollappMetadata) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + type DenomMetadata struct { Display string `protobuf:"bytes,1,opt,name=display,proto3" json:"display,omitempty"` Base string `protobuf:"bytes,2,opt,name=base,proto3" json:"base,omitempty"` @@ -218,31 +227,31 @@ func init() { } var fileDescriptor_481e8ecd49e74695 = []byte{ - // 370 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xbf, 0xae, 0xd3, 0x30, - 0x14, 0xc6, 0xeb, 0xcb, 0xe5, 0xde, 0xd4, 0xbd, 0x15, 0x92, 0x27, 0xc3, 0x10, 0x4a, 0xa7, 0x2e, - 0x4d, 0x24, 0xca, 0x13, 0x20, 0x26, 0x24, 0x3a, 0x44, 0x62, 0x80, 0xa5, 0x72,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 0x02, 0x4d, 0x7a, 0x1f, 0x11, 0xfd, 0x30, 0xb4, 0x5a, 0x28, 0x03, 0x26, 0xac, 0x9f, - 0xf6, 0xc3, 0x83, 0xe6, 0xf7, 0xbf, 0xc7, 0xd3, 0x03, 0xc0, 0xae, 0x02, 0xa9, 0x1a, 0x8a, 0x17, - 0x68, 0x35, 0x7b, 0xbd, 0xce, 0x1e, 0x4f, 0x32, 0x7b, 0xe7, 0x9b, 0x87, 0x0c, 0x8b, 0xe4, 0x00, - 0x10, 0x94, 0xe5, 0x27, 0x3c, 0xff, 0xa7, 0xe4, 0x9d, 0x45, 0xa3, 0x43, 0xbc, 0x11, 0x09, 0xc1, - 0xb7, 0x25, 0xb3, 0x10, 0x73, 0x0d, 0x6f, 0x9f, 0x1a, 0xb4, 0x5a, 0x49, 0x90, 0x2e, 0x04, 0x3a, - 0x2f, 0x46, 0x7e, 0xbb, 0xfd, 0x79, 0x4e, 0xd1, 0xe9, 0x9c, 0xa2, 0x3f, 0xe7, 0x14, 0xfd, 0xb8, - 0xa4, 0x93, 0xd3, 0x25, 0x9d, 0xfc, 0xba, 0xa4, 0x93, 0xcf, 0x6f, 0x6a, 0xee, 0xbe, 0x1c, 0xcb, - 0x6c, 0xaf, 0x9a, 0xfc, 0x3f, 0x07, 0xf3, 0x75, 0x93, 0xb7, 0xe3, 0xd5, 0xb8, 0x4e, 0x83, 0x2d, - 0xef, 0xc2, 0xcd, 0x6c, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0xd4, 0xe3, 0x4d, 0x5f, 0x64, 0x02, - 0x00, 0x00, + // 384 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xb1, 0x8e, 0xd4, 0x30, + 0x10, 0x86, 0xd7, 0x77, 0xc7, 0x5d, 0xe2, 0xdc, 0x09, 0xc9, 0x95, 0xa1, 0x08, 0xe1, 0xaa, 0x6d, + 0x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bd, 0x8a, 0x8b, 0x4c, 0xda, 0x03, 0xeb, 0xc1, 0x7f, + 0xc2, 0xb1, 0x4e, 0x70, 0x09, 0x34, 0x99, 0xf6, 0x88, 0xe8, 0xcd, 0x30, 0x68, 0xa1, 0x0c, 0x98, + 0x30, 0x3e, 0x9d, 0xcc, 0xb3, 0xe6, 0xe7, 0xbf, 0xc3, 0xe9, 0x16, 0x60, 0xd3, 0x82, 0x54, 0x3d, + 0xc5, 0x05, 0x5a, 0x67, 0xaf, 0xee, 0xca, 0xff, 0x27, 0x59, 0xbe, 0xf5, 0xcd, 0x73, 0x86, 0x75, + 0xb2, 0x05, 0x08, 0x0a, 0x21, 0xf8, 0xc2, 0xb1, 0xce, 0xd2, 0xac, 0x38, 0x5f, 0xa7, 0x75, 0xa8, + 0x6f, 0x3f, 0xe2, 0x9b, 0xbf, 0xda, 0xfd, 0xb6, 0x71, 0xf9, 0x39, 0xf2, 0x88, 0xde, 0xde, 0x30, + 0x0b, 0x31, 0xeb, 0x50, 0xfb, 0x24, 0x61, 0xd0, 0x4a, 0x82, 0x74, 0x21, 0xe4, 0x9b, 0x7a, 0xe1, + 0x37, 0x0f, 0x3f, 0x0e, 0x39, 0xda, 0x1f, 0x72, 0xf4, 0xeb, 0x90, 0xa3, 0xef, 0xc7, 0x7c, 0xb5, + 0x3f, 0xe6, 0xab, 0x9f, 0xc7, 0x7c, 0xf5, 0xe9, 0x75, 0xc7, 0xdd, 0xe7, 0x5d, 0x53, 0x3e, 0xaa, + 0xbe, 0xfa, 0xc7, 0x11, 0x7d, 0xb9, 0xaf, 0x86, 0xe5, 0x92, 0xdc, 0xa8, 0xc1, 0x36, 0x97, 0xe1, + 0x8e, 0xee, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8d, 0x3a, 0xf5, 0xd3, 0x78, 0x02, 0x00, 0x00, } func (m *RollappMetadata) Marshal() (dAtA []byte, err error) { @@ -265,6 +274,15 @@ func (m *RollappMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Tags) > 0 { + for iNdEx := len(m.Tags) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Tags[iNdEx]) + copy(dAtA[i:], m.Tags[iNdEx]) + i = encodeVarintMetadata(dAtA, i, uint64(len(m.Tags[iNdEx]))) + i-- + dAtA[i] = 0x5a + } + } if m.FeeDenom != nil { { size, err := m.FeeDenom.MarshalToSizedBuffer(dAtA[:i]) @@ -442,6 +460,12 @@ func (m *RollappMetadata) Size() (n int) { l = m.FeeDenom.Size() n += 1 + l + sovMetadata(uint64(l)) } + if len(m.Tags) > 0 { + for _, s := range m.Tags { + l = len(s) + n += 1 + l + sovMetadata(uint64(l)) + } + } return n } @@ -824,6 +848,38 @@ func (m *RollappMetadata) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Tags", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowMetadata + } + 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 ErrInvalidLengthMetadata + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMetadata + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Tags = append(m.Tags, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipMetadata(dAtA[iNdEx:]) diff --git a/x/rollapp/types/rollapp.go b/x/rollapp/types/rollapp.go index bc863369a..0749e92a6 100644 --- a/x/rollapp/types/rollapp.go +++ b/x/rollapp/types/rollapp.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net/url" + "slices" "strings" errorsmod "cosmossdk.io/errors" @@ -19,8 +20,23 @@ const ( maxTaglineLength = 64 maxURLLength = 256 maxGenesisChecksumLength = 64 + maxTags = 3 ) +// RollappTags are hardcoded for now TODO: manage them through the store +var RollappTags = []string{ + "Meme", + "AI", + "DeFI", + "NFT", + "Gaming", + "Betting", + "Community", + "Social", + "DePIN", + "Launchpad", +} + type AllowedDecimals uint32 const ( @@ -231,6 +247,22 @@ func (md *RollappMetadata) Validate() error { } } + if len(md.Tags) > maxTags { + return ErrTooManyTags + } + + seen := make(map[string]struct{}) + + for _, tag := range md.Tags { + if !slices.Contains(RollappTags, tag) { + return ErrInvalidTag + } + if _, ok := seen[tag]; ok { + return ErrDuplicateTag + } + seen[tag] = struct{}{} + } + return nil }