forked from TrueCloudLab/neoneo-go
cli/query: add height command
This commit is contained in:
parent
7366d45985
commit
8b0dfe135f
3 changed files with 50 additions and 0 deletions
|
@ -48,6 +48,12 @@ func NewCommands() []cli.Command {
|
|||
Action: queryCommittee,
|
||||
Flags: options.RPC,
|
||||
},
|
||||
{
|
||||
Name: "height",
|
||||
Usage: "Get node height",
|
||||
Action: queryHeight,
|
||||
Flags: options.RPC,
|
||||
},
|
||||
{
|
||||
Name: "tx",
|
||||
Usage: "Query transaction status",
|
||||
|
@ -201,6 +207,33 @@ func queryCommittee(ctx *cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func queryHeight(ctx *cli.Context) error {
|
||||
var err error
|
||||
|
||||
gctx, cancel := options.GetTimeoutContext(ctx)
|
||||
defer cancel()
|
||||
|
||||
c, err := options.GetRPCClient(gctx, ctx)
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
|
||||
blockCount, err := c.GetBlockCount()
|
||||
if err != nil {
|
||||
return cli.NewExitError(err, 1)
|
||||
}
|
||||
blockHeight := blockCount - 1 // GetBlockCount returns block count (including 0), not the highest block index.
|
||||
|
||||
fmt.Fprintf(ctx.App.Writer, "Latest block: %d\n", blockHeight)
|
||||
|
||||
stateHeight, err := c.GetStateHeight()
|
||||
if err == nil { // We can be talking to a node without getstateheight request support.
|
||||
fmt.Fprintf(ctx.App.Writer, "Validated state: %d\n", stateHeight.Validated)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func queryVoter(ctx *cli.Context) error {
|
||||
args := ctx.Args()
|
||||
if len(args) == 0 {
|
||||
|
|
|
@ -130,3 +130,12 @@ func (e *executor) compareQueryTxVerbose(t *testing.T, tx *transaction.Transacti
|
|||
}
|
||||
e.checkEOF(t)
|
||||
}
|
||||
|
||||
func TestQueryHeight(t *testing.T) {
|
||||
e := newExecutor(t, true)
|
||||
|
||||
e.Run(t, "neo-go", "query", "height", "--rpc-endpoint", "http://"+e.RPC.Addr)
|
||||
e.checkNextLine(t, `^Latest block: [0-9]+$`)
|
||||
e.checkNextLine(t, `^Validated state: [0-9]+$`)
|
||||
e.checkEOF(t)
|
||||
}
|
||||
|
|
|
@ -466,6 +466,14 @@ You can also vote for candidates if you own NEO:
|
|||
|
||||
### Getting data from chain
|
||||
|
||||
#### Node height/validated height
|
||||
`query height` returns the latest block and validated state height:
|
||||
```
|
||||
$ ./bin/neo-go query height -r http://localhost:20332
|
||||
Latest block: 11926
|
||||
Validated state: 11926
|
||||
```
|
||||
|
||||
#### Transaction status
|
||||
`query tx` provides convenient wrapper over RPC calls to query transaction status.
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue