-
Notifications
You must be signed in to change notification settings - Fork 21
cmd/network/show: Print entity name #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import ( | |
|
|
||
| "github.com/oasisprotocol/cli/cmd/common" | ||
| cliConfig "github.com/oasisprotocol/cli/config" | ||
| "github.com/oasisprotocol/cli/metadata" | ||
| "github.com/oasisprotocol/cli/table" | ||
| ) | ||
|
|
||
|
|
@@ -306,12 +307,40 @@ var showCmd = &cobra.Command{ | |
| }) | ||
| cobra.CheckErr(err) | ||
|
|
||
| // Build a lookup map from entity ID to entity name. | ||
| fromRegistry, err := metadata.EntitiesFromRegistry(ctx) | ||
| if err != nil { | ||
| common.Warnf("Warning: failed to query metadata registry: %v\n", err) | ||
| } | ||
| fromOasisscan, err := metadata.EntitiesFromOasisscan(ctx) | ||
| if err != nil { | ||
| common.Warnf("Warning: failed to query oasisscan: %v\n", err) | ||
| } | ||
| entityNameByID := make(map[string]string) | ||
| for _, src := range []struct { | ||
| m *map[types.Address]*metadata.Entity | ||
| suffix string | ||
| }{ | ||
| {&fromRegistry, ""}, | ||
| {&fromOasisscan, " (from oasisscan)"}, | ||
| } { | ||
| if src.m == nil || *src.m == nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm ... 🤔 // Build a lookup map from entity ID to entity name.
fromRegistry, err := metadata.EntitiesFromRegistry(ctx)
if err != nil {
common.Warnf("Warning: failed to query metadata registry: %v\n", err)
}
fromOasisscan, err := metadata.EntitiesFromOasisscan(ctx)
if err != nil {
common.Warnf("Warning: failed to query oasisscan: %v\n", err)
}
entityNameByID := make(map[string]string)
for _, src := range []struct {
m map[types.Address]*metadata.Entity
suffix string
}{
{fromRegistry, ""},
{fromOasisscan, " (oasisscan)"},
} {
for _, ent := range src.m {
id := ent.ID.String()
if _, ok := entityNameByID[id]; ok {
continue
}
entityNameByID[id] = ent.Name + src.suffix
}
} |
||
| continue | ||
| } | ||
| for _, ent := range *src.m { | ||
| if _, exists := entityNameByID[ent.ID.String()]; exists { | ||
| continue | ||
| } | ||
| entityNameByID[ent.ID.String()] = ent.Name + src.suffix | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the name is empty, would this produce name |
||
| } | ||
| } | ||
|
|
||
| for _, runtime := range runtimes { | ||
| if runtime.Kind != registry.KindCompute { | ||
| continue | ||
| } | ||
| table := table.New() | ||
| table.Header("Entity ID", "Node ID", "Role") | ||
| table.Header("Entity Name", "Entity ID", "Node ID", "Role") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the entity name is not to be trusted and can be empty, I would not put it in the first column. |
||
|
|
||
| runtimeID := runtime.ID | ||
| paratimeName := getParatimeName(cfg, runtimeID.String()) | ||
|
|
@@ -337,7 +366,13 @@ var showCmd = &cobra.Command{ | |
| node, err := registryConn.GetNode(ctx, nodeQuery) | ||
| cobra.CheckErr(err) | ||
|
|
||
| name := entityNameByID[node.EntityID.String()] | ||
| if name == "" { | ||
| name = "unknown" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just use |
||
| } | ||
|
|
||
| output = append(output, []string{ | ||
| name, | ||
| node.EntityID.String(), | ||
| member.PublicKey.String(), | ||
| member.Role.String(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need data also from Oasis scan?