Implement query to list authorities
All checks were successful
Protobuf / lint (pull_request) Successful in 26s
Integration Tests / test-integration (pull_request) Successful in 3m10s
Build / build (pull_request) Successful in 3m23s
E2E Tests / test-e2e (pull_request) Successful in 4m51s
Unit Tests / test-unit (pull_request) Successful in 2m12s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 9m7s
SDK Tests / sdk_tests (pull_request) Successful in 9m59s
SDK Tests / sdk_tests_auctions (pull_request) Successful in 14m35s
All checks were successful
Protobuf / lint (pull_request) Successful in 26s
Integration Tests / test-integration (pull_request) Successful in 3m10s
Build / build (pull_request) Successful in 3m23s
E2E Tests / test-e2e (pull_request) Successful in 4m51s
Unit Tests / test-unit (pull_request) Successful in 2m12s
SDK Tests / sdk_tests_nameservice_expiry (pull_request) Successful in 9m7s
SDK Tests / sdk_tests (pull_request) Successful in 9m59s
SDK Tests / sdk_tests_auctions (pull_request) Successful in 14m35s
This commit is contained in:
parent
76b239fe03
commit
be3bcf9687
@ -67,20 +67,11 @@ func (k *Keeper) ExportGenesis(ctx sdk.Context) (*registry.GenesisState, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authorities, err := k.ListNameAuthorityRecords(ctx)
|
||||
authorityEntries, err := k.ListNameAuthorityRecords(ctx, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
authorityEntries := []registry.AuthorityEntry{}
|
||||
// #nosec G705
|
||||
for name, record := range authorities {
|
||||
authorityEntries = append(authorityEntries, registry.AuthorityEntry{
|
||||
Name: name,
|
||||
Entry: &record, //nolint: all
|
||||
}) // #nosec G601
|
||||
}
|
||||
|
||||
names, err := k.ListNameRecords(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -41,19 +41,30 @@ func (k Keeper) GetNameAuthority(ctx sdk.Context, name string) (registrytypes.Na
|
||||
return authority, nil
|
||||
}
|
||||
|
||||
// ListNameAuthorityRecords - get all name authority records.
|
||||
func (k Keeper) ListNameAuthorityRecords(ctx sdk.Context) (map[string]registrytypes.NameAuthority, error) {
|
||||
nameAuthorityRecords := make(map[string]registrytypes.NameAuthority)
|
||||
// ListNameAuthorityRecords - get all name authority records for given owner
|
||||
// Returns all authorities if owner set to ""
|
||||
func (k Keeper) ListNameAuthorityRecords(ctx sdk.Context, owner string) ([]registrytypes.AuthorityEntry, error) {
|
||||
authorityEntries := []registrytypes.AuthorityEntry{}
|
||||
|
||||
err := k.Authorities.Walk(ctx, nil, func(key string, value registrytypes.NameAuthority) (bool, error) {
|
||||
nameAuthorityRecords[key] = value
|
||||
// If owner is not empty, skip if authority is not owned by owner
|
||||
if owner != "" && owner != value.OwnerAddress {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
authorityEntries = append(authorityEntries, registrytypes.AuthorityEntry{
|
||||
Name: key,
|
||||
Entry: &value,
|
||||
})
|
||||
|
||||
// Continue the walk
|
||||
return false, nil
|
||||
})
|
||||
if err != nil {
|
||||
return map[string]registrytypes.NameAuthority{}, err
|
||||
return []registrytypes.AuthorityEntry{}, err
|
||||
}
|
||||
|
||||
return nameAuthorityRecords, nil
|
||||
return authorityEntries, nil
|
||||
}
|
||||
|
||||
// HasNameRecord - checks if a name record exists.
|
||||
|
@ -112,10 +112,10 @@ func (qs queryServer) NameRecords(c context.Context, _ *registrytypes.QueryNameR
|
||||
return ®istrytypes.QueryNameRecordsResponse{Names: nameRecords}, nil
|
||||
}
|
||||
|
||||
func (qs queryServer) Whois(c context.Context, request *registrytypes.QueryWhoisRequest) (*registrytypes.QueryWhoisResponse, error) {
|
||||
func (qs queryServer) Whois(c context.Context, req *registrytypes.QueryWhoisRequest) (*registrytypes.QueryWhoisResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
nameAuthority, err := qs.k.GetNameAuthority(ctx, request.GetName())
|
||||
nameAuthority, err := qs.k.GetNameAuthority(ctx, req.GetName())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -123,6 +123,17 @@ func (qs queryServer) Whois(c context.Context, request *registrytypes.QueryWhois
|
||||
return ®istrytypes.QueryWhoisResponse{NameAuthority: nameAuthority}, nil
|
||||
}
|
||||
|
||||
func (qs queryServer) Authorities(c context.Context, req *registrytypes.QueryAuthoritiesRequest) (*registrytypes.QueryAuthoritiesResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
authorityEntries, err := qs.k.ListNameAuthorityRecords(ctx, req.GetOwner())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ®istrytypes.QueryAuthoritiesResponse{Authorities: authorityEntries}, nil
|
||||
}
|
||||
|
||||
func (qs queryServer) LookupLrn(c context.Context, req *registrytypes.QueryLookupLrnRequest) (*registrytypes.QueryLookupLrnResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
lrn := req.GetLrn()
|
||||
|
@ -51,6 +51,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
|
||||
{ProtoField: "name"},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "Authorities",
|
||||
Use: "list-authorities [owner]",
|
||||
Short: "List authorities (optionally by owner)",
|
||||
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
|
||||
{ProtoField: "owner", Optional: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
RpcMethod: "NameRecords",
|
||||
Use: "names",
|
||||
|
Loading…
Reference in New Issue
Block a user