Additional registry module commands #6

Merged
ashwin merged 13 commits from pm-additional-commands into main 2024-02-26 05:42:38 +00:00
3 changed files with 25 additions and 3 deletions
Showing only changes of commit c809f22b83 - Show all commits

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]",