2019-06-25 11:42:17 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2019-07-23 18:49:09 +00:00
|
|
|
"net/http"
|
|
|
|
|
2020-05-20 17:43:22 +00:00
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-05-20 17:43:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/apistruct"
|
2019-06-25 11:42:17 +00:00
|
|
|
)
|
|
|
|
|
2019-08-02 16:25:10 +00:00
|
|
|
// NewCommonRPC creates a new http jsonrpc client.
|
2019-10-03 18:12:30 +00:00
|
|
|
func NewCommonRPC(addr string, requestHeader http.Header) (api.Common, jsonrpc.ClientCloser, error) {
|
2019-12-09 17:08:32 +00:00
|
|
|
var res apistruct.CommonStruct
|
2019-10-03 18:12:30 +00:00
|
|
|
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
|
2019-08-02 16:25:10 +00:00
|
|
|
[]interface{}{
|
|
|
|
&res.Internal,
|
2020-03-24 18:00:08 +00:00
|
|
|
},
|
|
|
|
requestHeader,
|
|
|
|
)
|
2019-08-02 16:25:10 +00:00
|
|
|
|
2019-10-03 18:12:30 +00:00
|
|
|
return &res, closer, err
|
2019-08-02 16:25:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 00:40:19 +00:00
|
|
|
// NewFullNodeRPC creates a new http jsonrpc client.
|
2019-10-03 18:12:30 +00:00
|
|
|
func NewFullNodeRPC(addr string, requestHeader http.Header) (api.FullNode, jsonrpc.ClientCloser, error) {
|
2019-12-09 17:08:32 +00:00
|
|
|
var res apistruct.FullNodeStruct
|
2019-10-03 18:12:30 +00:00
|
|
|
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
|
2019-07-24 00:40:19 +00:00
|
|
|
[]interface{}{
|
|
|
|
&res.CommonStruct.Internal,
|
|
|
|
&res.Internal,
|
|
|
|
}, requestHeader)
|
|
|
|
|
2019-10-03 18:12:30 +00:00
|
|
|
return &res, closer, err
|
2019-07-01 20:00:22 +00:00
|
|
|
}
|
2019-07-24 00:40:19 +00:00
|
|
|
|
|
|
|
// NewStorageMinerRPC creates a new http jsonrpc client for storage miner
|
2019-10-03 18:12:30 +00:00
|
|
|
func NewStorageMinerRPC(addr string, requestHeader http.Header) (api.StorageMiner, jsonrpc.ClientCloser, error) {
|
2019-12-09 17:08:32 +00:00
|
|
|
var res apistruct.StorageMinerStruct
|
2019-10-03 18:12:30 +00:00
|
|
|
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
|
2019-07-24 00:40:19 +00:00
|
|
|
[]interface{}{
|
|
|
|
&res.CommonStruct.Internal,
|
|
|
|
&res.Internal,
|
2020-03-24 18:00:08 +00:00
|
|
|
},
|
|
|
|
requestHeader,
|
|
|
|
)
|
2019-07-24 00:40:19 +00:00
|
|
|
|
2019-10-03 18:12:30 +00:00
|
|
|
return &res, closer, err
|
2019-07-24 01:10:26 +00:00
|
|
|
}
|
2020-03-11 01:57:52 +00:00
|
|
|
|
2020-05-27 20:53:20 +00:00
|
|
|
func NewWorkerRPC(addr string, requestHeader http.Header) (api.WorkerAPI, jsonrpc.ClientCloser, error) {
|
2020-03-11 01:57:52 +00:00
|
|
|
var res apistruct.WorkerStruct
|
|
|
|
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
|
|
|
|
[]interface{}{
|
|
|
|
&res.Internal,
|
2020-03-24 18:00:08 +00:00
|
|
|
},
|
|
|
|
requestHeader,
|
|
|
|
)
|
2020-03-11 01:57:52 +00:00
|
|
|
|
|
|
|
return &res, closer, err
|
|
|
|
}
|