forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror_node.go
44 lines (35 loc) · 977 Bytes
/
mirror_node.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
package hedera
import (
"github.com/hashgraph/hedera-sdk-go/v2/proto/mirror"
"github.com/pkg/errors"
"google.golang.org/grpc/keepalive"
"time"
"google.golang.org/grpc"
)
type mirrorNode struct {
channel *mirror.ConsensusServiceClient
address string
}
func newMirrorNode(address string) *mirrorNode {
return &mirrorNode{
address: address,
channel: nil,
}
}
func (node *mirrorNode) getChannel() (*mirror.ConsensusServiceClient, error) {
if node.channel != nil {
return node.channel, nil
}
var kacp = keepalive.ClientParameters{
Time: 10 * time.Second,
Timeout: time.Second,
PermitWithoutStream: true,
}
conn, err := grpc.Dial(node.address, grpc.WithInsecure(), grpc.WithKeepaliveParams(kacp), grpc.WithBlock())
if err != nil {
return nil, errors.Wrapf(err, "error connecting to mirror at %s", node.address)
}
channel := mirror.NewConsensusServiceClient(conn)
node.channel = &channel
return node.channel, nil
}