From 65dcec0ebcf80e250caa625d22a3e57d2fed2309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 23 Mar 2021 19:15:44 +0100 Subject: [PATCH] api client: Use versioned api packages --- api/client/client.go | 10 ++++++---- api/v0api/storage.go | 9 +++++++++ chain/wallet/remotewallet/remote.go | 2 +- cli/util/api.go | 14 +++++++------- cli/util/apiinfo.go | 6 +++--- cmd/lotus-shed/consensus.go | 2 +- 6 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 api/v0api/storage.go diff --git a/api/client/client.go b/api/client/client.go index 9ffd1707e..a08da0929 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -11,12 +11,14 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apistruct" + "github.com/filecoin-project/lotus/api/v0api" + "github.com/filecoin-project/lotus/api/v1api" "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) { - var res apistruct.CommonStruct + var res v0api.CommonStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ &res.Internal, @@ -29,7 +31,7 @@ func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) ( // NewFullNodeRPC creates a new http jsonrpc client. func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) { - var res apistruct.FullNodeStruct + var res v1api.FullNodeStruct closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin", []interface{}{ &res.CommonStruct.Internal, @@ -40,8 +42,8 @@ func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) } // NewStorageMinerRPC creates a new http jsonrpc client for miner -func NewStorageMinerRPC(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.StorageMiner, jsonrpc.ClientCloser, error) { - var res apistruct.StorageMinerStruct +func NewStorageMinerRPC(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{}{ &res.CommonStruct.Internal, diff --git a/api/v0api/storage.go b/api/v0api/storage.go new file mode 100644 index 000000000..a05f48285 --- /dev/null +++ b/api/v0api/storage.go @@ -0,0 +1,9 @@ +package v0api + +import ( + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/apistruct" +) + +type StorageMiner = api.StorageMiner +type StorageMinerStruct = apistruct.StorageMinerStruct diff --git a/chain/wallet/remotewallet/remote.go b/chain/wallet/remotewallet/remote.go index 262b5f9c6..685d0fc35 100644 --- a/chain/wallet/remotewallet/remote.go +++ b/chain/wallet/remotewallet/remote.go @@ -20,7 +20,7 @@ func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycl return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) { ai := cliutil.ParseApiInfo(info) - url, err := ai.DialArgs() + url, err := ai.DialArgs("v0") if err != nil { return nil, err } diff --git a/cli/util/api.go b/cli/util/api.go index ce5945f2e..c0f0b0ed1 100644 --- a/cli/util/api.go +++ b/cli/util/api.go @@ -133,13 +133,13 @@ func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) { }, nil } -func GetRawAPI(ctx *cli.Context, t repo.RepoType) (string, http.Header, error) { +func GetRawAPI(ctx *cli.Context, t repo.RepoType, version string) (string, http.Header, error) { ainfo, err := GetAPIInfo(ctx, t) if err != nil { return "", nil, xerrors.Errorf("could not get API info: %w", err) } - addr, err := ainfo.DialArgs() + addr, err := ainfo.DialArgs(version) if err != nil { return "", nil, xerrors.Errorf("could not get DialArgs: %w", err) } @@ -165,7 +165,7 @@ func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) { return tn.(api.FullNode), func() {}, nil } - addr, headers, err := GetRawAPI(ctx, t) + addr, headers, err := GetRawAPI(ctx, t, "v0") if err != nil { return nil, nil, err } @@ -178,7 +178,7 @@ func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error return tn.(api.FullNode), func() {}, nil } - addr, headers, err := GetRawAPI(ctx, repo.FullNode) + addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1") if err != nil { return nil, nil, err } @@ -206,7 +206,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St return tn.(api.StorageMiner), func() {}, nil } - addr, headers, err := GetRawAPI(ctx, repo.StorageMiner) + addr, headers, err := GetRawAPI(ctx, repo.StorageMiner, "v0") if err != nil { return nil, nil, err } @@ -231,7 +231,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St } func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) { - addr, headers, err := GetRawAPI(ctx, repo.Worker) + addr, headers, err := GetRawAPI(ctx, repo.Worker, "v0") if err != nil { return nil, nil, err } @@ -240,7 +240,7 @@ func GetWorkerAPI(ctx *cli.Context) (api.Worker, jsonrpc.ClientCloser, error) { } func GetGatewayAPI(ctx *cli.Context) (api.Gateway, jsonrpc.ClientCloser, error) { - addr, headers, err := GetRawAPI(ctx, repo.FullNode) + addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v0") if err != nil { return nil, nil, err } diff --git a/cli/util/apiinfo.go b/cli/util/apiinfo.go index 1f9a83769..41ca18c61 100644 --- a/cli/util/apiinfo.go +++ b/cli/util/apiinfo.go @@ -36,7 +36,7 @@ func ParseApiInfo(s string) APIInfo { } } -func (a APIInfo) DialArgs() (string, error) { +func (a APIInfo) DialArgs(version string) (string, error) { ma, err := multiaddr.NewMultiaddr(a.Addr) if err == nil { _, addr, err := manet.DialArgs(ma) @@ -44,14 +44,14 @@ func (a APIInfo) DialArgs() (string, error) { return "", err } - return "ws://" + addr + "/rpc/v0", nil + return "ws://" + addr + "/rpc/" + version, nil } _, err = url.Parse(a.Addr) if err != nil { return "", err } - return a.Addr + "/rpc/v0", nil + return a.Addr + "/rpc/" + version, nil } func (a APIInfo) Host() (string, error) { diff --git a/cmd/lotus-shed/consensus.go b/cmd/lotus-shed/consensus.go index c78c9c00f..8e30f5cee 100644 --- a/cmd/lotus-shed/consensus.go +++ b/cmd/lotus-shed/consensus.go @@ -113,7 +113,7 @@ var consensusCheckCmd = &cli.Command{ return err } ainfo := cliutil.APIInfo{Addr: apima.String()} - addr, err := ainfo.DialArgs() + addr, err := ainfo.DialArgs("v1") if err != nil { return err }