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

TLD registration #79

Merged
merged 8 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ import (
const (
AccountAddressPrefix = "mycel"
Name = "mycel"
HumanCoinUnit = "mycel"
BaseCoinUnit = "umycel"
MycelExponent = 6
HumanCoinUnit = "mycel"
BaseCoinUnit = "umycel"
MycelExponent = 6

DefaultBondDenom = BaseCoinUnit

Expand All @@ -161,6 +161,7 @@ func RegisterDenoms() {
panic(err)
}
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand All @@ -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 == "" {
Expand Down
3 changes: 1 addition & 2 deletions app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 17 additions & 8 deletions proto/mycel/registry/tx.proto
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {}
Expand All @@ -38,3 +40,10 @@ message MsgRegisterDomain {

message MsgRegisterDomainResponse {}

message MsgRegisterTopLevelDomain {
string creator = 1;
string name = 2;
uint64 registrationPeriodInYear = 3;
}

message MsgRegisterTopLevelDomainResponse {}
1 change: 1 addition & 0 deletions x/registry/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
45 changes: 45 additions & 0 deletions x/registry/client/cli/tx_register_top_level_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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/cast"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdRegisterTopLevelDomain() *cobra.Command {
taryune marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
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) {
argName := args[0]
argRegistrationPeriodInYear, err := cast.ToUint64E(args[1])

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgRegisterTopLevelDomain(
clientCtx.GetFromAddress().String(),
argName,
argRegistrationPeriodInYear,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
43 changes: 43 additions & 0 deletions x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package keeper

import (
"context"
"errors"
"fmt"

"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)

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)

defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030)
domain := types.TopLevelDomain{
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
}

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

return &types.MsgRegisterTopLevelDomainResponse{}, nil
}
92 changes: 92 additions & 0 deletions x/registry/keeper/msg_server_register_top_level_domain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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
expErr error
fn func()
}{
{
creator: testutil.Alice,
name: "cel0",
registrationPeriodInYear: 1,
expErr: nil,
fn: func() {},
},
{
creator: testutil.Alice,
name: "cel1",
registrationPeriodInYear: 4,
expErr: nil,
fn: func() {},
},
{
creator: testutil.Alice,
name: "cel2",
registrationPeriodInYear: 1,
expErr: sdkerrors.Wrapf(errors.New(fmt.Sprintf("cel2")), types.ErrDomainIsAlreadyTaken.Error()),
fn: func() {
// Register domain once
domain := &types.MsgRegisterTopLevelDomain{
Creator: testutil.Alice,
Name: "cel2",
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 tc.expErr == 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.EventTypeRegsterTopLevelDomain,
Attributes: []sdk.Attribute{
{Key: types.AttributeRegisterTopLevelDomainEventName, Value: tc.name},
{Key: types.AttributeRegisterTopLevelDomainEventExpirationDate, Value: events[eventIndex].Attributes[1].Value},
},
}, events[eventIndex])
} else {
suite.Require().EqualError(err, tc.expErr.Error())
}
})
}
}
44 changes: 44 additions & 0 deletions x/registry/keeper/register_top_level_domain.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading