Skip to content

Commit 742092d

Browse files
committed
feat(cmd/network): Add nodes info to network show { <id> | entities }
1 parent c476181 commit 742092d

4 files changed

Lines changed: 88 additions & 9 deletions

File tree

cmd/network/show.go

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,70 @@ const (
4043
selParameters
4144
)
4245

46+
func printEntityNodes(ctx context.Context, stake 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 Addr: %s\n", entityAddr.String())
56+
57+
fmt.Printf("Entity ID: %s\n", entity.ID.String())
58+
59+
account, err := stake.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", commission.String())
76+
77+
fmt.Println()
78+
fmt.Printf("=== NODES ===\n")
79+
for _, 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+
if nodeStatus, err := registryConn.GetNodeStatus(ctx, idQuery2); err == nil {
87+
if node, err2 := registryConn.GetNode(ctx, idQuery2); err2 == nil {
88+
fmt.Printf(" Node Roles: %s\n", node.Roles.String())
89+
fmt.Printf(" Oasis Core: %s\n", node.SoftwareVersion)
90+
fmt.Printf(" Runtimes:\n")
91+
for _, runtime := range node.Runtimes {
92+
fmt.Printf(" Runtime ID: %s\n", runtime.ID)
93+
fmt.Printf(" Runtime Version: %s\n", runtime.Version)
94+
}
95+
fmt.Printf(" Node Status:\n")
96+
fmt.Printf(" Expiration Processed: %t\n", nodeStatus.ExpirationProcessed)
97+
fmt.Printf(" Freeze End Time: %d\n", nodeStatus.FreezeEndTime)
98+
fmt.Printf(" Election Eligible After: %d\n", nodeStatus.ElectionEligibleAfter)
99+
} else {
100+
return fmt.Errorf("could not get a node: %s", err2)
101+
}
102+
} else {
103+
fmt.Println(" Node is not active")
104+
}
105+
fmt.Println()
106+
}
107+
return nil
108+
}
109+
43110
var showCmd = &cobra.Command{
44111
Use: "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }",
45112
Short: "Show network properties",
@@ -63,6 +130,9 @@ var showCmd = &cobra.Command{
63130
roothashConn := conn.Consensus().RootHash()
64131
schedulerConn := conn.Consensus().Scheduler()
65132
stakingConn := conn.Consensus().Staking()
133+
beaconConn := conn.Consensus().Beacon()
134+
135+
stake := conn.Consensus().Staking()
66136

67137
// Figure out the height to use if "latest".
68138
height, err := common.GetActualHeight(
@@ -92,7 +162,7 @@ var showCmd = &cobra.Command{
92162
}
93163

94164
if entity, err := registryConn.GetEntity(ctx, idQuery); err == nil {
95-
err = prettyPrint(entity)
165+
err = printEntityNodes(ctx, stake, registryConn, beaconConn, entity, height)
96166
cobra.CheckErr(err)
97167
return
98168
}
@@ -125,7 +195,7 @@ var showCmd = &cobra.Command{
125195
cobra.CheckErr(err) // If this doesn't work the other large queries won't either.
126196
for _, entity := range entities {
127197
if staking.NewAddress(entity.ID).Equal(addr) {
128-
err = prettyPrint(entity)
198+
err = printEntityNodes(ctx, stake, registryConn, beaconConn, entity, height)
129199
cobra.CheckErr(err)
130200
return
131201
}

examples/network-show/id-entity.out

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

0 commit comments

Comments
 (0)