mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 03:47:18 +00:00
cli: support WS client for query height
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
5566e354d4
commit
36bf30a03a
1 changed files with 22 additions and 1 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/neo"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -249,7 +250,27 @@ func queryHeight(ctx *cli.Context) error {
|
||||||
gctx, cancel := options.GetTimeoutContext(ctx)
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, err := options.GetRPCClient(gctx, ctx)
|
endpoint := ctx.String(options.RPCEndpointFlag)
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return cli.NewExitError("errNoEndpoint", 1)
|
||||||
|
}
|
||||||
|
var c interface {
|
||||||
|
GetBlockCount() (uint32, error)
|
||||||
|
GetStateHeight() (*result.StateHeight, error)
|
||||||
|
Init() error
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(endpoint, "ws://") || strings.HasPrefix(endpoint, "wss://") {
|
||||||
|
c, err = rpcclient.NewWS(gctx, endpoint, rpcclient.WSOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c, err = rpcclient.New(gctx, endpoint, rpcclient.Options{})
|
||||||
|
if err != nil {
|
||||||
|
return cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = c.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue