Skip to content

Commit

Permalink
feat(cmd/paratime/list): Add column DENOMINATION(S)
Browse files Browse the repository at this point in the history
  • Loading branch information
amela committed May 16, 2024
1 parent ac59a9d commit daf6177
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
26 changes: 25 additions & 1 deletion cmd/paratime/list.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package paratime

import (
"fmt"
"slices"
"sort"
"strings"

"github.com/spf13/cobra"

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

"github.com/oasisprotocol/cli/cmd/common"
cliConfig "github.com/oasisprotocol/cli/config"
"github.com/oasisprotocol/cli/table"
Expand All @@ -18,7 +23,7 @@ var listCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg := cliConfig.Global()
table := table.New()
table.SetHeader([]string{"Network", "Paratime", "ID"})
table.SetHeader([]string{"Network", "Paratime", "ID", "Denomination(s)"})

var output [][]string
for netName, net := range cfg.Networks.All {
Expand All @@ -32,6 +37,7 @@ var listCmd = &cobra.Command{
netName,
displayPtName,
pt.ID,
formatDenominations(pt.Denominations),
})
}
}
Expand All @@ -48,3 +54,21 @@ var listCmd = &cobra.Command{
table.Render()
},
}

func formatDenominations(denominations map[string]*config.DenominationInfo) string {
var (

Check failure on line 59 in cmd/paratime/list.go

View workflow job for this annotation

GitHub Actions / lint

Consider pre-allocating `fmtDenomArray` (prealloc)
fmtDenomArray []string
fmtDenom string
)
for nativeKey, denom := range denominations {
if nativeKey == config.NativeDenominationKey {
fmtDenom = fmt.Sprintf("%s[%d] (*)", denom.Symbol, denom.Decimals)
} else {
fmtDenom = fmt.Sprintf("%s[%d]", denom.Symbol, denom.Decimals)
}

fmtDenomArray = append(fmtDenomArray, fmtDenom)
}
slices.Sort(fmtDenomArray)
return strings.Join(fmtDenomArray, "\n")
}
19 changes: 10 additions & 9 deletions examples/paratime-remove/00-list.out
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
NETWORK PARATIME ID
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb
mainnet emerald (*) 000000000000000000000000000000000000000000000000e2eaa99fc008f87f
mainnet sapphire 000000000000000000000000000000000000000000000000f80306c9858e7279
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000
testnet emerald (*) 00000000000000000000000000000000000000000000000072c8215e60d5bca7
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c
testnet sapphire2 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6d
NETWORK PARATIME ID DENOMINATION(S)
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb ROSE[9] (*)
mainnet emerald (*) 000000000000000000000000000000000000000000000000e2eaa99fc008f87f ROSE[18] (*)
mainnet sapphire 000000000000000000000000000000000000000000000000f80306c9858e7279 ROSE[18] (*)
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000 TEST[9] (*)
testnet emerald (*) 00000000000000000000000000000000000000000000000072c8215e60d5bca7 TEST[18] (*)
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421 EUROe[18] (*)
TEST[18]
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c TEST[18] (*)
testnet sapphire2 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6d TEST[18] (*)
17 changes: 9 additions & 8 deletions examples/paratime-remove/02-list.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
NETWORK PARATIME ID
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb
mainnet emerald (*) 000000000000000000000000000000000000000000000000e2eaa99fc008f87f
mainnet sapphire 000000000000000000000000000000000000000000000000f80306c9858e7279
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000
testnet emerald (*) 00000000000000000000000000000000000000000000000072c8215e60d5bca7
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c
NETWORK PARATIME ID DENOMINATION(S)
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb ROSE[9] (*)
mainnet emerald (*) 000000000000000000000000000000000000000000000000e2eaa99fc008f87f ROSE[18] (*)
mainnet sapphire 000000000000000000000000000000000000000000000000f80306c9858e7279 ROSE[18] (*)
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000 TEST[9] (*)
testnet emerald (*) 00000000000000000000000000000000000000000000000072c8215e60d5bca7 TEST[18] (*)
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421 EUROe[18] (*)
TEST[18]
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c TEST[18] (*)
17 changes: 9 additions & 8 deletions examples/paratime/00-list.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
NETWORK PARATIME ID
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb
mainnet emerald 000000000000000000000000000000000000000000000000e2eaa99fc008f87f
mainnet sapphire (*) 000000000000000000000000000000000000000000000000f80306c9858e7279
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000
testnet emerald 00000000000000000000000000000000000000000000000072c8215e60d5bca7
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421
testnet sapphire (*) 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c
NETWORK PARATIME ID DENOMINATION(S)
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb ROSE[9] (*)
mainnet emerald 000000000000000000000000000000000000000000000000e2eaa99fc008f87f ROSE[18] (*)
mainnet sapphire (*) 000000000000000000000000000000000000000000000000f80306c9858e7279 ROSE[18] (*)
testnet cipher 0000000000000000000000000000000000000000000000000000000000000000 TEST[9] (*)
testnet emerald 00000000000000000000000000000000000000000000000072c8215e60d5bca7 TEST[18] (*)
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421 EUROe[18] (*)
TEST[18]
testnet sapphire (*) 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c TEST[18] (*)
17 changes: 9 additions & 8 deletions examples/paratime/02-list.out
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
NETWORK PARATIME ID
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb
mainnet emerald 000000000000000000000000000000000000000000000000e2eaa99fc008f87f
mainnet sapphire (*) 000000000000000000000000000000000000000000000000f80306c9858e7279
testnet cipher (*) 0000000000000000000000000000000000000000000000000000000000000000
testnet emerald 00000000000000000000000000000000000000000000000072c8215e60d5bca7
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c
NETWORK PARATIME ID DENOMINATION(S)
mainnet cipher 000000000000000000000000000000000000000000000000e199119c992377cb ROSE[9] (*)
mainnet emerald 000000000000000000000000000000000000000000000000e2eaa99fc008f87f ROSE[18] (*)
mainnet sapphire (*) 000000000000000000000000000000000000000000000000f80306c9858e7279 ROSE[18] (*)
testnet cipher (*) 0000000000000000000000000000000000000000000000000000000000000000 TEST[9] (*)
testnet emerald 00000000000000000000000000000000000000000000000072c8215e60d5bca7 TEST[18] (*)
testnet pontusx 0000000000000000000000000000000000000000000000004febe52eb412b421 EUROe[18] (*)
TEST[18]
testnet sapphire 000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c TEST[18] (*)

0 comments on commit daf6177

Please sign in to comment.