From 7d7ca281775372b02d811086b22358a5cf2250dc Mon Sep 17 00:00:00 2001 From: foxytanuki Date: Sat, 18 Nov 2023 07:00:53 +0900 Subject: [PATCH] Impl registry/keeper/query_role --- x/registry/keeper/query_role.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/x/registry/keeper/query_role.go b/x/registry/keeper/query_role.go index c7cc4750..3d5ded68 100644 --- a/x/registry/keeper/query_role.go +++ b/x/registry/keeper/query_role.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "strings" sdk "github.com/cosmos/cosmos-sdk/types" "google.golang.org/grpc/codes" @@ -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 }