api client: Use versioned api packages
This commit is contained in:
parent
b3774f8b87
commit
65dcec0ebc
@ -11,12 +11,14 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/api/apistruct"
|
"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"
|
"github.com/filecoin-project/lotus/lib/rpcenc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommonRPC creates a new http jsonrpc client.
|
// NewCommonRPC creates a new http jsonrpc client.
|
||||||
func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) {
|
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",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
&res.Internal,
|
&res.Internal,
|
||||||
@ -29,7 +31,7 @@ func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) (
|
|||||||
|
|
||||||
// NewFullNodeRPC creates a new http jsonrpc client.
|
// NewFullNodeRPC creates a new http jsonrpc client.
|
||||||
func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) {
|
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",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
&res.CommonStruct.Internal,
|
&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
|
// 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) {
|
func NewStorageMinerRPC(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (v0api.StorageMiner, jsonrpc.ClientCloser, error) {
|
||||||
var res apistruct.StorageMinerStruct
|
var res v0api.StorageMinerStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
&res.CommonStruct.Internal,
|
&res.CommonStruct.Internal,
|
||||||
|
9
api/v0api/storage.go
Normal file
9
api/v0api/storage.go
Normal file
@ -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
|
@ -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) {
|
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle) (*RemoteWallet, error) {
|
||||||
ai := cliutil.ParseApiInfo(info)
|
ai := cliutil.ParseApiInfo(info)
|
||||||
|
|
||||||
url, err := ai.DialArgs()
|
url, err := ai.DialArgs("v0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -133,13 +133,13 @@ func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) {
|
|||||||
}, nil
|
}, 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)
|
ainfo, err := GetAPIInfo(ctx, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, xerrors.Errorf("could not get API info: %w", err)
|
return "", nil, xerrors.Errorf("could not get API info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := ainfo.DialArgs()
|
addr, err := ainfo.DialArgs(version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, xerrors.Errorf("could not get DialArgs: %w", err)
|
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
|
return tn.(api.FullNode), func() {}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, headers, err := GetRawAPI(ctx, t)
|
addr, headers, err := GetRawAPI(ctx, t, "v0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error
|
|||||||
return tn.(api.FullNode), func() {}, nil
|
return tn.(api.FullNode), func() {}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, headers, err := GetRawAPI(ctx, repo.FullNode)
|
addr, headers, err := GetRawAPI(ctx, repo.FullNode, "v1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
|
|||||||
return tn.(api.StorageMiner), func() {}, nil
|
return tn.(api.StorageMiner), func() {}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, headers, err := GetRawAPI(ctx, repo.StorageMiner)
|
addr, headers, err := GetRawAPI(ctx, repo.StorageMiner, "v0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
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) {
|
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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
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) {
|
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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -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)
|
ma, err := multiaddr.NewMultiaddr(a.Addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, addr, err := manet.DialArgs(ma)
|
_, addr, err := manet.DialArgs(ma)
|
||||||
@ -44,14 +44,14 @@ func (a APIInfo) DialArgs() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return "ws://" + addr + "/rpc/v0", nil
|
return "ws://" + addr + "/rpc/" + version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = url.Parse(a.Addr)
|
_, err = url.Parse(a.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return a.Addr + "/rpc/v0", nil
|
return a.Addr + "/rpc/" + version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a APIInfo) Host() (string, error) {
|
func (a APIInfo) Host() (string, error) {
|
||||||
|
@ -113,7 +113,7 @@ var consensusCheckCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ainfo := cliutil.APIInfo{Addr: apima.String()}
|
ainfo := cliutil.APIInfo{Addr: apima.String()}
|
||||||
addr, err := ainfo.DialArgs()
|
addr, err := ainfo.DialArgs("v1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user