Add a command to get naming info
This commit is contained in:
parent
9ee1f315a1
commit
5b116308eb
@ -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.
|
||||||
|
@ -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 ®istrytypes.QueryLookupCrnResponse{Name: nameRecord}, nil
|
return ®istrytypes.QueryLookupCrnResponse{Name: nameRecord}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user