Add a command to get naming info

This commit is contained in:
Prathamesh Musale 2024-02-19 19:11:03 +05:30
parent 9ee1f315a1
commit 5b116308eb
3 changed files with 18 additions and 3 deletions

View File

@ -40,8 +40,8 @@ func (k Keeper) GetNameAuthority(ctx sdk.Context, name string) (registrytypes.Na
} }
// HasNameRecord - checks if a name record exists. // HasNameRecord - checks if a name record exists.
func (k Keeper) HasNameRecord(ctx sdk.Context, crn string) bool { func (k Keeper) HasNameRecord(ctx sdk.Context, crn string) (bool, error) {
panic("unimplemented") return k.NameRecords.Has(ctx, crn)
} }
// GetNameRecord - gets a name record from the store. // GetNameRecord - gets a name record from the store.

View File

@ -118,13 +118,20 @@ func (qs queryServer) Whois(c context.Context, request *registrytypes.QueryWhois
func (qs queryServer) LookupCrn(c context.Context, req *registrytypes.QueryLookupCrnRequest) (*registrytypes.QueryLookupCrnResponse, error) { func (qs queryServer) LookupCrn(c context.Context, req *registrytypes.QueryLookupCrnRequest) (*registrytypes.QueryLookupCrnResponse, error) {
ctx := sdk.UnwrapSDKContext(c) ctx := sdk.UnwrapSDKContext(c)
crn := req.GetCrn() crn := req.GetCrn()
if !qs.k.HasNameRecord(ctx, crn) {
crnExists, err := qs.k.HasNameRecord(ctx, crn)
if err != nil {
return nil, err
}
if !crnExists {
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.") return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.")
} }
nameRecord, _ := qs.k.LookupNameRecord(ctx, crn) nameRecord, _ := qs.k.LookupNameRecord(ctx, crn)
if nameRecord == nil { if nameRecord == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.") return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.")
} }
return &registrytypes.QueryLookupCrnResponse{Name: nameRecord}, nil return &registrytypes.QueryLookupCrnResponse{Name: nameRecord}, nil
} }

View File

@ -51,6 +51,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{ProtoField: "name"}, {ProtoField: "name"},
}, },
}, },
{
RpcMethod: "LookupCrn",
Use: "lookup [crn]",
Short: "Get naming info for CRN",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
{ProtoField: "crn"},
},
},
{ {
RpcMethod: "GetRegistryModuleBalance", RpcMethod: "GetRegistryModuleBalance",
Use: "balance", Use: "balance",