Skip to content

Commit

Permalink
feat(cmd/network/status): Sort paratimes
Browse files Browse the repository at this point in the history
  • Loading branch information
amela committed Oct 23, 2024
1 parent d8e00d0 commit 4279b09
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion cmd/network/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package network
import (
"context"
"fmt"
"sort"
"strings"
"time"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

coreCommon "github.com/oasisprotocol/oasis-core/go/common"

"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"

"github.com/oasisprotocol/cli/cmd/common"
Expand Down Expand Up @@ -132,7 +135,40 @@ var (
fmt.Println("==== ParaTimes ====")
}

for _, runtime := range nodeStatus.Runtimes {
keys := make([]coreCommon.Namespace, 0, len(nodeStatus.Runtimes))
for key := range nodeStatus.Runtimes {
keys = append(keys, key)
}
sort.Slice(keys, func(i, j int) bool {
iParatimeName := "unknown"
jParatimeName := "unknown"

iDescriptor := nodeStatus.Runtimes[keys[i]].Descriptor
jDescriptor := nodeStatus.Runtimes[keys[j]].Descriptor

iDescriptorID := ""
jDescriptorID := ""

if iDescriptor != nil {
iDescriptorID = iDescriptor.ID.String()
iParatimeName = getParatimeName(cfg, iDescriptorID)
}

if jDescriptor != nil {
jDescriptorID = jDescriptor.ID.String()
jParatimeName = getParatimeName(cfg, jDescriptorID)
}

switch iParatimeName == jParatimeName {
case true:
return iDescriptorID < jDescriptorID
default:
return iParatimeName < jParatimeName
}
})

for _, key := range keys {
runtime := nodeStatus.Runtimes[key]
descriptor := runtime.Descriptor
if descriptor != nil {
paratimeName := getParatimeName(cfg, descriptor.ID.String())
Expand Down

0 comments on commit 4279b09

Please sign in to comment.