@@ -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,93 @@ 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+ fmt .Printf ("Node ID: %s\n " , node .String ())
89+ idQuery2 := & registry.IDQuery {
90+ Height : height ,
91+ ID : node ,
92+ }
93+
94+ nodeStatus , err := registryConn .GetNodeStatus (ctx , idQuery2 )
95+ if err != nil {
96+ fmt .Println (" Node is not active" )
97+ continue
98+ }
99+
100+ if node , err2 := registryConn .GetNode (ctx , idQuery2 ); err2 == nil {
101+ fmt .Printf (" Node Roles: %s\n " , node .Roles .String ())
102+
103+ var addrStrings []string
104+ for _ , addr := range node .P2P .Addresses {
105+ addrStrings = append (addrStrings , fmt .Sprintf ("%s:%d" , addr .IP .String (), addr .Port ))
106+ }
107+ fmtAddrs := strings .Join (addrStrings , ", " )
108+ fmt .Printf (" Node Address(es): %s\n " , fmtAddrs )
109+
110+ fmt .Printf (" Software Version: %s\n " , node .SoftwareVersion )
111+ if len (node .Runtimes ) > 0 {
112+ fmt .Printf (" Runtimes:\n " )
113+ }
114+ for _ , runtime := range node .Runtimes {
115+ fmt .Printf (" Runtime ID: %s\n " , runtime .ID )
116+ fmt .Printf (" Runtime Version: %s\n " , runtime .Version )
117+ }
118+ fmt .Printf (" Node Status:\n " )
119+ fmt .Printf (" Expiration Processed: %t\n " , nodeStatus .ExpirationProcessed )
120+ fmt .Printf (" Freeze End Time: %d\n " , nodeStatus .FreezeEndTime )
121+ fmt .Printf (" Election Eligible After: %d\n " , nodeStatus .ElectionEligibleAfter )
122+ } else {
123+ return fmt .Errorf ("could not get a node: %s" , err2 )
124+ }
125+
126+ if i < len (entity .Nodes )- 1 {
127+ fmt .Println ()
128+ }
129+ }
130+ return nil
131+ }
132+
43133var showCmd = & cobra.Command {
44134 Use : "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }" ,
45135 Short : "Show network properties" ,
@@ -63,6 +153,7 @@ var showCmd = &cobra.Command{
63153 roothashConn := conn .Consensus ().RootHash ()
64154 schedulerConn := conn .Consensus ().Scheduler ()
65155 stakingConn := conn .Consensus ().Staking ()
156+ beaconConn := conn .Consensus ().Beacon ()
66157
67158 // Figure out the height to use if "latest".
68159 height , err := common .GetActualHeight (
@@ -92,7 +183,7 @@ var showCmd = &cobra.Command{
92183 }
93184
94185 if entity , err := registryConn .GetEntity (ctx , idQuery ); err == nil {
95- err = prettyPrint ( entity )
186+ err = printEntityNodes ( ctx , npa , stakingConn , registryConn , beaconConn , entity , height )
96187 cobra .CheckErr (err )
97188 return
98189 }
@@ -125,7 +216,7 @@ var showCmd = &cobra.Command{
125216 cobra .CheckErr (err ) // If this doesn't work the other large queries won't either.
126217 for _ , entity := range entities {
127218 if staking .NewAddress (entity .ID ).Equal (addr ) {
128- err = prettyPrint ( entity )
219+ err = printEntityNodes ( ctx , npa , stakingConn , registryConn , beaconConn , entity , height )
129220 cobra .CheckErr (err )
130221 return
131222 }
0 commit comments