Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
rename registerDomain -> registerSecondLevelDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Oct 18, 2023
1 parent be2a2b4 commit fd061b8
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 146 deletions.
6 changes: 3 additions & 3 deletions proto/mycel/registry/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option go_package = "github.com/mycel-domain/mycel/x/registry/types";
service Msg {
rpc UpdateWalletRecord (MsgUpdateWalletRecord ) returns (MsgUpdateWalletRecordResponse );
rpc UpdateDnsRecord (MsgUpdateDnsRecord ) returns (MsgUpdateDnsRecordResponse );
rpc RegisterDomain (MsgRegisterDomain ) returns (MsgRegisterDomainResponse );
rpc RegisterSecondLevelDomain (MsgRegisterSecondLevelDomain ) returns (MsgRegisterSecondLevelDomainResponse );
rpc RegisterTopLevelDomain (MsgRegisterTopLevelDomain ) returns (MsgRegisterTopLevelDomainResponse );
rpc WithdrawRegistrationFee (MsgWithdrawRegistrationFee) returns (MsgWithdrawRegistrationFeeResponse);
}
Expand All @@ -32,14 +32,14 @@ message MsgUpdateDnsRecord {

message MsgUpdateDnsRecordResponse {}

message MsgRegisterDomain {
message MsgRegisterSecondLevelDomain {
string creator = 1;
string name = 2;
string parent = 3;
uint64 registrationPeriodInYear = 4;
}

message MsgRegisterDomainResponse {}
message MsgRegisterSecondLevelDomainResponse {}

message MsgRegisterTopLevelDomain {
string creator = 1;
Expand Down
2 changes: 1 addition & 1 deletion x/registry/client/cli/tx_register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func CmdRegisterDomain() *cobra.Command {
return err
}

msg := types.NewMsgRegisterDomain(
msg := types.NewMsgRegisterSecondLevelDomain(
clientCtx.GetFromAddress().String(),
argName,
argParent,
Expand Down
6 changes: 3 additions & 3 deletions x/registry/keeper/msg_server_register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) RegisterDomain(goCtx context.Context, msg *types.MsgRegisterDomain) (*types.MsgRegisterDomainResponse, error) {
func (k msgServer) RegisterSecondLevelDomain(goCtx context.Context, msg *types.MsgRegisterSecondLevelDomain) (*types.MsgRegisterSecondLevelDomainResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

if msg.RegistrationPeriodInYear < 1 || msg.RegistrationPeriodInYear > 4 {
Expand All @@ -38,10 +38,10 @@ func (k msgServer) RegisterDomain(goCtx context.Context, msg *types.MsgRegisterD
AccessControl: accessControl,
}

err = k.Keeper.RegisterDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)
err = k.Keeper.RegisterSecondLevelDomain(ctx, domain, creatorAddress, msg.RegistrationPeriodInYear)
if err != nil {
return nil, err
}

return &types.MsgRegisterDomainResponse{}, nil
return &types.MsgRegisterSecondLevelDomainResponse{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
expErr: errorsmod.Wrapf(errors.New(fmt.Sprintf("foo.cel")), types.ErrDomainIsAlreadyTaken.Error()),
fn: func() {
// Register domain once
domain := &types.MsgRegisterDomain{
domain := &types.MsgRegisterSecondLevelDomain{
Creator: testutil.Alice,
Name: "foo",
Parent: "cel",
RegistrationPeriodInYear: 1,
}
_, err := suite.msgServer.RegisterDomain(suite.ctx, domain)
_, err := suite.msgServer.RegisterSecondLevelDomain(suite.ctx, domain)
suite.Require().Nil(err)
},
},
Expand All @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
suite.Run(fmt.Sprintf("Case %d", i), func() {
suite.SetupTest()

registerMsg := &types.MsgRegisterDomain{
registerMsg := &types.MsgRegisterSecondLevelDomain{
Creator: tc.creator,
Name: tc.name,
Parent: tc.parent,
Expand All @@ -98,7 +98,7 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
tc.fn()

// Register domain
_, err := suite.msgServer.RegisterDomain(suite.ctx, registerMsg)
_, err := suite.msgServer.RegisterSecondLevelDomain(suite.ctx, registerMsg)
fmt.Println("----Case_", i, "---01", err)

if err == nil {
Expand All @@ -125,9 +125,9 @@ func (suite *KeeperTestSuite) TestRegisterSecondLevelDomain() {
suite.Require().EqualValues(sdk.StringEvent{
Type: types.EventTypeRegsterDomain,
Attributes: []sdk.Attribute{
{Key: types.AttributeRegisterDomainEventName, Value: tc.name},
{Key: types.AttributeRegisterDomainEventParent, Value: tc.parent},
{Key: types.AttributeRegisterDomainEventExpirationDate, Value: events[eventIndex].Attributes[2].Value},
{Key: types.AttributeRegisterSecondLevelDomainEventName, Value: tc.name},
{Key: types.AttributeRegisterSecondLevelDomainEventParent, Value: tc.parent},
{Key: types.AttributeRegisterSecondLevelDomainEventExpirationDate, Value: events[eventIndex].Attributes[2].Value},
},
}, events[eventIndex])
} else {
Expand Down
4 changes: 2 additions & 2 deletions x/registry/keeper/msg_server_update_dns_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func (suite *KeeperTestSuite) TestUpdateDnsRecord() {
suite.SetupTest()

// Register domain
domain := &types.MsgRegisterDomain{
domain := &types.MsgRegisterSecondLevelDomain{
Creator: testutil.Alice,
Name: "foo",
Parent: "cel",
RegistrationPeriodInYear: 1,
}
_, err := suite.msgServer.RegisterDomain(suite.ctx, domain)
_, err := suite.msgServer.RegisterSecondLevelDomain(suite.ctx, domain)
suite.Require().Nil(err)
// Run test case function
tc.fn()
Expand Down
2 changes: 1 addition & 1 deletion x/registry/keeper/msg_server_update_wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (k msgServer) UpdateWalletRecord(goCtx context.Context, msg *types.MsgUpdat
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeUpdateWalletRecord,
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventDomainName, msg.Name),
sdk.NewAttribute(types.AttributeRegisterDomainEventParent, msg.Parent),
sdk.NewAttribute(types.AttributeUpdateDnsRecordEventDomainParent, msg.Parent),
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventWalletRecordType, msg.WalletRecordType),
sdk.NewAttribute(types.AttributeUpdateWalletRecordEventValue, msg.Value),
),
Expand Down
4 changes: 2 additions & 2 deletions x/registry/keeper/msg_server_update_wallet_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ func (suite *KeeperTestSuite) TestUpdateWalletRecord() {
suite.SetupTest()

// Register domain
domain := &types.MsgRegisterDomain{
domain := &types.MsgRegisterSecondLevelDomain{
Creator: testutil.Alice,
Name: "foo",
Parent: "cel",
RegistrationPeriodInYear: 1,
}
_, err := suite.msgServer.RegisterDomain(suite.ctx, domain)
_, err := suite.msgServer.RegisterSecondLevelDomain(suite.ctx, domain)
suite.Require().Nil(err)
// Run test case function
tc.fn()
Expand Down
8 changes: 4 additions & 4 deletions x/registry/keeper/register_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (k Keeper) IncrementParentsSubdomainCount(ctx sdk.Context, domain types.Sec
k.SetTopLevelDomain(ctx, parentDomain)
}

func (k Keeper) RegisterDomain(ctx sdk.Context, domain types.SecondLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) {
func (k Keeper) RegisterSecondLevelDomain(ctx sdk.Context, domain types.SecondLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) {
// Validate domain
err = k.ValidateSecondLevelDomain(ctx, domain)
if err != nil {
Expand Down Expand Up @@ -104,9 +104,9 @@ func (k Keeper) RegisterDomain(ctx sdk.Context, domain types.SecondLevelDomain,
// Emit event
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeRegsterDomain,
sdk.NewAttribute(types.AttributeRegisterDomainEventName, domain.Name),
sdk.NewAttribute(types.AttributeRegisterDomainEventParent, domain.Parent),
sdk.NewAttribute(types.AttributeRegisterDomainEventExpirationDate, strconv.FormatInt(domain.ExpirationDate, 10)),
sdk.NewAttribute(types.AttributeRegisterSecondLevelDomainEventName, domain.Name),
sdk.NewAttribute(types.AttributeRegisterSecondLevelDomainEventParent, domain.Parent),
sdk.NewAttribute(types.AttributeRegisterSecondLevelDomainEventExpirationDate, strconv.FormatInt(domain.ExpirationDate, 10)),
),
)

Expand Down
14 changes: 7 additions & 7 deletions x/registry/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgUpdateWalletRecord int = 100

opWeightMsgRegisterDomain = "op_weight_msg_register_domain"
opWeightMsgRegisterSecondLevelDomain = "op_weight_msg_register_domain"
// TODO: Determine the simulation weight value
defaultWeightMsgRegisterDomain int = 100
defaultWeightMsgRegisterSecondLevelDomain int = 100

opWeightMsgRegisterTopLevelDomain = "op_weight_msg_register_top_level_domain"
// TODO: Determine the simulation weight value
Expand Down Expand Up @@ -78,15 +78,15 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
registrysimulation.SimulateMsgUpdateWalletRecord(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgRegisterDomain int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegisterDomain, &weightMsgRegisterDomain, nil,
var weightMsgRegisterSecondLevelDomain int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgRegisterSecondLevelDomain, &weightMsgRegisterSecondLevelDomain, nil,
func(_ *rand.Rand) {
weightMsgRegisterDomain = defaultWeightMsgRegisterDomain
weightMsgRegisterSecondLevelDomain = defaultWeightMsgRegisterSecondLevelDomain
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgRegisterDomain,
registrysimulation.SimulateMsgRegisterDomain(am.accountKeeper, am.bankKeeper, am.keeper),
weightMsgRegisterSecondLevelDomain,
registrysimulation.SimulateMsgRegisterSecondLevelDomain(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgRegisterTopLevelDomain int
Expand Down
8 changes: 4 additions & 4 deletions x/registry/simulation/register_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
"github.com/mycel-domain/mycel/x/registry/types"
)

func SimulateMsgRegisterDomain(
func SimulateMsgRegisterSecondLevelDomain(
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.MsgRegisterDomain{
msg := &types.MsgRegisterSecondLevelDomain{
Creator: simAccount.Address.String(),
}

// TODO: Handling the RegisterDomain simulation
// TODO: Handling the RegisterSecondLevelDomain simulation

return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "RegisterDomain simulation not implemented"), nil, nil
return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "RegisterSecondLevelDomain simulation not implemented"), nil, nil
}
}
4 changes: 2 additions & 2 deletions x/registry/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgUpdateWalletRecord{}, "registry/UpdateWalletRecord", nil)
cdc.RegisterConcrete(&MsgRegisterDomain{}, "registry/RegisterDomain", nil)
cdc.RegisterConcrete(&MsgRegisterSecondLevelDomain{}, "registry/RegisterSecondLevelDomain", nil)
cdc.RegisterConcrete(&MsgRegisterTopLevelDomain{}, "registry/RegisterTopLevelDomain", nil)
cdc.RegisterConcrete(&MsgWithdrawRegistrationFee{}, "registry/WithdrawRegistrationFee", nil)
// this line is used by starport scaffolding # 2
Expand All @@ -20,7 +20,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgUpdateWalletRecord{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgRegisterDomain{},
&MsgRegisterSecondLevelDomain{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgRegisterTopLevelDomain{},
Expand Down
6 changes: 3 additions & 3 deletions x/registry/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package types
const (
EventTypeRegsterDomain = "register-domain"

AttributeRegisterDomainEventName = "name"
AttributeRegisterDomainEventParent = "parent"
AttributeRegisterDomainEventExpirationDate = "expiration-date"
AttributeRegisterSecondLevelDomainEventName = "name"
AttributeRegisterSecondLevelDomainEventParent = "parent"
AttributeRegisterSecondLevelDomainEventExpirationDate = "expiration-date"
)

// Register top-level-domain event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgRegisterDomain = "register_domain"
const TypeMsgRegisterSecondLevelDomain = "register_domain"

var _ sdk.Msg = &MsgRegisterDomain{}
var _ sdk.Msg = &MsgRegisterSecondLevelDomain{}

func NewMsgRegisterDomain(creator string, name string, parent string, registrationPeriodInYear uint64) *MsgRegisterDomain {
return &MsgRegisterDomain{
func NewMsgRegisterSecondLevelDomain(creator string, name string, parent string, registrationPeriodInYear uint64) *MsgRegisterSecondLevelDomain {
return &MsgRegisterSecondLevelDomain{
Creator: creator,
Name: name,
Parent: parent,
RegistrationPeriodInYear: registrationPeriodInYear,
}
}

func (msg *MsgRegisterDomain) Route() string {
func (msg *MsgRegisterSecondLevelDomain) Route() string {
return RouterKey
}

func (msg *MsgRegisterDomain) Type() string {
return TypeMsgRegisterDomain
func (msg *MsgRegisterSecondLevelDomain) Type() string {
return TypeMsgRegisterSecondLevelDomain
}

func (msg *MsgRegisterDomain) GetSigners() []sdk.AccAddress {
func (msg *MsgRegisterSecondLevelDomain) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}

func (msg *MsgRegisterDomain) GetSignBytes() []byte {
func (msg *MsgRegisterSecondLevelDomain) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgRegisterDomain) ValidateBasic() error {
func (msg *MsgRegisterSecondLevelDomain) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/stretchr/testify/require"
)

func TestMsgRegisterDomain_ValidateBasic(t *testing.T) {
func TestMsgRegisterSecondLevelDomain_ValidateBasic(t *testing.T) {
tests := []struct {
name string
msg MsgRegisterDomain
msg MsgRegisterSecondLevelDomain
err error
}{
{
name: "invalid address",
msg: MsgRegisterDomain{
msg: MsgRegisterSecondLevelDomain{
Creator: "invalid_address",
Name: "foo",
Parent: "cel",
Expand All @@ -25,7 +25,7 @@ func TestMsgRegisterDomain_ValidateBasic(t *testing.T) {
err: sdkerrors.ErrInvalidAddress,
}, {
name: "valid address",
msg: MsgRegisterDomain{
msg: MsgRegisterSecondLevelDomain{
Creator: sample.AccAddress(),
Name: "foo",
Parent: "cel",
Expand Down
Loading

0 comments on commit fd061b8

Please sign in to comment.