From c809f22b83e1e0f8d5b971d7ebedba8a2272bf8d Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 19 Feb 2024 19:23:31 +0530 Subject: [PATCH] Add a command to list name records --- x/registry/keeper/naming_keeper.go | 15 +++++++++++++-- x/registry/keeper/query_server.go | 7 ++++++- x/registry/module/autocli.go | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/x/registry/keeper/naming_keeper.go b/x/registry/keeper/naming_keeper.go index 1f2e032c..2a19f3af 100644 --- a/x/registry/keeper/naming_keeper.go +++ b/x/registry/keeper/naming_keeper.go @@ -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. diff --git a/x/registry/keeper/query_server.go b/x/registry/keeper/query_server.go index c242fafd..1f935031 100644 --- a/x/registry/keeper/query_server.go +++ b/x/registry/keeper/query_server.go @@ -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 ®istrytypes.QueryNameRecordsResponse{Names: nameRecords}, nil } diff --git a/x/registry/module/autocli.go b/x/registry/module/autocli.go index 1419565f..45b76af1 100644 --- a/x/registry/module/autocli.go +++ b/x/registry/module/autocli.go @@ -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]",