Skip to content

Commit 400e6bc

Browse files
authored
Merge pull request #533 from oasisprotocol/amela/add-info-to-network-show-id
feat(cmd/network): Add nodes info to network show { <id> | entities }
2 parents e86381a + bc12def commit 400e6bc

5 files changed

Lines changed: 105 additions & 11 deletions

File tree

cmd/network/show.go

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
43127
var 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
}

docs/network.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ The provided ID can be one of the following:
410410
- If the entity ID is provided, Oasis CLI shows information on the entity and
411411
its corresponding nodes in the network registry. For example:
412412

413-
![code shell](../examples/network-show/id-entity.in)
413+
![code shell](../examples/network-show/id-entity.in.static)
414414

415-
![code json](../examples/network-show/id-entity.out)
415+
![code json](../examples/network-show/id-entity.out.static)
416416

417417
- If the node ID is provided, Oasis CLI shows detailed information of the node
418418
such as the Oasis Core software version, the node's role, supported
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis network show xQN6ffLSdc51EfEQ2BzltK1iWYAw6Y1CkBAbFzlhhEQ=

examples/network-show/id-entity.out

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== ENTITY ===
2+
Entity Address: oasis1qzp84num6xgspdst65yv7yqegln6ndcxmuuq8s9w
3+
Entity ID: xQN6ffLSdc51EfEQ2BzltK1iWYAw6Y1CkBAbFzlhhEQ=
4+
Stake: 11504987.432765658 ROSE
5+
Commission: 20.0%
6+
7+
=== NODES ===
8+
Node Address: oasis1qqzjrsadvr2q5qq5ev6xyspjses8cjxxdcrth0g7
9+
Node ID: Kb6opWKGbJHL0LK2Lto+m5ROIAXLhIr1lxQz0/kAOUM=
10+
Node Roles: validator
11+
Software Version: 24.1
12+
Node Status:
13+
Expiration Processed: false
14+
Freeze End Time: 0
15+
Election Eligible After: 38659

0 commit comments

Comments
 (0)