package util import ( "context" "net/http" "github.com/filecoin-project/go-jsonrpc" "github.com/filecoin-project/lotus/api" "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) (api.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.NewFullNodeRPC(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 }