forked from decred/tumblebit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpcclient.go
37 lines (30 loc) · 830 Bytes
/
rpcclient.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
// Copyright (c) 2013-2015 The btcsuite developers
// Copyright (c) 2015-2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"context"
"net"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
func startRPCClient(ctx context.Context) (*grpc.ClientConn, error) {
var opts []grpc.DialOption
if !cfg.DisableClientTLS {
host, _, err := net.SplitHostPort(cfg.RPCConnect)
if err != nil {
return nil, err
}
creds, err := credentials.NewClientTLSFromFile(cfg.CAFile.Value, host)
if err != nil {
return nil, err
}
opts = append(opts, grpc.WithTransportCredentials(creds))
}
client, err := grpc.DialContext(ctx, cfg.RPCConnect, opts...)
if err != nil {
return nil, err
}
return client, nil
}