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

Commit

Permalink
impl tld registration fee query
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Nov 2, 2023
1 parent c39311f commit f923a89
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 114 deletions.
71 changes: 50 additions & 21 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50200,21 +50200,33 @@ paths:
schema:
type: object
properties:
isRegstrable:
type: boolean
fee:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: >-
Coin defines a token with a denomination and an amount.


NOTE: The amount field is an Int which implements the custom
method
NOTE: The amount field is an Int which implements the custom
method

signatures required by gogoproto.
signatures required by gogoproto.
registrationPeriodInYear:
type: string
format: uint64
maxSubDomainRegistrations:
type: string
format: uint64
errorMessage:
type: string
default:
description: An unexpected error response.
schema:
Expand Down Expand Up @@ -50242,6 +50254,11 @@ paths:
in: path
required: true
type: string
- name: registrationPeriodInYear
in: query
required: false
type: string
format: uint64
tags:
- Query
/mycel-domain/mycel/registry/is_registrable_domain/{name}/{parent}:
Expand Down Expand Up @@ -81788,18 +81805,30 @@ definitions:
mycel.registry.QueryDomainRegistrationFeeResponse:
type: object
properties:
isRegstrable:
type: boolean
fee:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.
type: array
items:
type: object
properties:
denom:
type: string
amount:
type: string
description: |-
Coin defines a token with a denomination and an amount.

NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
NOTE: The amount field is an Int which implements the custom method
signatures required by gogoproto.
registrationPeriodInYear:
type: string
format: uint64
maxSubDomainRegistrations:
type: string
format: uint64
errorMessage:
type: string
mycel.registry.QueryGetDomainOwnershipResponse:
type: object
properties:
Expand Down
10 changes: 9 additions & 1 deletion proto/mycel/registry/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,18 @@ message QueryAllDomainOwnershipResponse {
message QueryDomainRegistrationFeeRequest {
string name = 1;
string parent = 2;
uint64 registrationPeriodInYear = 3;
}

message QueryDomainRegistrationFeeResponse {
cosmos.base.v1beta1.Coin fee = 1 [(gogoproto.nullable) = false];
bool isRegstrable = 1;
repeated cosmos.base.v1beta1.Coin fee = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
uint64 registrationPeriodInYear = 3;
uint64 maxSubDomainRegistrations = 4;
string errorMessage = 5;
}

message QueryIsRegistrableDomainRequest {
Expand Down
8 changes: 5 additions & 3 deletions x/registry/client/cli/query_domain_registration_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/mycel-domain/mycel/x/registry/types"
"github.com/spf13/cast"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdDomainRegistrationFee() *cobra.Command {
cmd := &cobra.Command{
Use: "domain-registration-fee [name] [parent]",
Use: "domain-registration-fee [name] [parent] [registration-period-in-year]",
Short: "query domain registration fee",
Args: cobra.ExactArgs(2),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
reqName := args[0]
reqParent := args[1]
reqRegistrationPeriodInYear, err := cast.ToUint64E(args[2])

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand All @@ -28,9 +30,9 @@ func CmdDomainRegistrationFee() *cobra.Command {
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryDomainRegistrationFeeRequest{

Name: reqName,
Parent: reqParent,
RegistrationPeriodInYear: reqRegistrationPeriodInYear,
}

res, err := queryClient.DomainRegistrationFee(cmd.Context(), params)
Expand Down
63 changes: 53 additions & 10 deletions x/registry/keeper/query_domain_registration_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,64 @@ import (
"google.golang.org/grpc/status"
)

func createErrorResponse(err error) *types.QueryDomainRegistrationFeeResponse {
return &types.QueryDomainRegistrationFeeResponse{
IsRegstrable: false,
Fee: sdk.NewCoins(),
RegistrationPeriodInYear: 0,
MaxSubDomainRegistrations: 0,
ErrorMessage: err.Error(),
}
}

func (k Keeper) DomainRegistrationFee(goCtx context.Context, req *types.QueryDomainRegistrationFeeRequest) (*types.QueryDomainRegistrationFeeResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Process the query
_ = ctx
domain := types.SecondLevelDomain{Name: req.Name, Parent: req.Parent}
config := k.GetSecondLevelDomainParentsSubdomainConfig(ctx, domain)
fee, err := config.GetRegistrationFee(domain.Name, 1)
if err != nil {
return nil, err
if req.Parent == "" {
// Top level domain
config := types.GetDefaultSubdomainConfig(1)
domain := types.TopLevelDomain{
Name: req.Name,
SubdomainConfig: &config,
}
err := k.ValidateTopLevelDomainIsRegistrable(ctx, domain)
if err != nil {
return createErrorResponse(err), nil
}
fee, err := k.GetTopLevelDomainFee(ctx, domain, req.RegistrationPeriodInYear)
if err != nil {
return createErrorResponse(err), nil
} else {
return &types.QueryDomainRegistrationFeeResponse{
IsRegstrable: true,
Fee: fee.TotalFee,
RegistrationPeriodInYear: 1,
MaxSubDomainRegistrations: config.MaxSubdomainRegistrations,
ErrorMessage: "",
}, nil
}
} else {
// Second level domain
domain := types.SecondLevelDomain{Name: req.Name, Parent: req.Parent}
err := k.ValidateSecondLevelDomainIsRegistrable(ctx, domain)
if err != nil {
return createErrorResponse(err), nil
}
config := k.GetSecondLevelDomainParentsSubdomainConfig(ctx, domain)
fee, err := config.GetRegistrationFee(domain.Name, req.RegistrationPeriodInYear)
if err != nil {
return createErrorResponse(err), nil
} else {
return &types.QueryDomainRegistrationFeeResponse{
IsRegstrable: true,
Fee: sdk.NewCoins(fee),
RegistrationPeriodInYear: 1,
MaxSubDomainRegistrations: 0,
ErrorMessage: "",
}, nil
}
}

return &types.QueryDomainRegistrationFeeResponse{Fee: fee}, nil
}
1 change: 1 addition & 0 deletions x/registry/keeper/top_level_domain_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (k Keeper) GetTopLevelDomainFee(ctx sdk.Context, topLevelDomain types.TopLe
if err != nil {
return types.TopLevelDomainFee{}, err
}
topLevelDomainFee.TotalFee = sdk.NewCoins(sdk.NewCoin(denom, fee))

// Get burn weight (=W)
weight, err := k.GetBurnWeight(ctx)
Expand Down
Loading

0 comments on commit f923a89

Please sign in to comment.