[#189] sdk/client: Return NodeInfo SDK type from EndpointInfo method

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-05 15:49:31 +03:00 committed by Alex Vanin
parent 9834ed4e68
commit 162b0de725

View file

@ -3,8 +3,9 @@ package client
import ( import (
"context" "context"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/v2/client" "github.com/nspcc-dev/neofs-api-go/v2/client"
"github.com/nspcc-dev/neofs-api-go/v2/netmap" v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature" v2signature "github.com/nspcc-dev/neofs-api-go/v2/signature"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -20,7 +21,7 @@ func (c Client) EndpointInfo(ctx context.Context, opts ...CallOption) (*netmap.N
return nil, err return nil, err
} }
return resp.GetBody().GetNodeInfo(), nil return netmap.NewNodeInfoFromV2(resp.GetBody().GetNodeInfo()), nil
default: default:
return nil, unsupportedProtocolErr return nil, unsupportedProtocolErr
} }
@ -41,16 +42,16 @@ func (c Client) Epoch(ctx context.Context, opts ...CallOption) (uint64, error) {
} }
} }
func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*netmap.LocalNodeInfoResponse, error) { func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*v2netmap.LocalNodeInfoResponse, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
for i := range opts { for i := range opts {
opts[i].apply(&callOptions) opts[i].apply(&callOptions)
} }
reqBody := new(netmap.LocalNodeInfoRequestBody) reqBody := new(v2netmap.LocalNodeInfoRequestBody)
req := new(netmap.LocalNodeInfoRequest) req := new(v2netmap.LocalNodeInfoRequest)
req.SetBody(reqBody) req.SetBody(reqBody)
req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions)) req.SetMetaHeader(v2MetaHeaderFromOpts(callOptions))
@ -82,19 +83,19 @@ func (c Client) endpointInfoV2(ctx context.Context, opts ...CallOption) (*netmap
} }
} }
func v2NetmapClientFromOptions(opts *clientOptions) (cli *netmap.Client, err error) { func v2NetmapClientFromOptions(opts *clientOptions) (cli *v2netmap.Client, err error) {
switch { switch {
case opts.grpcOpts.v2NetmapClient != nil: case opts.grpcOpts.v2NetmapClient != nil:
// return value from client cache // return value from client cache
return opts.grpcOpts.v2NetmapClient, nil return opts.grpcOpts.v2NetmapClient, nil
case opts.grpcOpts.conn != nil: case opts.grpcOpts.conn != nil:
cli, err = netmap.NewClient(netmap.WithGlobalOpts( cli, err = v2netmap.NewClient(v2netmap.WithGlobalOpts(
client.WithGRPCConn(opts.grpcOpts.conn)), client.WithGRPCConn(opts.grpcOpts.conn)),
) )
case opts.addr != "": case opts.addr != "":
cli, err = netmap.NewClient(netmap.WithGlobalOpts( cli, err = v2netmap.NewClient(v2netmap.WithGlobalOpts(
client.WithNetworkAddress(opts.addr)), client.WithNetworkAddress(opts.addr)),
) )