forked from mapprotocol/atlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connections.go
40 lines (34 loc) · 954 Bytes
/
connections.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
package connections
import (
"context"
"fmt"
"gopkg.in/urfave/cli.v1"
"github.com/Alexfordev/atlas/cmd/marker/config"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
)
const (
httpScheme = "http"
httpsScheme = "https"
localHost = "localhost"
)
func DialConn(ctx *cli.Context, config *config.Config) (*ethclient.Client, string) {
conn, err := ethclient.Dial(config.RPCAddr)
if err != nil {
panic(fmt.Sprintf("Failed to connect to the map chain, addr: %s, error: %v", config.RPCAddr, err))
}
_, err = conn.ChainID(context.Background())
if err != nil {
panic(err)
}
return conn, config.RPCAddr
}
func DialRpc(config *config.Config) (*rpc.Client, string) {
logger := log.New("func", "dialConn")
conn, err := rpc.Dial(config.RPCAddr)
if err != nil {
logger.Error("Failed to connect to the Atlaschain client: %v", err)
}
return conn, config.RPCAddr
}