Add a command to list name records

This commit is contained in:
Prathamesh Musale 2024-02-19 19:23:31 +05:30
parent 5b116308eb
commit c809f22b83
3 changed files with 25 additions and 3 deletions

View File

@ -82,8 +82,19 @@ func (k Keeper) LookupNameRecord(ctx sdk.Context, crn string) (*registrytypes.Na
}
// ListNameRecords - get all name records.
func (k Keeper) ListNameRecords(ctx sdk.Context) []registrytypes.NameEntry {
panic("unimplemented")
func (k Keeper) ListNameRecords(ctx sdk.Context) ([]registrytypes.NameEntry, error) {
var nameEntries []registrytypes.NameEntry
err := k.NameRecords.Walk(ctx, nil, func(key string, value registrytypes.NameRecord) (stop bool, err error) {
nameEntries = append(nameEntries, registrytypes.NameEntry{
Name: key,
Entry: &value,
})
return false, nil
})
return nameEntries, err
}
// SaveNameRecord - sets a name record.

View File

@ -100,7 +100,12 @@ func (qs queryServer) GetRegistryModuleBalance(c context.Context,
func (qs queryServer) NameRecords(c context.Context, _ *registrytypes.QueryNameRecordsRequest) (*registrytypes.QueryNameRecordsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
nameRecords := qs.k.ListNameRecords(ctx)
nameRecords, err := qs.k.ListNameRecords(ctx)
if err != nil {
return nil, err
}
return &registrytypes.QueryNameRecordsResponse{Names: nameRecords}, nil
}

View File

@ -51,6 +51,12 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
{ProtoField: "name"},
},
},
{
RpcMethod: "NameRecords",
Use: "names",
Short: "List name records",
PositionalArgs: []*autocliv1.PositionalArgDescriptor{},
},
{
RpcMethod: "LookupCrn",
Use: "lookup [crn]",