Skip to content

Commit 42fbd7a

Browse files
committed
Implement ROFL list command
1 parent 857f671 commit 42fbd7a

6 files changed

Lines changed: 213 additions & 0 deletions

File tree

cmd/rofl/list.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package rofl
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"sort"
7+
8+
"github.com/spf13/cobra"
9+
10+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
11+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
12+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
13+
14+
"github.com/oasisprotocol/cli/cmd/common"
15+
cliConfig "github.com/oasisprotocol/cli/config"
16+
"github.com/oasisprotocol/cli/table"
17+
)
18+
19+
var listCmd = &cobra.Command{
20+
Use: "list",
21+
Aliases: []string{"ls"},
22+
Short: "List ROFL applications",
23+
Long: `List all ROFL applications registered on the selected paratime.
24+
25+
This command queries on-chain ROFL application data and displays application IDs,
26+
names, and admin addresses.
27+
28+
Use --format json for machine-readable output.`,
29+
Args: cobra.NoArgs,
30+
Run: func(_ *cobra.Command, _ []string) {
31+
cfg := cliConfig.Global()
32+
npa := common.GetNPASelection(cfg)
33+
npa.MustHaveParaTime()
34+
35+
ctx := context.Background()
36+
conn, err := connection.Connect(ctx, npa.Network)
37+
cobra.CheckErr(err)
38+
39+
// Query all ROFL apps from the chain.
40+
apps, err := conn.Runtime(npa.ParaTime).ROFL.Apps(ctx, client.RoundLatest)
41+
if err != nil {
42+
cobra.CheckErr(fmt.Errorf("failed to query ROFL apps: %w", err))
43+
}
44+
45+
// Sort apps by ID for consistent output.
46+
sort.Slice(apps, func(i, j int) bool {
47+
return apps[i].ID.String() < apps[j].ID.String()
48+
})
49+
50+
// Output format handling.
51+
if common.OutputFormat() == common.FormatJSON {
52+
outputAppsJSON(apps)
53+
return
54+
}
55+
56+
if len(apps) == 0 {
57+
fmt.Println("No ROFL applications found.")
58+
return
59+
}
60+
61+
outputAppsText(apps)
62+
},
63+
}
64+
65+
// outputAppsJSON returns apps in JSON format.
66+
func outputAppsJSON(apps []*rofl.AppConfig) {
67+
output := make([]common.JSONPrettyPrintRoflAppConfig, 0, len(apps))
68+
for _, app := range apps {
69+
output = append(output, common.JSONPrettyPrintRoflAppConfig(*app))
70+
}
71+
72+
data, err := common.PrettyJSONMarshal(output)
73+
cobra.CheckErr(err)
74+
fmt.Println(string(data))
75+
}
76+
77+
// outputAppsText returns apps in human-readable table format.
78+
func outputAppsText(apps []*rofl.AppConfig) {
79+
tbl := table.New()
80+
tbl.Header("App ID", "Name", "Version", "Admin")
81+
82+
rows := make([][]string, 0, len(apps))
83+
for _, app := range apps {
84+
// Extract name from metadata.
85+
name := app.Metadata["net.oasis.rofl.name"]
86+
87+
// Extract version from metadata.
88+
version := app.Metadata["net.oasis.rofl.version"]
89+
90+
// Format admin address.
91+
var admin string
92+
if app.Admin != nil {
93+
admin = app.Admin.String()
94+
}
95+
96+
rows = append(rows, []string{
97+
app.ID.String(),
98+
name,
99+
version,
100+
admin,
101+
})
102+
}
103+
104+
cobra.CheckErr(tbl.Bulk(rows))
105+
cobra.CheckErr(tbl.Render())
106+
}
107+
108+
func init() {
109+
common.AddSelectorNPFlags(listCmd)
110+
listCmd.Flags().AddFlagSet(common.FormatFlag)
111+
}

