Skip to content

Commit

Permalink
feat(rollapp): add tags to rollapp metadata (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Nov 28, 2024
1 parent 5e0a7c7 commit a7df970
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 26 deletions.
2 changes: 2 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions x/rollapp/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
62 changes: 61 additions & 1 deletion x/rollapp/types/message_update_rollapp_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
fmt "fmt"
"fmt"
"strings"
"testing"

Expand Down Expand Up @@ -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{
Expand Down
106 changes: 81 additions & 25 deletions x/rollapp/types/metadata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions x/rollapp/types/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/url"
"slices"
"strings"

errorsmod "cosmossdk.io/errors"
Expand All @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a7df970

Please sign in to comment.