35 lines
869 B
Go
35 lines
869 B
Go
package util
|
|
|
|
import (
|
|
"context"
|
|
"github.com/filecoin-project/lotus/api/v0api"
|
|
"net/http"
|
|
|
|
"github.com/filecoin-project/go-jsonrpc"
|
|
"github.com/filecoin-project/lotus/api/client"
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
manet "github.com/multiformats/go-multiaddr/net"
|
|
)
|
|
|
|
func GetFullNodeAPIUsingCredentials(ctx context.Context, listenAddr, token string) (v0api.FullNode, jsonrpc.ClientCloser, error) {
|
|
parsedAddr, err := ma.NewMultiaddr(listenAddr)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
_, addr, err := manet.DialArgs(parsedAddr)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
return client.NewFullNodeRPCV0(ctx, apiURI(addr), apiHeaders(token))
|
|
}
|
|
func apiURI(addr string) string {
|
|
return "ws://" + addr + "/rpc/v0"
|
|
}
|
|
func apiHeaders(token string) http.Header {
|
|
headers := http.Header{}
|
|
headers.Add("Authorization", "Bearer "+token)
|
|
return headers
|
|
}
|