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

Commit

Permalink
ExpirationDate -> ExpirationDateInUnixNano
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Nov 2, 2023
1 parent 85a80f4 commit 4c9ec36
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 82 deletions.
14 changes: 7 additions & 7 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50303,7 +50303,7 @@ paths:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -50531,7 +50531,7 @@ paths:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -81193,7 +81193,7 @@ definitions:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -81361,7 +81361,7 @@ definitions:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -81653,7 +81653,7 @@ definitions:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -81838,7 +81838,7 @@ definitions:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down Expand Up @@ -82107,7 +82107,7 @@ definitions:
properties:
name:
type: string
expirationDate:
expirationDateInUnixNano:
type: string
format: int64
metadata:
Expand Down
2 changes: 1 addition & 1 deletion proto/mycel/registry/top_level_domain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option go_package = "github.com/mycel-domain/mycel/x/registry/types";

message TopLevelDomain {
string name = 1;
int64 expirationDate = 2;
int64 expirationDateInUnixNano = 2;
map<string, string> metadata = 3;
SubdomainConfig subdomainConfig = 4;
uint64 subdomainCount = 5;
Expand Down
8 changes: 6 additions & 2 deletions x/registry/keeper/events.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package keeper

import (
"time"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/mycel-domain/mycel/x/registry/types"
"strconv"
)

// Register top-level-domain event
func EmitRegisterTopLevelDomainEvent(ctx sdk.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) {
expirationDate := time.Unix(0, domain.ExpirationDateInUnixNano)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeRegisterTopLevelDomain,
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventName, domain.Name),
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventExpirationDate, fmt.Sprintf("%d", domain.ExpirationDate)),
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventExpirationDate, expirationDate.String()),
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventMaxSubdomainRegistrations, fmt.Sprintf("%d", domain.SubdomainConfig.MaxSubdomainRegistrations)),
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventTotalRegistrationFee, fee.TotalFee.String()),
sdk.NewAttribute(types.AttributeRegisterTopLevelDomainEventBurnWeight, fee.BurnWeight),
Expand Down Expand Up @@ -71,10 +74,11 @@ func EmitWithdrawRegistrationFeeEvent(ctx sdk.Context, msg types.MsgWithdrawRegi

// Extend top-level-domain expiration date event
func EmitExtendTopLevelDomainExpirationDateEvent(ctx sdk.Context, domain types.TopLevelDomain, fee types.TopLevelDomainFee) {
expirationDate := time.Unix(0, domain.ExpirationDateInUnixNano)
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeExtendTopLevelDomainExpirationDate,
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventDomainName, domain.Name),
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventExpirationDate, fmt.Sprintf("%d", domain.ExpirationDate)),
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventExpirationDate, expirationDate.String()),
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventTotalRegistrationFee, fee.TotalFee.String()),
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventBurnWeight, fee.BurnWeight),
sdk.NewAttribute(types.AttributeExtendTopLevelDomainExpirationDateEventRegistrationFeeToBurn, fee.FeeToBurn.String()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ func (suite *KeeperTestSuite) TestExtendTopLevelDomain() {
suite.Require().Nil(err)
beforeDomain, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, name)
suite.Require().True(found)
beforeExpirationDate := time.Unix(0, beforeDomain.ExpirationDate)
_ = beforeExpirationDate
beforeExpirationDate := time.Unix(0, beforeDomain.ExpirationDateInUnixNano)

// Run test case function
tc.fn()
Expand All @@ -78,14 +77,14 @@ func (suite *KeeperTestSuite) TestExtendTopLevelDomain() {
suite.Require().Nil(err)
// Evaluate if domain is extended
// Response
registerExpirationDate := time.Unix(0, registerRsp.TopLevelDomain.ExpirationDate)
extendExpirationDate := time.Unix(0, extendRsp.TopLevelDomain.ExpirationDate)
registerExpirationDate := time.Unix(0, registerRsp.TopLevelDomain.ExpirationDateInUnixNano)
extendExpirationDate := time.Unix(0, extendRsp.TopLevelDomain.ExpirationDateInUnixNano)
suite.Require().Equal(registerExpirationDate.AddDate(0, 0, int(tc.extensionPeriodInYear)*params.OneYearInDays), extendExpirationDate)
// Store
afterDomain, found := suite.app.RegistryKeeper.GetTopLevelDomain(suite.ctx, name)
suite.Require().True(found)
expAfterExpirationDate := beforeExpirationDate.AddDate(0, 0, int(tc.extensionPeriodInYear)*params.OneYearInDays)
afterExpirationDate := time.Unix(0, afterDomain.ExpirationDate)
afterExpirationDate := time.Unix(0, afterDomain.ExpirationDateInUnixNano)
suite.Require().Equal(expAfterExpirationDate, afterExpirationDate)

// Evalute events
Expand Down
12 changes: 6 additions & 6 deletions x/registry/keeper/msg_server_register_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func (k msgServer) RegisterTopLevelDomain(goCtx context.Context, msg *types.MsgR

defaultRegistrationConfig := types.GetDefaultSubdomainConfig(3030)
domain := types.TopLevelDomain{
Name: msg.Name,
ExpirationDate: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
TotalWithdrawalAmount: sdk.NewCoins(),
Name: msg.Name,
ExpirationDateInUnixNano: expirationDate.UnixNano(),
Metadata: nil,
SubdomainConfig: &defaultRegistrationConfig,
AccessControl: accessControl,
TotalWithdrawalAmount: sdk.NewCoins(),
}

fee, err := k.Keeper.RegisterTopLevelDomain(ctx, domain, msg.Creator, msg.RegistrationPeriodInYear)
Expand Down
6 changes: 3 additions & 3 deletions x/registry/keeper/top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func (k Keeper) GetValidTopLevelDomain(ctx sdk.Context, name string) (topLevelDo
}

// Check if domain is not expired
expirationDate := time.Unix(0, topLevelDomain.ExpirationDate)
if ctx.BlockTime().After(expirationDate) && topLevelDomain.ExpirationDate != 0 {
expirationDate := time.Unix(0, topLevelDomain.ExpirationDateInUnixNano)
if ctx.BlockTime().After(expirationDate) && topLevelDomain.ExpirationDateInUnixNano != 0 {
return topLevelDomain, errorsmod.Wrapf(types.ErrDomainExpired, "%s", name)
}

Expand Down Expand Up @@ -219,7 +219,7 @@ func (k Keeper) ExtendTopLevelDomainExpirationDate(ctx sdk.Context, creator stri
}

// Update domain store
currentExpirationDate := time.Unix(0, domain.ExpirationDate)
currentExpirationDate := time.Unix(0, domain.ExpirationDateInUnixNano)
domain.ExtendExpirationDate(currentExpirationDate, extensionPeriodInYear)
k.SetTopLevelDomain(ctx, *domain)

Expand Down
6 changes: 3 additions & 3 deletions x/registry/keeper/top_level_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ func (suite *KeeperTestSuite) TestGetValidTopLevelDomain() {
{
topLevelDomain: types.TopLevelDomain{
Name: "test",
ExpirationDate: suite.ctx.BlockTime().AddDate(0, 0, 20).UnixNano(),
ExpirationDateInUnixNano: suite.ctx.BlockTime().AddDate(0, 0, 20).UnixNano(),
},
expErr: nil,
},
{
topLevelDomain: types.TopLevelDomain{
Name: "test",
ExpirationDate: 0,
ExpirationDateInUnixNano: 0,
},
expErr: nil,
},
{
topLevelDomain: types.TopLevelDomain{
Name: "test",
ExpirationDate: suite.ctx.BlockTime().AddDate(0, 0, -20).UnixNano(),
ExpirationDateInUnixNano: suite.ctx.BlockTime().AddDate(0, 0, -20).UnixNano(),
},
expErr: errorsmod.Wrapf(types.ErrDomainExpired, "test"),
},
Expand Down
2 changes: 1 addition & 1 deletion x/registry/types/top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (topLevelDomain TopLevelDomain) IsEditable(sender string) (isEditable bool,
func (topLevelDomain *TopLevelDomain) ExtendExpirationDate(from time.Time, extensionPeriodInYear uint64) (expirationDateInUnixNano int64) {
newExpirationDate := from.AddDate(0, 0, params.OneYearInDays*int(extensionPeriodInYear))
expirationDateInUnixNano = newExpirationDate.UnixNano()
topLevelDomain.ExpirationDate = expirationDateInUnixNano
topLevelDomain.ExpirationDateInUnixNano = expirationDateInUnixNano

return expirationDateInUnixNano
}
Loading

0 comments on commit 4c9ec36

Please sign in to comment.