@@ -2,20 +2,22 @@ package sdk
2
2
3
3
import (
4
4
"context"
5
+ "log"
5
6
"net/http"
6
7
7
8
"github.com/ethereum/go-ethereum/ethclient"
8
9
ethrpc "github.com/ethereum/go-ethereum/rpc"
9
10
"github.com/filecoin-project/go-jsonrpc"
10
11
lotusapi "github.com/filecoin-project/lotus/api"
11
12
"github.com/glifio/go-pools/rpc"
13
+ "github.com/gorilla/websocket"
12
14
)
13
15
14
16
func (c * fevmExtern ) ConnectEthClient () (* ethclient.Client , error ) {
15
- return connectEthClient (c .dialAddr , c .token )
17
+ return ConnectEthClient (c .dialAddr , c .token )
16
18
}
17
19
18
- func connectEthClient (dialAddr string , token string ) (* ethclient.Client , error ) {
20
+ func ConnectEthClient (dialAddr string , token string ) (* ethclient.Client , error ) {
19
21
if token == "" {
20
22
return ethclient .Dial (dialAddr )
21
23
}
@@ -34,11 +36,25 @@ func connectEthClient(dialAddr string, token string) (*ethclient.Client, error)
34
36
return ethclient .NewClient (client ), nil
35
37
}
36
38
39
+ func ConnectEthClientWS (dialAddr string , token string ) (* ethclient.Client , error ) {
40
+
41
+ tokenHeader := ethrpc .WithHeader ("Authorization" , "Bearer " + token )
42
+ httpClient := ethrpc .WithWebsocketDialer (websocket.Dialer {})
43
+
44
+ client , err := ethrpc .DialOptions (context .Background (), dialAddr , httpClient , tokenHeader )
45
+ if err != nil {
46
+ log .Println ("error dialing eth client" , err )
47
+ return nil , err
48
+ }
49
+
50
+ return ethclient .NewClient (client ), nil
51
+ }
52
+
37
53
func (c * fevmExtern ) ConnectLotusClient () (* lotusapi.FullNodeStruct , jsonrpc.ClientCloser , error ) {
38
- return connectLotusClient (c .dialAddr , c .token )
54
+ return ConnectLotusClient (c .dialAddr , c .token )
39
55
}
40
56
41
- func connectLotusClient (lotusDialAddr string , lotusToken string ) (* lotusapi.FullNodeStruct , jsonrpc.ClientCloser , error ) {
57
+ func ConnectLotusClient (lotusDialAddr string , lotusToken string ) (* lotusapi.FullNodeStruct , jsonrpc.ClientCloser , error ) {
42
58
head := http.Header {}
43
59
44
60
if lotusToken != "" {
0 commit comments