cmd/rofl/rofl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func init() {
2222
Cmd.AddCommand(pushCmd)
2323
Cmd.AddCommand(removeCmd)
2424
Cmd.AddCommand(showCmd)
25+
Cmd.AddCommand(listCmd)
2526
Cmd.AddCommand(trustRootCmd)
2627
Cmd.AddCommand(build.Cmd)
2728
Cmd.AddCommand(identityCmd)

examples/rofl/list-json.in.static

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis rofl list --format json

examples/rofl/list-json.out.static

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
[
2+
{
3+
"id": "rofl1qp08ps63uhs7t6mwvs66ret63m6jem7a85npn8rz",
4+
"policy": {
5+
"quotes": {
6+
"pcs": {
7+
"tcb_validity_period": 30,
8+
"min_tcb_evaluation_data_number": 18,
9+
"tdx": {}
10+
}
11+
},
12+
"enclaves": [],
13+
"endorsements": [
14+
{
15+
"any": {}
16+
}
17+
],
18+
"fees": 2,
19+
"max_expiration": 3
20+
},
21+
"admin": "oasis1qqy0z5h4ff2f59je3462kqc2kdszljgyssm42tfd",
22+
"stake": {
23+
"Amount": "100000000000000000000",
24+
"Denomination": ""
25+
},
26+
"metadata": {
27+
"net.oasis.rofl.name": "tgbotforAuctionx",
28+
"net.oasis.rofl.version": "0.1.0"
29+
},
30+
"sek": "k56wl/QOQe7Hx+Gx/Gl9CTzTUNnKk9y1wEuVaRYF5CU="
31+
},
32+
{
33+
"id": "rofl1qp0d82k8jf2xt4jp6eq4psmsmm532pdgqctzm3s0",
34+
"policy": {
35+
"quotes": {
36+
"pcs": {
37+
"tcb_validity_period": 30,
38+
"min_tcb_evaluation_data_number": 18,
39+
"tdx": {}
40+
}
41+
},
42+
"enclaves": [
43+
"yKPITijRyjYPs7W2ekQ3u9w+alnXyQy7wwyTnw5umMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
44+
"2ot6nXp4WekANt3AN4jJqaCfC4D2bDs1FbeKO1AyRI8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="
45+
],
46+
"endorsements": [
47+
{
48+
"any": {}
49+
}
50+
],
51+
"fees": 2,
52+
"max_expiration": 3
53+
},
54+
"admin": "oasis1qpsmn7u78k9gm6jyra6zm2lu0n949pztgqpxss4n",
55+
"stake": {
56+
"Amount": "100000000000000000000",
57+
"Denomination": ""
58+
},
59+
"metadata": {
60+
"net.oasis.rofl.name": "rofl-port-check2",
61+
"net.oasis.rofl.version": "0.1.0"
62+
},
63+
"sek": "h6mkA1errPLtxk0kY+9QQNJ2t+YsTPPGJTCiIWbcNxM="
64+
},
65+
{
66+
"id": "rofl1qq36f7xn7cphzclevyyrnnh4e4rnvkv3fsaxx0hd",
67+
"policy": {
68+
"quotes": {
69+
"pcs": {
70+
"tcb_validity_period": 30,
71+
"min_tcb_evaluation_data_number": 17,
72+
"tdx": {}
73+
}
74+
},
75+
"enclaves": [],
76+
"endorsements": [
77+
{
78+
"any": {}
79+
}
80+
],
81+
"fees": 2,
82+
"max_expiration": 3
83+
},
84+
"admin": "oasis1qqzrmkwkgc68p048hrjm6dsp34mkklvu85kj4x7r",
85+
"stake": {
86+
"Amount": "100000000000000000000",
87+
"Denomination": ""
88+
},
89+
"sek": "WmTpBU0AtdT97lqFA50CobqggK5lsPNQCoiJjv16IT4="
90+
}
91+
]

examples/rofl/list.in.static

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis rofl list

examples/rofl/list.out.static

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
APP ID NAME VERSION ADMIN
2+
rofl1qp08ps63uhs7t6mwvs66ret63m6jem7a85npn8rz tgbotforAuctionx 0.1.0 oasis1qqy0z5h4ff2f59je3462kqc2kdszljgyssm42tfd
3+
rofl1qp0d82k8jf2xt4jp6eq4psmsmm532pdgqctzm3s0 rofl-port-check2 0.1.0 oasis1qpsmn7u78k9gm6jyra6zm2lu0n949pztgqpxss4n
4+
rofl1qp0yy4s53y755dw4vkey4rxr433cr4c2857nxsrk number-pusher 0.1.0 oasis1qqwzg0n2rr6zxh226wwvc5x5uklwhkl68qufn6kr
5+
rofl1qp222jk93w34n5njc804z6rajad8lhc3xy3fu2w9 rofl-demo 0.1.0 oasis1qpfv6tuewmtxcwvx563pc6u6lhn7zjsq0glh9yyx
6+
rofl1qq36f7xn7cphzclevyyrnnh4e4rnvkv3fsaxx0hd oasis1qqzrmkwkgc68p048hrjm6dsp34mkklvu85kj4x7r
7+
rofl1qq8pufpjy0anp8rrz60sld3al5vdxep6uyvz8x79 oasis1qzlg0du255xz5c987c2g8nnvquew9a3d6c4zpw3u
8+
rofl1qq9m6uynq93zatx3gpeyr8r3dx0wvc6n9yllfhhk oasis1qzprctyyjqxp4j76kmgldh4atatpg8lyq55309k0

0 commit comments

Comments
 (0)