/
lily.go
52 lines (43 loc) · 1.35 KB
/
lily.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package commands
import (
"context"
"fmt"
"net/http"
"strings"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/lily/lens/lily"
cliutil "github.com/filecoin-project/lotus/cli/util"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/repo"
)
func GetAPI(ctx context.Context) (lily.LilyAPI, jsonrpc.ClientCloser, error) {
addrStr := strings.TrimSpace(ClientAPIFlags.APIAddr)
ainfo := cliutil.APIInfo{Addr: addrStr, Token: []byte(ClientAPIFlags.APIToken)}
addr, err := ainfo.DialArgs("v0")
if err != nil {
return nil, nil, fmt.Errorf("could not get DialArgs: %w", err)
}
return NewSentinelNodeRPC(ctx, addr, ainfo.AuthHeader())
}
func NewSentinelNodeRPC(ctx context.Context, addr string, requestHeader http.Header) (lily.LilyAPI, jsonrpc.ClientCloser, error) {
var res lily.LilyAPIStruct
closer, err := jsonrpc.NewMergeClient(ctx, addr, "Filecoin",
[]interface{}{
&res.Internal,
},
requestHeader,
)
return &res, closer, err
}
// Lily Node settings for injection into lotus node.
func LilyNodeAPIOption(out *lily.LilyAPI, fopts ...node.Option) node.Option {
resAPI := &lily.LilyNodeAPI{}
opts := node.Options(
node.WithRepoType(repo.FullNode),
node.WithEnableLibp2pNode(true),
node.Options(fopts...),
node.WithInvokesKey(node.ExtractApiKey, resAPI),
)
*out = resAPI
return opts
}