Skip to content

Commit f3bc7d6

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

6 files changed

Lines changed: 116 additions & 23 deletions

File tree

cmd/account/show/show.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var (
5454
c, err := connection.Connect(ctx, npa.Network)
5555
cobra.CheckErr(err)
5656

57-
addr, _, err := common.ResolveLocalAccountOrAddress(npa.Network, targetAddress)
57+
nativeAddr, ethAddr, err := common.ResolveLocalAccountOrAddress(npa.Network, targetAddress)
5858
cobra.CheckErr(err)
5959

6060
height, err := common.GetActualHeight(
@@ -64,7 +64,7 @@ var (
6464
cobra.CheckErr(err)
6565

6666
ownerQuery := &staking.OwnerQuery{
67-
Owner: addr.ConsensusAddress(),
67+
Owner: nativeAddr.ConsensusAddress(),
6868
Height: height,
6969
}
7070

@@ -74,7 +74,15 @@ var (
7474
consensusAccount, err := c.Consensus().Staking().Account(ctx, ownerQuery)
7575
cobra.CheckErr(err)
7676

77-
fmt.Printf("Address: %s\n", addr)
77+
78+
// TODO name
79+
// fmt.Printf("Name: %s\n", name)
80+
81+
if ethAddr != nil {
82+
fmt.Printf("Ethereum Address: %s\n", ethAddr)
83+
}
84+
85+
fmt.Printf("Native Address: %s\n", nativeAddr)
7886
fmt.Println()
7987
fmt.Printf("=== CONSENSUS LAYER (%s) ===\n", npa.NetworkName)
8088
fmt.Printf(" Nonce: %d\n", consensusAccount.General.Nonce)
@@ -93,7 +101,7 @@ var (
93101

94102
prettyPrintAccountBalanceAndDelegationsFrom(
95103
npa.Network,
96-
addr,
104+
nativeAddr,
97105
consensusAccount.General,
98106
outgoingDelegations,
99107
outgoingDebondingDelegations,
@@ -105,7 +113,7 @@ var (
105113
fmt.Println(" Allowances for this Account:")
106114
prettyPrintAllowances(
107115
npa.Network,
108-
addr,
116+
nativeAddr,
109117
consensusAccount.General.Allowances,
110118
" ",
111119
os.Stdout,
@@ -123,7 +131,7 @@ var (
123131
fmt.Println(" Active Delegations to this Account:")
124132
prettyPrintDelegationsTo(
125133
npa.Network,
126-
addr,
134+
nativeAddr,
127135
consensusAccount.Escrow.Active,
128136
incomingDelegations,
129137
" ",
@@ -135,7 +143,7 @@ var (
135143
fmt.Println(" Debonding Delegations to this Account:")
136144
prettyPrintDelegationsTo(
137145
npa.Network,
138-
addr,
146+
nativeAddr,
139147
consensusAccount.Escrow.Debonding,
140148
incomingDebondingDelegations,
141149
" ",
@@ -177,7 +185,7 @@ var (
177185
}
178186

179187
// Query runtime account when a ParaTime has been configured.
180-
rtBalances, err := c.Runtime(npa.ParaTime).Accounts.Balances(ctx, round, *addr)
188+
rtBalances, err := c.Runtime(npa.ParaTime).Accounts.Balances(ctx, round, *nativeAddr)
181189
cobra.CheckErr(err)
182190

183191
var hasNonZeroBalance bool
@@ -187,7 +195,7 @@ var (
187195
}
188196
}
189197

190-
nonce, err := c.Runtime(npa.ParaTime).Accounts.Nonce(ctx, round, *addr)
198+
nonce, err := c.Runtime(npa.ParaTime).Accounts.Nonce(ctx, round, *nativeAddr)
191199
cobra.CheckErr(err)
192200
hasNonZeroNonce := nonce > 0
193201

@@ -214,17 +222,17 @@ var (
214222
ctx,
215223
round,
216224
&consensusaccounts.DelegationsQuery{
217-
From: *addr,
225+
From: *nativeAddr,
218226
},
219227
)
220228
rtUndelegations, _ := c.Runtime(npa.ParaTime).ConsensusAccounts.Undelegations(
221229
ctx,
222230
round,
223231
&consensusaccounts.UndelegationsQuery{
224-
To: *addr,
232+
To: *nativeAddr,
225233
},
226234
)
227-
prettyPrintParaTimeDelegations(ctx, c, height, npa, addr, rtDelegations, rtUndelegations, " ", os.Stdout)
235+
prettyPrintParaTimeDelegations(ctx, c, height, npa, nativeAddr, rtDelegations, rtUndelegations, " ", os.Stdout)
228236
}
229237
}
230238
}

cmd/network/show.go

Lines changed: 79 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"
@@ -40,6 +42,80 @@ const (
4042
selParameters
4143
)
4244

45+
func printEntityNodes(ctx context.Context, npa *common.NPASelection, stakingConn staking.Backend, registryConn registry.Backend, beaconConn api.Backend, entity *entity.Entity, height int64) error {
46+
epoch, err := beaconConn.GetEpoch(ctx, height)
47+
if err != nil {
48+
return err
49+
}
50+
51+
fmt.Printf("=== ENTITY ===\n")
52+
53+
entityAddr := staking.NewAddress(entity.ID)
54+
fmt.Printf("Entity Address: %s\n", entityAddr.String())
55+
56+
fmt.Printf("Entity ID: %s\n", entity.ID.String())
57+
58+
account, err := stakingConn.Account(
59+
ctx,
60+
&staking.OwnerQuery{Height: height, Owner: entityAddr},
61+
)
62+
if err != nil {
63+
return err
64+
}
65+
66+
balance := &account.Escrow.Active.Balance
67+
commission := account.Escrow.CommissionSchedule.CurrentRate(epoch)
68+
69+
fmt.Printf("Stake: %s %s\n", consensusPretty.QuantityFrac(*balance, uint8(9)), npa.Network.Denomination.Symbol)
70+
71+
var commissionString string
72+
if commission != nil {
73+
commissionString = staking.PrettyPrintCommissionRatePercentage(*commission)
74+
} else {
75+
commissionString = "not set"
76+
}
77+
fmt.Printf("Commission: %s\n", commissionString)
78+
79+
fmt.Println()
80+
fmt.Printf("=== NODES ===\n")
81+
for i, node := range entity.Nodes {
82+
fmt.Printf("Node ID: %s\n", node.String())
83+
idQuery2 := &registry.IDQuery{
84+
Height: height,
85+
ID: node,
86+
}
87+
88+
nodeStatus, err := registryConn.GetNodeStatus(ctx, idQuery2)
89+
if err != nil {
90+
fmt.Println(" Node is not active")
91+
continue
92+
}
93+
94+
if node, err2 := registryConn.GetNode(ctx, idQuery2); err2 == nil {
95+
fmt.Printf(" Node Roles: %s\n", node.Roles.String())
96+
fmt.Printf(" Software Version: %s\n", node.SoftwareVersion)
97+
if len(node.Runtimes) > 0 {
98+
fmt.Printf(" Runtimes:\n")
99+
}
100+
for _, runtime := range node.Runtimes {
101+
fmt.Printf(" Runtime ID: %s\n", runtime.ID)
102+
fmt.Printf(" Runtime Version: %s\n", runtime.Version)
103+
}
104+
fmt.Printf(" Node Status:\n")
105+
fmt.Printf(" Expiration Processed: %t\n", nodeStatus.ExpirationProcessed)
106+
fmt.Printf(" Freeze End Time: %d\n", nodeStatus.FreezeEndTime)
107+
fmt.Printf(" Election Eligible After: %d\n", nodeStatus.ElectionEligibleAfter)
108+
} else {
109+
return fmt.Errorf("could not get a node: %s", err2)
110+
}
111+
112+
if i < len(entity.Nodes)-1 {
113+
fmt.Println()
114+
}
115+
}
116+
return nil
117+
}
118+
43119
var showCmd = &cobra.Command{
44120
Use: "show { <id> | committees | entities | gas-costs | native-token | nodes | parameters | paratimes | validators }",
45121
Short: "Show network properties",
@@ -63,6 +139,7 @@ var showCmd = &cobra.Command{
63139
roothashConn := conn.Consensus().RootHash()
64140
schedulerConn := conn.Consensus().Scheduler()
65141
stakingConn := conn.Consensus().Staking()
142+
beaconConn := conn.Consensus().Beacon()
66143

67144
// Figure out the height to use if "latest".
68145
height, err := common.GetActualHeight(
@@ -92,7 +169,7 @@ var showCmd = &cobra.Command{
92169
}
93170

94171
if entity, err := registryConn.GetEntity(ctx, idQuery); err == nil {
95-
err = prettyPrint(entity)
172+
err = printEntityNodes(ctx, npa, stakingConn, registryConn, beaconConn, entity, height)
96173
cobra.CheckErr(err)
97174
return
98175
}
@@ -125,7 +202,7 @@ var showCmd = &cobra.Command{
125202
cobra.CheckErr(err) // If this doesn't work the other large queries won't either.
126203
for _, entity := range entities {
127204
if staking.NewAddress(entity.ID).Equal(addr) {
128-
err = prettyPrint(entity)
205+
err = printEntityNodes(ctx, npa, stakingConn, registryConn, beaconConn, entity, height)
129206
cobra.CheckErr(err)
130207
return
131208
}

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== ENTITY ===
2+
Entity Address: oasis1qzp84num6xgspdst65yv7yqegln6ndcxmuuq8s9w
3+
Entity ID: xQN6ffLSdc51EfEQ2BzltK1iWYAw6Y1CkBAbFzlhhEQ=
4+
Stake: 11601040.379679788 ROSE
5+
Commission: 20.0%
6+
7+
=== NODES ===
8+
Node ID: Kb6opWKGbJHL0LK2Lto+m5ROIAXLhIr1lxQz0/kAOUM=
9+
Node Roles: validator
10+
Software Version: 24.1
11+
Node Status:
12+
Expiration Processed: false
13+
Freeze End Time: 0
14+
Election Eligible After: 38659

0 commit comments

Comments
 (0)