@@ -10,8 +10,11 @@ import (
1010
1111 "github.com/spf13/cobra"
1212
13+ "github.com/oasisprotocol/oasis-core/go/beacon/api"
1314 "github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
15+ "github.com/oasisprotocol/oasis-core/go/common/entity"
1416 consensusPretty "github.com/oasisprotocol/oasis-core/go/common/prettyprint"
17+ "github.com/oasisprotocol/oasis-core/go/common/quantity"
1518 consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1619 "github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
1720 registry "github.com/oasisprotocol/oasis-core/go/registry/api"
@@ -40,6 +43,77 @@ const (
4043 selParameters
4144)
4245
46+ func printEntityNodes (ctx context.Context , stakingConn staking.Backend , registryConn registry.Backend , beaconConn api.Backend , entity * entity.Entity , height int64 ) error {
47+ epoch , err := beaconConn .GetEpoch (ctx , height )
48+ if err != nil {
49+ return err
50+ }
51+
52+ fmt .Printf ("=== ENTITY ===\n " )
53+
54+ entityAddr := staking .NewAddress (entity .ID )
55+ fmt .Printf ("Entity Address: %s\n " , entityAddr .String ())
56+
57+ fmt .Printf ("Entity ID: %s\n " , entity .ID .String ())
58+
59+ account , err := stakingConn .Account (
60+ ctx ,
61+ & staking.OwnerQuery {Height : height , Owner : entityAddr },
62+ )
63+ if err != nil {
64+ return err
65+ }
66+
67+ balance := & account .Escrow .Active .Balance
68+ commission := account .Escrow .CommissionSchedule .CurrentRate (epoch )
69+
70+ q := quantity .NewFromUint64 (uint64 (1_000_000_000 ))
71+ err = balance .Quo (q )
72+ cobra .CheckErr (err )
73+
74+ fmt .Printf ("Stake: %s ROSE\n " , balance .String ())
75+ fmt .Printf ("Commission: %s%%\n " , staking .PrettyPrintCommissionRatePercentage (* commission ))
76+
77+ fmt .Println ()
78+ fmt .Printf ("=== NODES ===\n " )
79+ for i , node := range entity .Nodes {
80+ fmt .Printf ("Node ID: %s\n " , node .String ())
81+ idQuery2 := & registry.IDQuery {
82+ Height : height ,
83+ ID : node ,
84+ }
85+
86+ nodeStatus , err := registryConn .GetNodeStatus (ctx , idQuery2 )
87+ if err != nil {
88+ fmt .Println (" Node is not active" )
89+ continue
90+ }
91+
92+ if node , err2 := registryConn .GetNode (ctx , idQuery2 ); err2 == nil {
93+ fmt .Printf (" Node Roles: %s\n " , node .Roles .String ())
94+ fmt .Printf (" Software Version: %s\n " , node .SoftwareVersion )
95+ if len (node .Runtimes ) > 0 {
96+ fmt .Printf (" Runtimes:\n " )
97+ }
98+ for _ , runtime := range node .Runtimes {
99+ fmt .Printf (" Runtime ID: %s\n " , runtime .ID )
100+ fmt .Printf (" Runtime Version: %s\n " , runtime .Version )
101+ }
102+ fmt .Printf (" Node Status:\n " )
103+ fmt .Printf (" Expiration Processed: %t\n " , nodeStatus .ExpirationProcessed )
104+ fmt .Printf (" Freeze End Time: %d\n " , nodeStatus .FreezeEndTime )
105+ fmt .Printf (" Election Eligible After: %d\n " , nodeStatus .ElectionEligibleAfter )
106+ } else {
107+ return fmt .Errorf ("could not get a node: %s" , err2 )
108+ }
109+
110+ if i < len (entity .Nodes )- 1 {
111+ fmt .Println ()
112+ }
113+ }
114+ return nil
115+ }
116+
43117var showCmd = & cobra.Command {
44118 Use : "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }" ,
45119 Short : "Show network properties" ,
@@ -63,6 +137,7 @@ var showCmd = &cobra.Command{
63137 roothashConn := conn .Consensus ().RootHash ()
64138 schedulerConn := conn .Consensus ().Scheduler ()
65139 stakingConn := conn .Consensus ().Staking ()
140+ beaconConn := conn .Consensus ().Beacon ()
66141
67142 // Figure out the height to use if "latest".
68143 height , err := common .GetActualHeight (
@@ -92,7 +167,7 @@ var showCmd = &cobra.Command{
92167 }
93168
94169 if entity , err := registryConn .GetEntity (ctx , idQuery ); err == nil {
95- err = prettyPrint ( entity )
170+ err = printEntityNodes ( ctx , stakingConn , registryConn , beaconConn , entity , height )
96171 cobra .CheckErr (err )
97172 return
98173 }
@@ -125,7 +200,7 @@ var showCmd = &cobra.Command{
125200 cobra .CheckErr (err ) // If this doesn't work the other large queries won't either.
126201 for _ , entity := range entities {
127202 if staking .NewAddress (entity .ID ).Equal (addr ) {
128- err = prettyPrint ( entity )
203+ err = printEntityNodes ( ctx , stakingConn , registryConn , beaconConn , entity , height )
129204 cobra .CheckErr (err )
130205 return
131206 }
0 commit comments