From e003977559dae78f6cfe92d5a84ea752ebdf10fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 25 Mar 2021 15:39:48 +0100 Subject: [PATCH] apiclient: Version client funcs --- api/client/client.go | 32 ++++++++++++++++++++--------- chain/wallet/remotewallet/remote.go | 2 +- cli/util/api.go | 10 ++++----- cmd/lotus-chainwatch/util/api.go | 2 +- cmd/lotus-gateway/endtoend_test.go | 2 +- cmd/lotus-shed/consensus.go | 2 +- node/impl/remoteworker.go | 2 +- node/test/builder.go | 4 ++-- tools/stats/rpc.go | 2 +- 9 files changed, 35 insertions(+), 23 deletions(-) diff --git a/api/client/client.go b/api/client/client.go index 6c2f00b46..7dea837e8 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -15,8 +15,8 @@ import ( "github.com/filecoin-project/lotus/lib/rpcenc" ) -// NewCommonRPC creates a new http jsonrpc client. -func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) { +// NewCommonRPCV0 creates a new http jsonrpc client. +func NewCommonRPCV0(ctx context.Context, addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) { var res v0api.CommonStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ @@ -28,8 +28,20 @@ func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) ( return &res, closer, err } -// NewFullNodeRPC creates a new http jsonrpc client. -func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) { +// NewFullNodeRPCV0 creates a new http jsonrpc client. +func NewFullNodeRPCV0(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) { + var res v0api.FullNodeStruct + closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", + []interface{}{ + &res.CommonStruct.Internal, + &res.Internal, + }, requestHeader) + + return &res, closer, err +} + +// NewFullNodeRPCV1 creates a new http jsonrpc client. +func NewFullNodeRPCV1(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) { var res v1api.FullNodeStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ @@ -40,8 +52,8 @@ func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) return &res, closer, err } -// NewStorageMinerRPC creates a new http jsonrpc client for miner -func NewStorageMinerRPC(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (v0api.StorageMiner, jsonrpc.ClientCloser, error) { +// NewStorageMinerRPCV0 creates a new http jsonrpc client for miner +func NewStorageMinerRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (v0api.StorageMiner, jsonrpc.ClientCloser, error) { var res v0api.StorageMinerStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ @@ -55,7 +67,7 @@ func NewStorageMinerRPC(ctx context.Context, addr string, requestHeader http.Hea return &res, closer, err } -func NewWorkerRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Worker, jsonrpc.ClientCloser, error) { +func NewWorkerRPCV0(ctx context.Context, addr string, requestHeader http.Header) (api.Worker, jsonrpc.ClientCloser, error) { u, err := url.Parse(addr) if err != nil { return nil, nil, err @@ -84,8 +96,8 @@ func NewWorkerRPC(ctx context.Context, addr string, requestHeader http.Header) ( return &res, closer, err } -// NewGatewayRPC creates a new http jsonrpc client for a gateway node. -func NewGatewayRPC(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) { +// NewGatewayRPCV0 creates a new http jsonrpc client for a gateway node. +func NewGatewayRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) { var res api.GatewayStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ @@ -98,7 +110,7 @@ func NewGatewayRPC(ctx context.Context, addr string, requestHeader http.Header, return &res, closer, err } -func NewWalletRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Wallet, jsonrpc.ClientCloser, error) { +func NewWalletRPCV0(ctx context.Context, addr string, requestHeader http.Header) (api.Wallet, jsonrpc.ClientCloser, error) { var res api.WalletStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ diff --git a/chain/wallet/remotewallet/remote.go b/chain/wallet/remotewallet/remote.go index 685d0fc35..d1734518e 100644 --- a/chain/wallet/remotewallet/remote.go +++ b/chain/wallet/remotewallet/remote.go @@ -25,7 +25,7 @@ func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycl return nil, err } - wapi, closer, err := client.NewWalletRPC(mctx, url, ai.AuthHeader()) + wapi, closer, err := client.NewWalletRPCV0(mctx, url, ai.AuthHeader()) if err != nil { return nil, xerrors.Errorf("creating jsonrpc client: %w", err) } diff --git a/cli/util/api.go b/cli/util/api.go index c0f0b0ed1..c296c84ff 100644 --- a/cli/util/api.go +++ b/cli/util/api.go @@ -170,7 +170,7 @@ func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) { return nil, nil, err } - return client.NewCommonRPC(ctx.Context, addr, headers) + return client.NewCommonRPCV0(ctx.Context, addr, headers) } func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error) { @@ -183,7 +183,7 @@ func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error return nil, nil, err } - return client.NewFullNodeRPC(ctx.Context, addr, headers) + return client.NewFullNodeRPCV1(ctx.Context, addr, headers) } type GetStorageMinerOptions struct { @@ -227,7 +227,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St addr = u.String() } - return client.NewStorageMinerRPC(ctx.Context, addr, headers) + return client.NewStorageMinerRPCV0(ctx.Context, addr, headers) } func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) { @@ -236,7 +236,7 @@ func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) { return nil, nil, err } - return client.NewWorkerRPC(ctx.Context, addr, headers) + return client.NewWorkerRPCV0(ctx.Context, addr, headers) } func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) { @@ -245,7 +245,7 @@ func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) return nil, nil, err } - return client.NewGatewayRPC(ctx.Context, addr, headers) + return client.NewGatewayRPCV0(ctx.Context, addr, headers) } func DaemonContext(cctx *cli.Context) context.Context { diff --git a/cmd/lotus-chainwatch/util/api.go b/cmd/lotus-chainwatch/util/api.go index cfda833e0..57e75fe58 100644 --- a/cmd/lotus-chainwatch/util/api.go +++ b/cmd/lotus-chainwatch/util/api.go @@ -22,7 +22,7 @@ func GetFullNodeAPIUsingCredentials(ctx context.Context, listenAddr, token strin return nil, nil, err } - return client.NewFullNodeRPC(ctx, apiURI(addr), apiHeaders(token)) + return client.NewFullNodeRPCV1(ctx, apiURI(addr), apiHeaders(token)) } func apiURI(addr string) string { return "ws://" + addr + "/rpc/v0" diff --git a/cmd/lotus-gateway/endtoend_test.go b/cmd/lotus-gateway/endtoend_test.go index 8c1901d65..f575c5776 100644 --- a/cmd/lotus-gateway/endtoend_test.go +++ b/cmd/lotus-gateway/endtoend_test.go @@ -250,7 +250,7 @@ func startNodes( // Create a gateway client API that connects to the gateway server var gapi api.Gateway - gapi, closer, err = client.NewGatewayRPC(ctx, addr, nil) + gapi, closer, err = client.NewGatewayRPCV0(ctx, addr, nil) require.NoError(t, err) // Provide the gateway API to dependency injection diff --git a/cmd/lotus-shed/consensus.go b/cmd/lotus-shed/consensus.go index 8e30f5cee..2c5df4ea5 100644 --- a/cmd/lotus-shed/consensus.go +++ b/cmd/lotus-shed/consensus.go @@ -118,7 +118,7 @@ var consensusCheckCmd = &cli.Command{ return err } - api, closer, err := client.NewFullNodeRPC(cctx.Context, addr, nil) + api, closer, err := client.NewFullNodeRPCV1(cctx.Context, addr, nil) if err != nil { return err } diff --git a/node/impl/remoteworker.go b/node/impl/remoteworker.go index 1369dc248..8dc7510b4 100644 --- a/node/impl/remoteworker.go +++ b/node/impl/remoteworker.go @@ -33,7 +33,7 @@ func connectRemoteWorker(ctx context.Context, fa api.Common, url string) (*remot headers := http.Header{} headers.Add("Authorization", "Bearer "+string(token)) - wapi, closer, err := client.NewWorkerRPC(context.TODO(), url, headers) + wapi, closer, err := client.NewWorkerRPCV0(context.TODO(), url, headers) if err != nil { return nil, xerrors.Errorf("creating jsonrpc client: %w", err) } diff --git a/node/test/builder.go b/node/test/builder.go index 72a55ab49..9c4515a9b 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -505,7 +505,7 @@ func fullRpc(t *testing.T, nd test.TestNode) test.TestNode { var stop func() var full test.TestNode - full.FullNode, stop, err = client.NewFullNodeRPC(context.Background(), listenAddr, nil) + full.FullNode, stop, err = client.NewFullNodeRPCV1(context.Background(), listenAddr, nil) require.NoError(t, err) t.Cleanup(stop) @@ -519,7 +519,7 @@ func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode { var stop func() var storer test.TestStorageNode - storer.StorageMiner, stop, err = client.NewStorageMinerRPC(context.Background(), listenAddr, nil) + storer.StorageMiner, stop, err = client.NewStorageMinerRPCV0(context.Background(), listenAddr, nil) require.NoError(t, err) t.Cleanup(stop) diff --git a/tools/stats/rpc.go b/tools/stats/rpc.go index b01c07a35..cd3987ff1 100644 --- a/tools/stats/rpc.go +++ b/tools/stats/rpc.go @@ -220,5 +220,5 @@ func GetFullNodeAPI(ctx context.Context, repo string) (api.FullNode, jsonrpc.Cli return nil, nil, err } - return client.NewFullNodeRPC(ctx, addr, headers) + return client.NewFullNodeRPCV1(ctx, addr, headers) }