@@ -10,7 +10,9 @@ 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"
1517 consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1618 "github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
@@ -19,6 +21,7 @@ import (
1921 staking "github.com/oasisprotocol/oasis-core/go/staking/api"
2022 "github.com/oasisprotocol/oasis-core/go/staking/api/token"
2123 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
24+ "github.com/oasisprotocol/oasis-sdk/client-sdk/go/helpers"
2225 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"
2326
2427 "github.com/oasisprotocol/cli/cmd/common"
@@ -40,6 +43,87 @@ const (
4043 selParameters
4144)
4245
46+ func printEntityNodes (ctx context.Context , npa * common.NPASelection , 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+ var fmtBalance string
69+ if balance != nil {
70+ fmtBalance = helpers .FormatConsensusDenomination (npa .Network , * balance )
71+ } else {
72+ fmtBalance = "unknown"
73+ }
74+ fmt .Printf ("Stake: %s\n " , fmtBalance )
75+
76+ commission := account .Escrow .CommissionSchedule .CurrentRate (epoch )
77+ var commissionString string
78+ if commission != nil {
79+ commissionString = staking .PrettyPrintCommissionRatePercentage (* commission )
80+ } else {
81+ commissionString = "not set"
82+ }
83+ fmt .Printf ("Commission: %s\n " , commissionString )
84+
85+ fmt .Println ()
86+ fmt .Printf ("=== NODES ===\n " )
87+ for i , node := range entity .Nodes {
88+ nodeAddr := staking .NewAddress (node )
89+ fmt .Printf ("Node Address: %s\n " , nodeAddr .String ())
90+ fmt .Printf ("Node ID: %s\n " , node .String ())
91+ idQuery2 := & registry.IDQuery {
92+ Height : height ,
93+ ID : node ,
94+ }
95+
96+ nodeStatus , err := registryConn .GetNodeStatus (ctx , idQuery2 )
97+ if err != nil {
98+ fmt .Println (" Node is not active" )
99+ continue
100+ }
101+
102+ if node , err2 := registryConn .GetNode (ctx , idQuery2 ); err2 == nil {
103+ fmt .Printf (" Node Roles: %s\n " , node .Roles .String ())
104+ fmt .Printf (" Software Version: %s\n " , node .SoftwareVersion )
105+ if len (node .Runtimes ) > 0 {
106+ fmt .Printf (" Runtimes:\n " )
107+ }
108+ for _ , runtime := range node .Runtimes {
109+ fmt .Printf (" Runtime ID: %s\n " , runtime .ID )
110+ fmt .Printf (" Runtime Version: %s\n " , runtime .Version )
111+ }
112+ fmt .Printf (" Node Status:\n " )
113+ fmt .Printf (" Expiration Processed: %t\n " , nodeStatus .ExpirationProcessed )
114+ fmt .Printf (" Freeze End Time: %d\n " , nodeStatus .FreezeEndTime )
115+ fmt .Printf (" Election Eligible After: %d\n " , nodeStatus .ElectionEligibleAfter )
116+ } else {
117+ return fmt .Errorf ("could not get a node: %s" , err2 )
118+ }
119+
120+ if i < len (entity .Nodes )- 1 {
121+ fmt .Println ()
122+ }
123+ }
124+ return nil
125+ }
126+
43127var showCmd = & cobra.Command {
44128 Use : "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }" ,
45129 Short : "Show network properties" ,
@@ -63,6 +147,7 @@ var showCmd = &cobra.Command{
63147 roothashConn := conn .Consensus ().RootHash ()
64148 schedulerConn := conn .Consensus ().Scheduler ()
65149 stakingConn := conn .Consensus ().Staking ()
150+ beaconConn := conn .Consensus ().Beacon ()
66151
67152 // Figure out the height to use if "latest".
68153 height , err := common .GetActualHeight (
@@ -92,7 +177,7 @@ var showCmd = &cobra.Command{
92177 }
93178
94179 if entity , err := registryConn .GetEntity (ctx , idQuery ); err == nil {
95- err = prettyPrint ( entity )
180+ err = printEntityNodes ( ctx , npa , stakingConn , registryConn , beaconConn , entity , height )
96181 cobra .CheckErr (err )
97182 return
98183 }
@@ -125,7 +210,7 @@ var showCmd = &cobra.Command{
125210 cobra .CheckErr (err ) // If this doesn't work the other large queries won't either.
126211 for _ , entity := range entities {
127212 if staking .NewAddress (entity .ID ).Equal (addr ) {
128- err = prettyPrint ( entity )
213+ err = printEntityNodes ( ctx , npa , stakingConn , registryConn , beaconConn , entity , height )
129214 cobra .CheckErr (err )
130215 return
131216 }
0 commit comments