forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
31 lines (26 loc) · 919 Bytes
/
client.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
package merkletree
import (
"context"
"time"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/merkletree/hashdb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// NewMTDBServiceClient creates a new MTDB client.
func NewMTDBServiceClient(ctx context.Context, c Config) (hashdb.HashDBServiceClient, *grpc.ClientConn, context.CancelFunc) {
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
}
const maxWaitSeconds = 120
ctx, cancel := context.WithTimeout(ctx, maxWaitSeconds*time.Second)
log.Infof("trying to connect to merkletree: %v", c.URI)
mtDBConn, err := grpc.DialContext(ctx, c.URI, opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
}
log.Infof("connected to merkletree")
mtDBClient := hashdb.NewHashDBServiceClient(mtDBConn)
return mtDBClient, mtDBConn, cancel
}