From 5dba0e165027834011829ba482734703e130812b Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Thu, 7 Sep 2023 13:08:39 +0900 Subject: [PATCH 1/7] add TopLevelDomain types --- x/registry/types/top_level_domain.go | 1 + x/registry/types/top_level_domain_test.go | 51 +++++++++++++++++++ x/registry/types/valdiate_top_level_domain.go | 29 +++++++++++ 3 files changed, 81 insertions(+) create mode 100644 x/registry/types/top_level_domain.go create mode 100644 x/registry/types/top_level_domain_test.go create mode 100644 x/registry/types/valdiate_top_level_domain.go diff --git a/x/registry/types/top_level_domain.go b/x/registry/types/top_level_domain.go new file mode 100644 index 00000000..ab1254f4 --- /dev/null +++ b/x/registry/types/top_level_domain.go @@ -0,0 +1 @@ +package types diff --git a/x/registry/types/top_level_domain_test.go b/x/registry/types/top_level_domain_test.go new file mode 100644 index 00000000..21464b79 --- /dev/null +++ b/x/registry/types/top_level_domain_test.go @@ -0,0 +1,51 @@ +package types + +import ( + "fmt" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" +) + +type TopLevelDomainTest struct { + Domain TopLevelDomain + DomainPrice sdk.Coins +} + +func TestTopLevelDomainValidate(t *testing.T) { + testCases := []struct { + domain TopLevelDomain + expErr string + }{ + // Valid domains + { + domain: TopLevelDomain{Name: "myc"}, + }, + // Invalid name + {domain: TopLevelDomain{Name: ".foo"}, + expErr: fmt.Sprintf("invalid name: .foo"), + }, + {domain: TopLevelDomain{Name: ""}, + expErr: fmt.Sprintf("invalid name: "), + }, + {domain: TopLevelDomain{Name: "bar.foo"}, + expErr: fmt.Sprintf("invalid name: bar.foo"), + }, + {domain: TopLevelDomain{Name: "."}, + expErr: fmt.Sprintf("invalid name: ."), + }, + {domain: TopLevelDomain{Name: "##"}, + expErr: fmt.Sprintf("invalid name: ##"), + }, + } + + for _, tc := range testCases { + err := tc.domain.Validate() + if tc.expErr == "" { + require.Nil(t, err) + } else { + require.EqualError(t, err, tc.expErr) + } + } +} diff --git a/x/registry/types/valdiate_top_level_domain.go b/x/registry/types/valdiate_top_level_domain.go new file mode 100644 index 00000000..28380ff6 --- /dev/null +++ b/x/registry/types/valdiate_top_level_domain.go @@ -0,0 +1,29 @@ +package types + +import ( + "errors" + fmt "fmt" + "regexp" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + TLDNamePattern = `-a-z0-9\p{So}\p{Sk}` +) + +func (topLevelDomain TopLevelDomain) ValidateName() (err error) { + regex := regexp.MustCompile(fmt.Sprintf(`(^[%s]+$)`, TLDNamePattern)) + if !regex.MatchString(topLevelDomain.Name) { + err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", topLevelDomain.Name)), ErrInvalidDomainName.Error()) + } + return err +} + +func (topLevelDomain TopLevelDomain) Validate() (err error) { + err = topLevelDomain.ValidateName() + if err != nil { + return err + } + return err +} From 72d9e6c650744087ec9e5b262174a334804ad0d2 Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Thu, 7 Sep 2023 17:40:00 +0900 Subject: [PATCH 2/7] add TopLevelDomain message --- app/app.go | 8 +- app/params/config.go | 3 +- docs/static/openapi.yml | 2 + proto/mycel/registry/tx.proto | 26 +- x/registry/client/cli/tx.go | 1 + .../cli/tx_register_top_level_domain.go | 40 ++ ...erver_register_second_level_domain_test.go | 4 +- .../msg_server_register_top_level_domain.go | 17 + ...g_server_register_top_level_domain_test.go | 93 +++++ x/registry/module_simulation.go | 15 + .../simulation/register_top_level_domain.go | 29 ++ x/registry/types/codec.go | 4 + x/registry/types/events.go | 8 + x/registry/types/genesis.go | 2 +- .../message_register_top_level_domain.go | 45 +++ .../message_register_top_level_domain_test.go | 40 ++ x/registry/types/second_level_domain_test.go | 2 +- x/registry/types/tx.pb.go | 379 ++++++++++++++++-- 18 files changed, 674 insertions(+), 44 deletions(-) create mode 100644 x/registry/client/cli/tx_register_top_level_domain.go create mode 100644 x/registry/keeper/msg_server_register_top_level_domain.go create mode 100644 x/registry/keeper/msg_server_register_top_level_domain_test.go create mode 100644 x/registry/simulation/register_top_level_domain.go create mode 100644 x/registry/types/message_register_top_level_domain.go create mode 100644 x/registry/types/message_register_top_level_domain_test.go diff --git a/app/app.go b/app/app.go index a8dadcb2..22810763 100644 --- a/app/app.go +++ b/app/app.go @@ -135,9 +135,9 @@ import ( const ( AccountAddressPrefix = "mycel" Name = "mycel" - HumanCoinUnit = "mycel" - BaseCoinUnit = "umycel" - MycelExponent = 6 + HumanCoinUnit = "mycel" + BaseCoinUnit = "umycel" + MycelExponent = 6 DefaultBondDenom = BaseCoinUnit @@ -161,6 +161,7 @@ func RegisterDenoms() { panic(err) } } + // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals func getGovProposalHandlers() []govclient.ProposalHandler { @@ -179,7 +180,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler { return govProposalHandlers } - // produce a list of enabled proposals to pass into wasmd app. func GetEnabledProposals() []wasmtypes.ProposalType { if EnableSpecificProposals == "" { diff --git a/app/params/config.go b/app/params/config.go index b23c2495..01360643 100644 --- a/app/params/config.go +++ b/app/params/config.go @@ -2,8 +2,8 @@ package params import ( errorsmod "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/types/address" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -42,7 +42,6 @@ func RegisterDenoms() { } } - // SetAddressPrefixes builds the Config with Bech32 addressPrefix and publKeyPrefix for accounts, validators, and consensus nodes and verifies that addreeses have correct format. func SetAddressPrefixes() { config := sdk.GetConfig() diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index e70979f5..54dff9cd 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -80505,6 +80505,8 @@ definitions: signatures required by gogoproto. mycel.registry.MsgRegisterDomainResponse: type: object + mycel.registry.MsgRegisterTopLevelDomainResponse: + type: object mycel.registry.MsgUpdateDnsRecordResponse: type: object mycel.registry.MsgUpdateWalletRecordResponse: diff --git a/proto/mycel/registry/tx.proto b/proto/mycel/registry/tx.proto index bfb14039..20a42b81 100644 --- a/proto/mycel/registry/tx.proto +++ b/proto/mycel/registry/tx.proto @@ -1,13 +1,15 @@ syntax = "proto3"; + package mycel.registry; option go_package = "github.com/mycel-domain/mycel/x/registry/types"; // Msg defines the Msg service. service Msg { - rpc UpdateWalletRecord (MsgUpdateWalletRecord) returns (MsgUpdateWalletRecordResponse); - rpc UpdateDnsRecord (MsgUpdateDnsRecord ) returns (MsgUpdateDnsRecordResponse ); - rpc RegisterDomain (MsgRegisterDomain ) returns (MsgRegisterDomainResponse ); + rpc UpdateWalletRecord (MsgUpdateWalletRecord ) returns (MsgUpdateWalletRecordResponse ); + rpc UpdateDnsRecord (MsgUpdateDnsRecord ) returns (MsgUpdateDnsRecordResponse ); + rpc RegisterDomain (MsgRegisterDomain ) returns (MsgRegisterDomainResponse ); + rpc RegisterTopLevelDomain (MsgRegisterTopLevelDomain) returns (MsgRegisterTopLevelDomainResponse); } message MsgUpdateWalletRecord { string creator = 1; @@ -20,11 +22,11 @@ message MsgUpdateWalletRecord { message MsgUpdateWalletRecordResponse {} message MsgUpdateDnsRecord { - string creator = 1; - string name = 2; - string parent = 3; - string dnsRecordType = 4; - string value = 5; + string creator = 1; + string name = 2; + string parent = 3; + string dnsRecordType = 4; + string value = 5; } message MsgUpdateDnsRecordResponse {} @@ -38,3 +40,11 @@ message MsgRegisterDomain { message MsgRegisterDomainResponse {} +message MsgRegisterTopLevelDomain { + string creator = 1; + string name = 2; + uint64 registrationPeriodInYear = 3; +} + +message MsgRegisterTopLevelDomainResponse {} + diff --git a/x/registry/client/cli/tx.go b/x/registry/client/cli/tx.go index 2133c98b..450b27d3 100644 --- a/x/registry/client/cli/tx.go +++ b/x/registry/client/cli/tx.go @@ -33,6 +33,7 @@ func GetTxCmd() *cobra.Command { cmd.AddCommand(CmdUpdateWalletRecord()) cmd.AddCommand(CmdUpdateDnsRecord()) cmd.AddCommand(CmdRegisterDomain()) + cmd.AddCommand(CmdRegisterTopLevelDomain()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/registry/client/cli/tx_register_top_level_domain.go b/x/registry/client/cli/tx_register_top_level_domain.go new file mode 100644 index 00000000..a1efed7d --- /dev/null +++ b/x/registry/client/cli/tx_register_top_level_domain.go @@ -0,0 +1,40 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/mycel-domain/mycel/x/registry/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdRegisterTopLevelDomain() *cobra.Command { + cmd := &cobra.Command{ + Use: "register-top-level-domain", + Short: "Broadcast message registerTopLevelDomain", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) (err error) { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgRegisterTopLevelDomain( + clientCtx.GetFromAddress().String(), + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/registry/keeper/msg_server_register_second_level_domain_test.go b/x/registry/keeper/msg_server_register_second_level_domain_test.go index ed2e9f54..1dc8620e 100644 --- a/x/registry/keeper/msg_server_register_second_level_domain_test.go +++ b/x/registry/keeper/msg_server_register_second_level_domain_test.go @@ -99,7 +99,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() { // Register domain _, err := suite.msgServer.RegisterDomain(suite.ctx, registerMsg) - fmt.Println("----Case_", i , "---01", err) + fmt.Println("----Case_", i, "---01", err) if err == nil { // Evalute domain ownership @@ -108,7 +108,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() { suite.Require().Equal(tc.domainOwnership, domainOwnership) // Evalute if domain is registered - _, found = suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.parent) + _, found = suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.parent) suite.Require().True(found) // // Evalute if parent's subdomainCount is increased diff --git a/x/registry/keeper/msg_server_register_top_level_domain.go b/x/registry/keeper/msg_server_register_top_level_domain.go new file mode 100644 index 00000000..48187717 --- /dev/null +++ b/x/registry/keeper/msg_server_register_top_level_domain.go @@ -0,0 +1,17 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/mycel-domain/mycel/x/registry/types" +) + +func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgRegisterTopLevelDomain) (*types.MsgRegisterTopLevelDomainResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // TODO: Handling the message + _ = ctx + + return &types.MsgRegisterTopLevelDomainResponse{}, nil +} diff --git a/x/registry/keeper/msg_server_register_top_level_domain_test.go b/x/registry/keeper/msg_server_register_top_level_domain_test.go new file mode 100644 index 00000000..e1db88f7 --- /dev/null +++ b/x/registry/keeper/msg_server_register_top_level_domain_test.go @@ -0,0 +1,93 @@ +package keeper_test + +import ( + "errors" + "fmt" + + "github.com/mycel-domain/mycel/testutil" + "github.com/mycel-domain/mycel/x/registry/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() { + testCases := []struct { + creator string + name string + registrationPeriodInYear uint64 + domainOwnership types.DomainOwnership + expErr error + fn func() + }{ + { + creator: testutil.Alice, + name: "cel", + registrationPeriodInYear: 1, + expErr: nil, + fn: func() {}, + }, + { + creator: testutil.Alice, + name: "cel", + registrationPeriodInYear: 4, + expErr: nil, + fn: func() {}, + }, + { + creator: testutil.Alice, + name: "cel", + registrationPeriodInYear: 1, + expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("foo.cel")), types.ErrDomainIsAlreadyTaken.Error()), + fn: func() { + // Register domain once + domain := &types.MsgRegisterTopLevelDomain{ + Creator: testutil.Alice, + Name: "cel", + RegistrationPeriodInYear: 1, + } + _, err := suite.msgServer.RegisterTopLevelDomain(suite.ctx, domain) + suite.Require().Nil(err) + }, + }, + } + + for i, tc := range testCases { + suite.Run(fmt.Sprintf("Case %d", i), func() { + suite.SetupTest() + + registerMsg := &types.MsgRegisterTopLevelDomain{ + Creator: tc.creator, + Name: tc.name, + RegistrationPeriodInYear: tc.registrationPeriodInYear, + } + + // Run test case function + tc.fn() + + // Register domain + _, err := suite.msgServer.RegisterTopLevelDomain(suite.ctx, registerMsg) + fmt.Println("----Case_", i, "---01", err) + + if err == nil { + // Evalute if domain is registered + _, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.name) + suite.Require().True(found) + + // Evalute events + suite.Require().Nil(err) + events := sdk.StringifyEvents(suite.ctx.EventManager().ABCIEvents()) + eventIndex := len(events) - 1 + suite.Require().EqualValues(sdk.StringEvent{ + Type: types.EventTypeRegsterDomain, + Attributes: []sdk.Attribute{ + {Key: types.AttributeRegisterTopLevelDomainEventName, Value: tc.name}, + {Key: types.AttributeRegisterTopLevelDomainEventExpirationDate, Value: events[eventIndex].Attributes[2].Value}, + }, + }, events[eventIndex]) + } else { + suite.Require().EqualError(err, tc.expErr.Error()) + } + }) + } +} diff --git a/x/registry/module_simulation.go b/x/registry/module_simulation.go index aa2b8265..bc58b7d5 100644 --- a/x/registry/module_simulation.go +++ b/x/registry/module_simulation.go @@ -31,6 +31,10 @@ const ( // TODO: Determine the simulation weight value defaultWeightMsgRegisterDomain int = 100 + opWeightMsgRegisterTopLevelDomain = "op_weight_msg_register_top_level_domain" + // TODO: Determine the simulation weight value + defaultWeightMsgRegisterTopLevelDomain int = 100 + // this line is used by starport scaffolding # simapp/module/const ) @@ -81,6 +85,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp registrysimulation.SimulateMsgRegisterDomain(am.accountKeeper, am.bankKeeper, am.keeper), )) + var weightMsgRegisterTopLevelDomain int + simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegisterTopLevelDomain, &weightMsgRegisterTopLevelDomain, nil, + func(_ *rand.Rand) { + weightMsgRegisterTopLevelDomain = defaultWeightMsgRegisterTopLevelDomain + }, + ) + operations = append(operations, simulation.NewWeightedOperation( + weightMsgRegisterTopLevelDomain, + registrysimulation.SimulateMsgRegisterTopLevelDomain(am.accountKeeper, am.bankKeeper, am.keeper), + )) + // this line is used by starport scaffolding # simapp/module/operation return operations diff --git a/x/registry/simulation/register_top_level_domain.go b/x/registry/simulation/register_top_level_domain.go new file mode 100644 index 00000000..046b8325 --- /dev/null +++ b/x/registry/simulation/register_top_level_domain.go @@ -0,0 +1,29 @@ +package simulation + +import ( + "math/rand" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/mycel-domain/mycel/x/registry/keeper" + "github.com/mycel-domain/mycel/x/registry/types" +) + +func SimulateMsgRegisterTopLevelDomain( + ak types.AccountKeeper, + bk types.BankKeeper, + k keeper.Keeper, +) simtypes.Operation { + return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + simAccount, _ := simtypes.RandomAcc(r, accs) + msg := &types.MsgRegisterTopLevelDomain{ + Creator: simAccount.Address.String(), + } + + // TODO: Handling the RegisterTopLevelDomain simulation + + return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "RegisterTopLevelDomain simulation not implemented"), nil, nil + } +} diff --git a/x/registry/types/codec.go b/x/registry/types/codec.go index d521cc6b..32478fe8 100644 --- a/x/registry/types/codec.go +++ b/x/registry/types/codec.go @@ -10,6 +10,7 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgUpdateWalletRecord{}, "registry/UpdateWalletRecord", nil) cdc.RegisterConcrete(&MsgRegisterDomain{}, "registry/RegisterDomain", nil) + cdc.RegisterConcrete(&MsgRegisterTopLevelDomain{}, "registry/RegisterTopLevelDomain", nil) // this line is used by starport scaffolding # 2 } @@ -20,6 +21,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgRegisterDomain{}, ) + registry.RegisterImplementations((*sdk.Msg)(nil), + &MsgRegisterTopLevelDomain{}, + ) // this line is used by starport scaffolding # 3 msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/registry/types/events.go b/x/registry/types/events.go index b5c62bbb..4ae3f813 100644 --- a/x/registry/types/events.go +++ b/x/registry/types/events.go @@ -9,6 +9,14 @@ const ( AttributeRegisterDomainEventExpirationDate = "expiration-date" ) +// Register top-level-domain event +const ( + EventTypeRegsterTopLevelDomain = "register-top-level-domain" + + AttributeRegisterTopLevelDomainEventName = "name" + AttributeRegisterTopLevelDomainEventExpirationDate = "expiration-date" +) + // Update wallet record event const ( EventTypeUpdateWalletRecord = "update-wallet-record" diff --git a/x/registry/types/genesis.go b/x/registry/types/genesis.go index 80a7eb02..239139ad 100644 --- a/x/registry/types/genesis.go +++ b/x/registry/types/genesis.go @@ -18,7 +18,7 @@ func GetDefaultTLDs() (defaultTLDs []TopLevelDomain) { defaultRegistrationConfig := GetDefaultSubdomainConfig(3030) for _, v := range GetDefaultTLDNames() { defaultTLDs = append(defaultTLDs, TopLevelDomain{ - Name: v, + Name: v, SubdomainConfig: &defaultRegistrationConfig, }) } diff --git a/x/registry/types/message_register_top_level_domain.go b/x/registry/types/message_register_top_level_domain.go new file mode 100644 index 00000000..61eefdff --- /dev/null +++ b/x/registry/types/message_register_top_level_domain.go @@ -0,0 +1,45 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgRegisterTopLevelDomain = "register_top_level_domain" + +var _ sdk.Msg = &MsgRegisterTopLevelDomain{} + +func NewMsgRegisterTopLevelDomain(creator string) *MsgRegisterTopLevelDomain { + return &MsgRegisterTopLevelDomain{ + Creator: creator, + } +} + +func (msg *MsgRegisterTopLevelDomain) Route() string { + return RouterKey +} + +func (msg *MsgRegisterTopLevelDomain) Type() string { + return TypeMsgRegisterTopLevelDomain +} + +func (msg *MsgRegisterTopLevelDomain) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgRegisterTopLevelDomain) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgRegisterTopLevelDomain) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + return nil +} diff --git a/x/registry/types/message_register_top_level_domain_test.go b/x/registry/types/message_register_top_level_domain_test.go new file mode 100644 index 00000000..50f6bba5 --- /dev/null +++ b/x/registry/types/message_register_top_level_domain_test.go @@ -0,0 +1,40 @@ +package types + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/mycel-domain/mycel/testutil/sample" + "github.com/stretchr/testify/require" +) + +func TestMsgRegisterTopLevelDomain_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgRegisterTopLevelDomain + err error + }{ + { + name: "invalid address", + msg: MsgRegisterTopLevelDomain{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, { + name: "valid address", + msg: MsgRegisterTopLevelDomain{ + Creator: sample.AccAddress(), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} diff --git a/x/registry/types/second_level_domain_test.go b/x/registry/types/second_level_domain_test.go index 8a074bd0..659af8d8 100644 --- a/x/registry/types/second_level_domain_test.go +++ b/x/registry/types/second_level_domain_test.go @@ -29,7 +29,7 @@ func TestDomainValidate(t *testing.T) { }{ // Valid domains { - domain: SecondLevelDomain{Name: "foo", Parent: "myc"}, + domain: SecondLevelDomain{Name: "foo", Parent: "myc"}, expDomainParent: TopLevelDomain{Name: "myc"}, }, // Invalid name diff --git a/x/registry/types/tx.pb.go b/x/registry/types/tx.pb.go index 737b0e42..102a1ec6 100644 --- a/x/registry/types/tx.pb.go +++ b/x/registry/types/tx.pb.go @@ -355,6 +355,86 @@ func (m *MsgRegisterDomainResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterDomainResponse proto.InternalMessageInfo +type MsgRegisterTopLevelDomain struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` +} + +func (m *MsgRegisterTopLevelDomain) Reset() { *m = MsgRegisterTopLevelDomain{} } +func (m *MsgRegisterTopLevelDomain) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterTopLevelDomain) ProtoMessage() {} +func (*MsgRegisterTopLevelDomain) Descriptor() ([]byte, []int) { + return fileDescriptor_7a4e7619dfc6612f, []int{6} +} +func (m *MsgRegisterTopLevelDomain) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterTopLevelDomain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterTopLevelDomain.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 *MsgRegisterTopLevelDomain) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterTopLevelDomain.Merge(m, src) +} +func (m *MsgRegisterTopLevelDomain) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterTopLevelDomain) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterTopLevelDomain.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterTopLevelDomain proto.InternalMessageInfo + +func (m *MsgRegisterTopLevelDomain) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +type MsgRegisterTopLevelDomainResponse struct { +} + +func (m *MsgRegisterTopLevelDomainResponse) Reset() { *m = MsgRegisterTopLevelDomainResponse{} } +func (m *MsgRegisterTopLevelDomainResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRegisterTopLevelDomainResponse) ProtoMessage() {} +func (*MsgRegisterTopLevelDomainResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_7a4e7619dfc6612f, []int{7} +} +func (m *MsgRegisterTopLevelDomainResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRegisterTopLevelDomainResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRegisterTopLevelDomainResponse.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 *MsgRegisterTopLevelDomainResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRegisterTopLevelDomainResponse.Merge(m, src) +} +func (m *MsgRegisterTopLevelDomainResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRegisterTopLevelDomainResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRegisterTopLevelDomainResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRegisterTopLevelDomainResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgUpdateWalletRecord)(nil), "mycel.registry.MsgUpdateWalletRecord") proto.RegisterType((*MsgUpdateWalletRecordResponse)(nil), "mycel.registry.MsgUpdateWalletRecordResponse") @@ -362,37 +442,41 @@ func init() { proto.RegisterType((*MsgUpdateDnsRecordResponse)(nil), "mycel.registry.MsgUpdateDnsRecordResponse") proto.RegisterType((*MsgRegisterDomain)(nil), "mycel.registry.MsgRegisterDomain") proto.RegisterType((*MsgRegisterDomainResponse)(nil), "mycel.registry.MsgRegisterDomainResponse") + proto.RegisterType((*MsgRegisterTopLevelDomain)(nil), "mycel.registry.MsgRegisterTopLevelDomain") + proto.RegisterType((*MsgRegisterTopLevelDomainResponse)(nil), "mycel.registry.MsgRegisterTopLevelDomainResponse") } func init() { proto.RegisterFile("mycel/registry/tx.proto", fileDescriptor_7a4e7619dfc6612f) } var fileDescriptor_7a4e7619dfc6612f = []byte{ - // 397 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcf, 0xad, 0x4c, 0x4e, - 0xcd, 0xd1, 0x2f, 0x4a, 0x4d, 0xcf, 0x2c, 0x2e, 0x29, 0xaa, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, - 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x03, 0x4b, 0xe8, 0xc1, 0x24, 0x94, 0xe6, 0x33, 0x72, 0x89, 0xfa, - 0x16, 0xa7, 0x87, 0x16, 0xa4, 0x24, 0x96, 0xa4, 0x86, 0x27, 0xe6, 0xe4, 0xa4, 0x96, 0x04, 0xa5, - 0x26, 0xe7, 0x17, 0xa5, 0x08, 0x49, 0x70, 0xb1, 0x27, 0x17, 0xa5, 0x26, 0x96, 0xe4, 0x17, 0x49, - 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0xc1, 0xb8, 0x42, 0x42, 0x5c, 0x2c, 0x79, 0x89, 0xb9, 0xa9, - 0x12, 0x4c, 0x60, 0x61, 0x30, 0x5b, 0x48, 0x8c, 0x8b, 0xad, 0x20, 0xb1, 0x28, 0x35, 0xaf, 0x44, - 0x82, 0x19, 0x2c, 0x0a, 0xe5, 0x09, 0x69, 0x71, 0x09, 0x94, 0x23, 0x99, 0x1a, 0x52, 0x59, 0x90, - 0x2a, 0xc1, 0x02, 0x56, 0x81, 0x21, 0x2e, 0x24, 0xc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, - 0xf9, 0x4e, 0x1e, 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, 0xa5, 0x97, 0x9e, - 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x0f, 0x36, 0x4e, 0x37, 0x05, 0xac, 0x15, - 0xc2, 0xd1, 0xaf, 0x40, 0xca, 0xc2, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x6c, 0x6c, 0x0c, - 0x08, 0x00, 0x00, 0xff, 0xff, 0xe2, 0x96, 0xd6, 0x2b, 0xe1, 0x03, 0x00, 0x00, + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x41, 0xab, 0xd3, 0x40, + 0x10, 0xc7, 0xbb, 0xb6, 0xef, 0x89, 0x03, 0x3e, 0x75, 0xd1, 0x67, 0x8c, 0x1a, 0x7d, 0x51, 0x41, + 0x0b, 0x4d, 0x50, 0xf1, 0xe2, 0x51, 0x7a, 0x50, 0xb0, 0x20, 0xa1, 0x22, 0x7a, 0x10, 0xb6, 0xc9, + 0x10, 0x23, 0x49, 0x36, 0xec, 0x6e, 0x6b, 0xf3, 0x2d, 0xbc, 0xe8, 0xd5, 0x2f, 0xe0, 0x07, 0xf1, + 0xd8, 0xa3, 0x47, 0x69, 0xbf, 0x88, 0xb0, 0x6d, 0x42, 0xd3, 0x26, 0xaf, 0x3d, 0xf4, 0x96, 0x99, + 0xf9, 0xcf, 0x7f, 0x7e, 0x61, 0x86, 0x85, 0x9b, 0x49, 0xee, 0x63, 0xec, 0x0a, 0x0c, 0x23, 0xa9, + 0x44, 0xee, 0xaa, 0xa9, 0x93, 0x09, 0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c6, 0xbb, 0xd8, 0xed, 0x07, + 0x70, 0xd6, 0xd8, 0x56, 0x78, 0x3f, 0xfb, 0xdd, 0x86, 0xf6, 0x40, 0x86, 0xf4, 0x2b, 0xd0, 0x9a, + 0x73, 0x7c, 0xe4, 0x54, 0x2f, 0xd7, 0xa9, 0x3d, 0x0a, 0xb3, 0xb7, 0x97, 0xac, 0x98, 0x49, 0x19, + 0x5c, 0xd9, 0xbc, 0x1b, 0xbb, 0xd1, 0xa1, 0xd4, 0x98, 0xdd, 0xdd, 0x9a, 0x72, 0xc4, 0x67, 0x38, + 0xd9, 0xd8, 0xf1, 0x59, 0x4d, 0x77, 0x55, 0x62, 0x3e, 0xd9, 0x29, 0x29, 0xfd, 0x27, 0x70, 0xda, + 0xb0, 0x8f, 0xf3, 0x4c, 0xaa, 0x52, 0xf3, 0xe9, 0xde, 0xd2, 0x62, 0xee, 0xab, 0xd7, 0x7f, 0xe6, + 0x16, 0x99, 0xcd, 0x2d, 0xf2, 0x6f, 0x6e, 0x91, 0xef, 0x0b, 0xab, 0x35, 0x5b, 0x58, 0xad, 0xbf, + 0x0b, 0xab, 0xf5, 0xc9, 0x09, 0x23, 0xf5, 0x65, 0x3c, 0x72, 0x7c, 0x9e, 0xb8, 0xda, 0xb6, 0x17, + 0xe8, 0xd6, 0x65, 0xe0, 0x4e, 0xd7, 0x9e, 0xa5, 0x3c, 0x43, 0x39, 0x3a, 0xd6, 0x4f, 0xd3, 0xf3, + 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x96, 0x97, 0xbe, 0xb5, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -410,6 +494,7 @@ type MsgClient interface { UpdateWalletRecord(ctx context.Context, in *MsgUpdateWalletRecord, opts ...grpc.CallOption) (*MsgUpdateWalletRecordResponse, error) UpdateDnsRecord(ctx context.Context, in *MsgUpdateDnsRecord, opts ...grpc.CallOption) (*MsgUpdateDnsRecordResponse, error) RegisterDomain(ctx context.Context, in *MsgRegisterDomain, opts ...grpc.CallOption) (*MsgRegisterDomainResponse, error) + RegisterTopLevelDomain(ctx context.Context, in *MsgRegisterTopLevelDomain, opts ...grpc.CallOption) (*MsgRegisterTopLevelDomainResponse, error) } type msgClient struct { @@ -447,11 +532,21 @@ func (c *msgClient) RegisterDomain(ctx context.Context, in *MsgRegisterDomain, o return out, nil } +func (c *msgClient) RegisterTopLevelDomain(ctx context.Context, in *MsgRegisterTopLevelDomain, opts ...grpc.CallOption) (*MsgRegisterTopLevelDomainResponse, error) { + out := new(MsgRegisterTopLevelDomainResponse) + err := c.cc.Invoke(ctx, "/mycel.registry.Msg/RegisterTopLevelDomain", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { UpdateWalletRecord(context.Context, *MsgUpdateWalletRecord) (*MsgUpdateWalletRecordResponse, error) UpdateDnsRecord(context.Context, *MsgUpdateDnsRecord) (*MsgUpdateDnsRecordResponse, error) RegisterDomain(context.Context, *MsgRegisterDomain) (*MsgRegisterDomainResponse, error) + RegisterTopLevelDomain(context.Context, *MsgRegisterTopLevelDomain) (*MsgRegisterTopLevelDomainResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -467,6 +562,9 @@ func (*UnimplementedMsgServer) UpdateDnsRecord(ctx context.Context, req *MsgUpda func (*UnimplementedMsgServer) RegisterDomain(ctx context.Context, req *MsgRegisterDomain) (*MsgRegisterDomainResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RegisterDomain not implemented") } +func (*UnimplementedMsgServer) RegisterTopLevelDomain(ctx context.Context, req *MsgRegisterTopLevelDomain) (*MsgRegisterTopLevelDomainResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterTopLevelDomain not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -526,6 +624,24 @@ func _Msg_RegisterDomain_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Msg_RegisterTopLevelDomain_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRegisterTopLevelDomain) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RegisterTopLevelDomain(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/mycel.registry.Msg/RegisterTopLevelDomain", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RegisterTopLevelDomain(ctx, req.(*MsgRegisterTopLevelDomain)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "mycel.registry.Msg", HandlerType: (*MsgServer)(nil), @@ -542,6 +658,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "RegisterDomain", Handler: _Msg_RegisterDomain_Handler, }, + { + MethodName: "RegisterTopLevelDomain", + Handler: _Msg_RegisterTopLevelDomain_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "mycel/registry/tx.proto", @@ -781,6 +901,59 @@ func (m *MsgRegisterDomainResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *MsgRegisterTopLevelDomain) 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 *MsgRegisterTopLevelDomain) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterTopLevelDomain) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRegisterTopLevelDomainResponse) 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 *MsgRegisterTopLevelDomainResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRegisterTopLevelDomainResponse) 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 @@ -901,6 +1074,28 @@ func (m *MsgRegisterDomainResponse) Size() (n int) { return n } +func (m *MsgRegisterTopLevelDomain) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRegisterTopLevelDomainResponse) 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 } @@ -1642,6 +1837,138 @@ func (m *MsgRegisterDomainResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgRegisterTopLevelDomain) 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: MsgRegisterTopLevelDomain: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterTopLevelDomain: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", 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.Creator = string(dAtA[iNdEx:postIndex]) + 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 *MsgRegisterTopLevelDomainResponse) 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: MsgRegisterTopLevelDomainResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRegisterTopLevelDomainResponse: 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 From 0863f8dadfb07d1d9ef2f5be055fd769af5f8a6e Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Thu, 7 Sep 2023 18:01:38 +0900 Subject: [PATCH 3/7] wip --- proto/mycel/registry/tx.proto | 1 - .../msg_server_register_top_level_domain.go | 30 +++- x/registry/types/tx.pb.go | 145 ++++++++++++++---- 3 files changed, 143 insertions(+), 33 deletions(-) diff --git a/proto/mycel/registry/tx.proto b/proto/mycel/registry/tx.proto index 20a42b81..dc690697 100644 --- a/proto/mycel/registry/tx.proto +++ b/proto/mycel/registry/tx.proto @@ -47,4 +47,3 @@ message MsgRegisterTopLevelDomain { } message MsgRegisterTopLevelDomainResponse {} - diff --git a/x/registry/keeper/msg_server_register_top_level_domain.go b/x/registry/keeper/msg_server_register_top_level_domain.go index 48187717..09862d31 100644 --- a/x/registry/keeper/msg_server_register_top_level_domain.go +++ b/x/registry/keeper/msg_server_register_top_level_domain.go @@ -2,16 +2,40 @@ package keeper import ( "context" + "errors" + "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/mycel-domain/mycel/x/registry/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgRegisterTopLevelDomain) (*types.MsgRegisterTopLevelDomainResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // TODO: Handling the message - _ = ctx + if msg.RegistrationPeriodInYear < 1 || msg.RegistrationPeriodInYear > 4 { + return nil, sdkerrors.Wrapf(errors.New(fmt.Sprintf("%d year(s)", msg.RegistrationPeriodInYear)), types.ErrInvalidRegistrationPeriod.Error()) + } + + creatorAddress, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return nil, err + } + + currentTime := ctx.BlockTime() + expirationDate := currentTime.AddDate(int(msg.RegistrationPeriodInYear), 0, 0) + + domain := types.TopLevelDomain{ + Name: msg.Name, + ExpirationDate: expirationDate.UnixNano(), + Metadata: nil, + } + + err = k.Keeper.RegisterTopLevelDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear) + if err != nil { + return nil, err + } return &types.MsgRegisterTopLevelDomainResponse{}, nil } diff --git a/x/registry/types/tx.pb.go b/x/registry/types/tx.pb.go index 102a1ec6..7af319c9 100644 --- a/x/registry/types/tx.pb.go +++ b/x/registry/types/tx.pb.go @@ -356,7 +356,9 @@ func (m *MsgRegisterDomainResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgRegisterDomainResponse proto.InternalMessageInfo type MsgRegisterTopLevelDomain struct { - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + RegistrationPeriodInYear uint64 `protobuf:"varint,3,opt,name=registrationPeriodInYear,proto3" json:"registrationPeriodInYear,omitempty"` } func (m *MsgRegisterTopLevelDomain) Reset() { *m = MsgRegisterTopLevelDomain{} } @@ -399,6 +401,20 @@ func (m *MsgRegisterTopLevelDomain) GetCreator() string { return "" } +func (m *MsgRegisterTopLevelDomain) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *MsgRegisterTopLevelDomain) GetRegistrationPeriodInYear() uint64 { + if m != nil { + return m.RegistrationPeriodInYear + } + return 0 +} + type MsgRegisterTopLevelDomainResponse struct { } @@ -449,34 +465,35 @@ func init() { func init() { proto.RegisterFile("mycel/registry/tx.proto", fileDescriptor_7a4e7619dfc6612f) } var fileDescriptor_7a4e7619dfc6612f = []byte{ - // 430 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x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6f, 0x6e, 0x91, 0xef, 0x0b, 0xab, 0x35, 0x5b, 0x58, 0xad, 0xbf, - 0x0b, 0xab, 0xf5, 0xc9, 0x09, 0x23, 0xf5, 0x65, 0x3c, 0x72, 0x7c, 0x9e, 0xb8, 0xda, 0xb6, 0x17, - 0xe8, 0xd6, 0x65, 0xe0, 0x4e, 0xd7, 0x9e, 0xa5, 0x3c, 0x43, 0x39, 0x3a, 0xd6, 0x4f, 0xd3, 0xf3, - 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x8b, 0x96, 0x97, 0xbe, 0xb5, 0x04, 0x00, 0x00, + // 438 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x3b, 0xa6, 0xbb, 0xe2, 0x03, 0x57, 0x1d, 0x74, 0x8d, 0x51, 0xa3, 0x1b, 0x15, 0x74, + 0x61, 0x13, 0xd4, 0x9b, 0x47, 0xd9, 0x83, 0x82, 0x05, 0x09, 0x2b, 0xa2, 0x07, 0x61, 0x9a, 0x3c, + 0x62, 0x24, 0xc9, 0x84, 0x99, 0x69, 0x6d, 0x3e, 0x80, 0x77, 0x2f, 0x7a, 0xf5, 0x0b, 0xf8, 0x41, + 0x3c, 0xf6, 0xe8, 0x51, 0xda, 0x2f, 0x22, 0x4c, 0x9b, 0xd0, 0xb4, 0x49, 0x5b, 0x96, 0xde, 0xf2, + 0xde, 0xfb, 0xcf, 0xff, 0xfd, 0xc2, 0x7b, 0x33, 0x70, 0x33, 0x2d, 0x02, 0x4c, 0x3c, 0x81, 0x51, + 0x2c, 0x95, 0x28, 0x3c, 0x35, 0x72, 0x73, 0xc1, 0x15, 0xa7, 0x07, 0xba, 0xe0, 0x96, 0x05, 0xe7, + 0x17, 0x81, 0x1b, 0x3d, 0x19, 0xbd, 0xcb, 0x43, 0xa6, 0xf0, 0x3d, 0x4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x4f, 0x46, 0xf4, 0x0b, 0xd0, 0x86, 0xfd, 0x7e, 0xe4, 0xd6, 0xaf, 0x82, 0xdb, 0xb8, 0x65, + 0xd6, 0xc9, 0x56, 0xb2, 0xb2, 0x27, 0x65, 0x70, 0x65, 0x79, 0x11, 0x9d, 0x56, 0x87, 0x4a, 0x63, + 0x1d, 0x6f, 0xd6, 0x54, 0x2d, 0x3e, 0xc1, 0xc1, 0xd2, 0xd2, 0x1c, 0x35, 0x9c, 0xae, 0x4b, 0xac, + 0x27, 0x1b, 0x25, 0x95, 0xff, 0x10, 0x0e, 0x5b, 0xe6, 0xbb, 0xce, 0xa4, 0x2e, 0xb5, 0x9e, 0x6e, + 0x2d, 0x2d, 0xfb, 0xbe, 0x7c, 0xf5, 0x67, 0x62, 0x93, 0xf1, 0xc4, 0x26, 0xff, 0x26, 0x36, 0xf9, + 0x3e, 0xb5, 0x3b, 0xe3, 0xa9, 0xdd, 0xf9, 0x3b, 0xb5, 0x3b, 0x1f, 0xdd, 0x28, 0x56, 0x9f, 0x07, + 0x7d, 0x37, 0xe0, 0xa9, 0xa7, 0x6d, 0x4f, 0x42, 0x7d, 0x74, 0x16, 0x78, 0xa3, 0x85, 0x77, 0xae, + 0xc8, 0x51, 0xf6, 0xf7, 0xf5, 0x5b, 0xf7, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x73, 0x10, + 0xd9, 0xf1, 0x06, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -921,6 +938,18 @@ func (m *MsgRegisterTopLevelDomain) MarshalToSizedBuffer(dAtA []byte) (int, erro _ = i var l int _ = l + if m.RegistrationPeriodInYear != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.RegistrationPeriodInYear)) + i-- + dAtA[i] = 0x18 + } + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTx(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x12 + } if len(m.Creator) > 0 { i -= len(m.Creator) copy(dAtA[i:], m.Creator) @@ -1084,6 +1113,13 @@ func (m *MsgRegisterTopLevelDomain) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.RegistrationPeriodInYear != 0 { + n += 1 + sovTx(uint64(m.RegistrationPeriodInYear)) + } return n } @@ -1898,6 +1934,57 @@ func (m *MsgRegisterTopLevelDomain) Unmarshal(dAtA []byte) error { } m.Creator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", 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.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RegistrationPeriodInYear", wireType) + } + m.RegistrationPeriodInYear = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RegistrationPeriodInYear |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From f5214376dc8c9b4b26655b6ae429f2748e547f96 Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Tue, 12 Sep 2023 10:07:02 +0900 Subject: [PATCH 4/7] add valitating for TLD domain & fix to pass test --- ...g_server_register_top_level_domain_test.go | 17 ++++--- .../keeper/register_top_level_domain.go | 44 +++++++++++++++++++ x/registry/keeper/validate_registration.go | 37 +++++++++++++--- 3 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 x/registry/keeper/register_top_level_domain.go diff --git a/x/registry/keeper/msg_server_register_top_level_domain_test.go b/x/registry/keeper/msg_server_register_top_level_domain_test.go index e1db88f7..8b41a322 100644 --- a/x/registry/keeper/msg_server_register_top_level_domain_test.go +++ b/x/registry/keeper/msg_server_register_top_level_domain_test.go @@ -16,34 +16,33 @@ func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() { creator string name string registrationPeriodInYear uint64 - domainOwnership types.DomainOwnership expErr error fn func() }{ { creator: testutil.Alice, - name: "cel", + name: "cel0", registrationPeriodInYear: 1, expErr: nil, fn: func() {}, }, { creator: testutil.Alice, - name: "cel", + name: "cel1", registrationPeriodInYear: 4, expErr: nil, fn: func() {}, }, { creator: testutil.Alice, - name: "cel", + name: "cel2", registrationPeriodInYear: 1, - expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("foo.cel")), types.ErrDomainIsAlreadyTaken.Error()), + expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("cel2")), types.ErrDomainIsAlreadyTaken.Error()), fn: func() { // Register domain once domain := &types.MsgRegisterTopLevelDomain{ Creator: testutil.Alice, - Name: "cel", + Name: "cel2", RegistrationPeriodInYear: 1, } _, err := suite.msgServer.RegisterTopLevelDomain(suite.ctx, domain) @@ -69,7 +68,7 @@ func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() { _, err := suite.msgServer.RegisterTopLevelDomain(suite.ctx, registerMsg) fmt.Println("----Case_", i, "---01", err) - if err == nil { + if tc.expErr == nil { // Evalute if domain is registered _, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, tc.name) suite.Require().True(found) @@ -79,10 +78,10 @@ func (suite *KeeperTestSuite) TestRegisterTopLevelDomain() { events := sdk.StringifyEvents(suite.ctx.EventManager().ABCIEvents()) eventIndex := len(events) - 1 suite.Require().EqualValues(sdk.StringEvent{ - Type: types.EventTypeRegsterDomain, + Type: types.EventTypeRegsterTopLevelDomain, Attributes: []sdk.Attribute{ {Key: types.AttributeRegisterTopLevelDomainEventName, Value: tc.name}, - {Key: types.AttributeRegisterTopLevelDomainEventExpirationDate, Value: events[eventIndex].Attributes[2].Value}, + {Key: types.AttributeRegisterTopLevelDomainEventExpirationDate, Value: events[eventIndex].Attributes[1].Value}, }, }, events[eventIndex]) } else { diff --git a/x/registry/keeper/register_top_level_domain.go b/x/registry/keeper/register_top_level_domain.go new file mode 100644 index 00000000..ef8556a9 --- /dev/null +++ b/x/registry/keeper/register_top_level_domain.go @@ -0,0 +1,44 @@ +package keeper + +import ( + // "errors" + // "fmt" + "github.com/mycel-domain/mycel/x/registry/types" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + // sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// Pay TLD registration fee +func (k Keeper) PayTLDRegstrationFee(ctx sdk.Context, payer sdk.AccAddress, domain types.TopLevelDomain, registrationPeriodInYear uint64) (err error) { + // TODO: Pay fee + return nil +} + +func (k Keeper) RegisterTopLevelDomain(ctx sdk.Context, domain types.TopLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) { + // Validate domain + err = k.ValidateTopLevelDomain(ctx, domain) + if err != nil { + return err + } + + // Pay TLD registration fee + err = k.PayTLDRegstrationFee(ctx, owner, domain, registrationPeriodIYear) + if err != nil { + return err + } + + // Set domain + k.SetTopLevelDomain(ctx, domain) + + // Emit event + ctx.EventManager().EmitEvent( + sdk.NewEvent(types.EventTypeRegsterTopLevelDomain, + sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventName, domain.Name), + sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventExpirationDate, strconv.FormatInt(domain.ExpirationDate, 10)), + ), + ) + + return err +} diff --git a/x/registry/keeper/validate_registration.go b/x/registry/keeper/validate_registration.go index 36c59f8a..7e54197f 100644 --- a/x/registry/keeper/validate_registration.go +++ b/x/registry/keeper/validate_registration.go @@ -22,12 +22,15 @@ func (k Keeper) GetIsParentDomainExist(ctx sdk.Context, domain types.SecondLevel return isParentDomainExist } +// Get is domain already taken +func (k Keeper) GetIsTopLevelDomainAlreadyTaken(ctx sdk.Context, domain types.TopLevelDomain) (isDomainAlreadyTaken bool) { + _, isDomainAlreadyTaken = k.GetTopLevelDomain(ctx, domain.Name) + return isDomainAlreadyTaken +} + // Validate TLD registration -func (k Keeper) ValidateRegisterTLD(ctx sdk.Context, domain types.SecondLevelDomain) (err error) { - if domain.Parent != "" { - err = sdkerrors.Wrapf(errors.New(domain.Parent), - types.ErrParentDomainMustBeEmpty.Error()) - } +func (k Keeper) ValidateRegisterTLD(ctx sdk.Context, domain types.TopLevelDomain) (err error) { + // TODO: Validate TLD // TODO: Is Staked enough to register TLD return err } @@ -84,3 +87,27 @@ func (k Keeper) ValidateSecondLevelDomain(ctx sdk.Context, domain types.SecondLe return err } + +// Validate top-level-domain +func (k Keeper) ValidateTopLevelDomain(ctx sdk.Context, domain types.TopLevelDomain) (err error) { + // Type check + err = domain.Validate() + if err != nil { + return err + } + // Check if domain is already taken + isDomainAlreadyTaken := k.GetIsTopLevelDomainAlreadyTaken(ctx, domain) + if isDomainAlreadyTaken { + err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", domain.Name)), + types.ErrDomainIsAlreadyTaken.Error()) + return err + } + + // Validate TLD + err = k.ValidateRegisterTLD(ctx, domain) + if err != nil { + return err + } + + return err +} From cf45054c6374e3bede9dfb175ba1eca998e7c152 Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Wed, 13 Sep 2023 16:28:31 +0900 Subject: [PATCH 5/7] add args to TLD registration message --- ...gister_domain.go => tx_register_second_level_domain.go} | 0 x/registry/client/cli/tx_register_top_level_domain.go | 7 ++++++- x/registry/types/message_register_domain_test.go | 6 ++++++ x/registry/types/message_register_top_level_domain.go | 6 ++++-- x/registry/types/message_register_top_level_domain_test.go | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) rename x/registry/client/cli/{tx_register_domain.go => tx_register_second_level_domain.go} (100%) diff --git a/x/registry/client/cli/tx_register_domain.go b/x/registry/client/cli/tx_register_second_level_domain.go similarity index 100% rename from x/registry/client/cli/tx_register_domain.go rename to x/registry/client/cli/tx_register_second_level_domain.go diff --git a/x/registry/client/cli/tx_register_top_level_domain.go b/x/registry/client/cli/tx_register_top_level_domain.go index a1efed7d..99329df2 100644 --- a/x/registry/client/cli/tx_register_top_level_domain.go +++ b/x/registry/client/cli/tx_register_top_level_domain.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/mycel-domain/mycel/x/registry/types" + "github.com/spf13/cast" "github.com/spf13/cobra" ) @@ -16,8 +17,10 @@ func CmdRegisterTopLevelDomain() *cobra.Command { cmd := &cobra.Command{ Use: "register-top-level-domain", Short: "Broadcast message registerTopLevelDomain", - Args: cobra.ExactArgs(0), + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) (err error) { + argName := args[0] + argRegistrationPeriodInYear, err := cast.ToUint64E(args[1]) clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -26,6 +29,8 @@ func CmdRegisterTopLevelDomain() *cobra.Command { msg := types.NewMsgRegisterTopLevelDomain( clientCtx.GetFromAddress().String(), + argName, + argRegistrationPeriodInYear, ) if err := msg.ValidateBasic(); err != nil { return err diff --git a/x/registry/types/message_register_domain_test.go b/x/registry/types/message_register_domain_test.go index c8597400..80d9cb7d 100644 --- a/x/registry/types/message_register_domain_test.go +++ b/x/registry/types/message_register_domain_test.go @@ -18,12 +18,18 @@ func TestMsgRegisterDomain_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgRegisterDomain{ Creator: "invalid_address", + Name: "foo", + Parent: "cel", + RegistrationPeriodInYear: 1, }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgRegisterDomain{ Creator: sample.AccAddress(), + Name: "foo", + Parent: "cel", + RegistrationPeriodInYear: 1, }, }, } diff --git a/x/registry/types/message_register_top_level_domain.go b/x/registry/types/message_register_top_level_domain.go index 61eefdff..095a07a9 100644 --- a/x/registry/types/message_register_top_level_domain.go +++ b/x/registry/types/message_register_top_level_domain.go @@ -9,9 +9,11 @@ const TypeMsgRegisterTopLevelDomain = "register_top_level_domain" var _ sdk.Msg = &MsgRegisterTopLevelDomain{} -func NewMsgRegisterTopLevelDomain(creator string) *MsgRegisterTopLevelDomain { +func NewMsgRegisterTopLevelDomain(creator string, name string, registrationPeriodInYear uint64) *MsgRegisterTopLevelDomain { return &MsgRegisterTopLevelDomain{ - Creator: creator, + Creator: creator, + Name: name, + RegistrationPeriodInYear: registrationPeriodInYear, } } diff --git a/x/registry/types/message_register_top_level_domain_test.go b/x/registry/types/message_register_top_level_domain_test.go index 50f6bba5..19614f68 100644 --- a/x/registry/types/message_register_top_level_domain_test.go +++ b/x/registry/types/message_register_top_level_domain_test.go @@ -18,12 +18,16 @@ func TestMsgRegisterTopLevelDomain_ValidateBasic(t *testing.T) { name: "invalid address", msg: MsgRegisterTopLevelDomain{ Creator: "invalid_address", + Name: "cel", + RegistrationPeriodInYear: 1, }, err: sdkerrors.ErrInvalidAddress, }, { name: "valid address", msg: MsgRegisterTopLevelDomain{ Creator: sample.AccAddress(), + Name: "cel", + RegistrationPeriodInYear: 1, }, }, } From 3a25eb3ba1ace461e37dee04e17e00b7c73e5e32 Mon Sep 17 00:00:00 2001 From: tarumi Date: Wed, 13 Sep 2023 10:03:10 +0200 Subject: [PATCH 6/7] rename commands name --- x/registry/client/cli/tx_register_second_level_domain.go | 4 ++-- x/registry/client/cli/tx_register_top_level_domain.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/registry/client/cli/tx_register_second_level_domain.go b/x/registry/client/cli/tx_register_second_level_domain.go index d8935735..8ebbbed9 100644 --- a/x/registry/client/cli/tx_register_second_level_domain.go +++ b/x/registry/client/cli/tx_register_second_level_domain.go @@ -15,8 +15,8 @@ var _ = strconv.Itoa(0) func CmdRegisterDomain() *cobra.Command { cmd := &cobra.Command{ - Use: "register-domain [name] [parent] [registration-period-in-year]", - Short: "Broadcast message registerDomain", + Use: "register-second-level-domain [name] [parent] [registration-period-in-year]", + Short: "Broadcast message registerSecondLevelDomain", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) (err error) { argName := args[0] diff --git a/x/registry/client/cli/tx_register_top_level_domain.go b/x/registry/client/cli/tx_register_top_level_domain.go index 99329df2..29832b6e 100644 --- a/x/registry/client/cli/tx_register_top_level_domain.go +++ b/x/registry/client/cli/tx_register_top_level_domain.go @@ -15,7 +15,7 @@ var _ = strconv.Itoa(0) func CmdRegisterTopLevelDomain() *cobra.Command { cmd := &cobra.Command{ - Use: "register-top-level-domain", + Use: "register-top-level-domain [name] [registration-period-in-year]", Short: "Broadcast message registerTopLevelDomain", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) (err error) { From d8b17fbd7f024c8ac21b71f159f9c64f5fc061d0 Mon Sep 17 00:00:00 2001 From: Yuji Yamaguchi Date: Wed, 13 Sep 2023 18:13:31 +0900 Subject: [PATCH 7/7] set defaultRegistrationConfig during TLD registration --- x/registry/keeper/msg_server_register_top_level_domain.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/x/registry/keeper/msg_server_register_top_level_domain.go b/x/registry/keeper/msg_server_register_top_level_domain.go index 09862d31..c1da39ed 100644 --- a/x/registry/keeper/msg_server_register_top_level_domain.go +++ b/x/registry/keeper/msg_server_register_top_level_domain.go @@ -26,10 +26,12 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR currentTime := ctx.BlockTime() expirationDate := currentTime.AddDate(int(msg.RegistrationPeriodInYear), 0, 0) + defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030) domain := types.TopLevelDomain{ - Name: msg.Name, - ExpirationDate: expirationDate.UnixNano(), - Metadata: nil, + Name: msg.Name, + ExpirationDate: expirationDate.UnixNano(), + Metadata: nil, + SubdomainConfig: &defaultRegistrationConfig, } err = k.Keeper.RegisterTopLevelDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)