cli: support WS client for query height

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-07-04 15:11:45 +03:00
parent 5566e354d4
commit 36bf30a03a

View file

@ -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)
} }