apiclient: Version client funcs
This commit is contained in:
parent
9223a8e5ff
commit
e003977559
@ -15,8 +15,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/lib/rpcenc"
|
"github.com/filecoin-project/lotus/lib/rpcenc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommonRPC creates a new http jsonrpc client.
|
// NewCommonRPCV0 creates a new http jsonrpc client.
|
||||||
func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) {
|
func NewCommonRPCV0(ctx context.Context, addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) {
|
||||||
var res v0api.CommonStruct
|
var res v0api.CommonStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -28,8 +28,20 @@ func NewCommonRPC(ctx context.Context, addr string, requestHeader http.Header) (
|
|||||||
return &res, closer, err
|
return &res, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFullNodeRPC creates a new http jsonrpc client.
|
// NewFullNodeRPCV0 creates a new http jsonrpc client.
|
||||||
func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) {
|
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
|
var res v1api.FullNodeStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -40,8 +52,8 @@ func NewFullNodeRPC(ctx context.Context, addr string, requestHeader http.Header)
|
|||||||
return &res, closer, err
|
return &res, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStorageMinerRPC creates a new http jsonrpc client for miner
|
// NewStorageMinerRPCV0 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) {
|
func NewStorageMinerRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (v0api.StorageMiner, jsonrpc.ClientCloser, error) {
|
||||||
var res v0api.StorageMinerStruct
|
var res v0api.StorageMinerStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -55,7 +67,7 @@ func NewStorageMinerRPC(ctx context.Context, addr string, requestHeader http.Hea
|
|||||||
return &res, closer, err
|
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)
|
u, err := url.Parse(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -84,8 +96,8 @@ func NewWorkerRPC(ctx context.Context, addr string, requestHeader http.Header) (
|
|||||||
return &res, closer, err
|
return &res, closer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGatewayRPC creates a new http jsonrpc client for a gateway node.
|
// NewGatewayRPCV0 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) {
|
func NewGatewayRPCV0(ctx context.Context, addr string, requestHeader http.Header, opts ...jsonrpc.Option) (api.Gateway, jsonrpc.ClientCloser, error) {
|
||||||
var res api.GatewayStruct
|
var res api.GatewayStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
@ -98,7 +110,7 @@ func NewGatewayRPC(ctx context.Context, addr string, requestHeader http.Header,
|
|||||||
return &res, closer, err
|
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
|
var res api.WalletStruct
|
||||||
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
|
||||||
[]interface{}{
|
[]interface{}{
|
||||||
|
@ -25,7 +25,7 @@ func SetupRemoteWallet(info string) func(mctx helpers.MetricsCtx, lc fx.Lifecycl
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
wapi, closer, err := client.NewWalletRPC(mctx, url, ai.AuthHeader())
|
wapi, closer, err := client.NewWalletRPCV0(mctx, url, ai.AuthHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) {
|
|||||||
return nil, nil, err
|
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) {
|
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 nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.NewFullNodeRPC(ctx.Context, addr, headers)
|
return client.NewFullNodeRPCV1(ctx.Context, addr, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetStorageMinerOptions struct {
|
type GetStorageMinerOptions struct {
|
||||||
@ -227,7 +227,7 @@ func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.St
|
|||||||
addr = u.String()
|
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) {
|
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 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) {
|
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 nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.NewGatewayRPC(ctx.Context, addr, headers)
|
return client.NewGatewayRPCV0(ctx.Context, addr, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DaemonContext(cctx *cli.Context) context.Context {
|
func DaemonContext(cctx *cli.Context) context.Context {
|
||||||
|
@ -22,7 +22,7 @@ func GetFullNodeAPIUsingCredentials(ctx context.Context, listenAddr, token strin
|
|||||||
return nil, nil, err
|
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 {
|
func apiURI(addr string) string {
|
||||||
return "ws://" + addr + "/rpc/v0"
|
return "ws://" + addr + "/rpc/v0"
|
||||||
|
@ -250,7 +250,7 @@ func startNodes(
|
|||||||
|
|
||||||
// Create a gateway client API that connects to the gateway server
|
// Create a gateway client API that connects to the gateway server
|
||||||
var gapi api.Gateway
|
var gapi api.Gateway
|
||||||
gapi, closer, err = client.NewGatewayRPC(ctx, addr, nil)
|
gapi, closer, err = client.NewGatewayRPCV0(ctx, addr, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Provide the gateway API to dependency injection
|
// Provide the gateway API to dependency injection
|
||||||
|
@ -118,7 +118,7 @@ var consensusCheckCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
api, closer, err := client.NewFullNodeRPC(cctx.Context, addr, nil)
|
api, closer, err := client.NewFullNodeRPCV1(cctx.Context, addr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ func connectRemoteWorker(ctx context.Context, fa api.Common, url string) (*remot
|
|||||||
headers := http.Header{}
|
headers := http.Header{}
|
||||||
headers.Add("Authorization", "Bearer "+string(token))
|
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 {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
return nil, xerrors.Errorf("creating jsonrpc client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ func fullRpc(t *testing.T, nd test.TestNode) test.TestNode {
|
|||||||
|
|
||||||
var stop func()
|
var stop func()
|
||||||
var full test.TestNode
|
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)
|
require.NoError(t, err)
|
||||||
t.Cleanup(stop)
|
t.Cleanup(stop)
|
||||||
|
|
||||||
@ -519,7 +519,7 @@ func storerRpc(t *testing.T, nd test.TestStorageNode) test.TestStorageNode {
|
|||||||
|
|
||||||
var stop func()
|
var stop func()
|
||||||
var storer test.TestStorageNode
|
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)
|
require.NoError(t, err)
|
||||||
t.Cleanup(stop)
|
t.Cleanup(stop)
|
||||||
|
|
||||||
|
@ -220,5 +220,5 @@ func GetFullNodeAPI(ctx context.Context, repo string) (api.FullNode, jsonrpc.Cli
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.NewFullNodeRPC(ctx, addr, headers)
|
return client.NewFullNodeRPCV1(ctx, addr, headers)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user