Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion cmd/network/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

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?

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the name is empty, would this produce name " (from oasiscan)"?

}
}

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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())
Expand All @@ -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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use "", as one could have an entity with name unknown.

}

output = append(output, []string{
name,
node.EntityID.String(),
member.PublicKey.String(),
member.Role.String(),
Expand Down
Loading