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

Commit

Permalink
Impl registry/keeper/query_role
Browse files Browse the repository at this point in the history
  • Loading branch information
foxytanuki committed Nov 17, 2023
1 parent e0cff80 commit 7d7ca28
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions x/registry/keeper/query_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
Expand All @@ -11,14 +12,30 @@ import (
)

func (k Keeper) Role(goCtx context.Context, req *types.QueryRoleRequest) (*types.QueryRoleResponse, error) {
var role types.DomainRole
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Process the query
_ = ctx
dms := strings.Split(req.DomainName, ".")
switch len(dms) {
case 1: // TLD
tld, found := k.GetTopLevelDomain(ctx, dms[0])
if !found {
return nil, status.Error(codes.NotFound, "domain not found")
}
role = tld.AccessControl[req.Address]
case 2: // SLD
sld, found := k.GetSecondLevelDomain(ctx, dms[0], dms[1])
if !found {
return nil, status.Error(codes.NotFound, "domain not found")
}
role = sld.AccessControl[req.Address]
default:
return nil, status.Error(codes.InvalidArgument, "invalid request: domain name")
}

return &types.QueryRoleResponse{}, nil
return &types.QueryRoleResponse{Role: role.String()}, nil
}

0 comments on commit 7d7ca28

Please sign in to comment.