-
Notifications
You must be signed in to change notification settings - Fork 1
/
ordererclient.go
66 lines (48 loc) · 1.63 KB
/
ordererclient.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Copyright IBM Corp. 2016-2017 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package common
import (
"context"
"crypto/tls"
ab "github.com/mcc-github/blockchain-protos-go/orderer"
"github.com/mcc-github/blockchain/core/comm"
"github.com/pkg/errors"
)
type OrdererClient struct {
CommonClient
}
func NewOrdererClientFromEnv() (*OrdererClient, error) {
address, override, clientConfig, err := configFromEnv("orderer")
if err != nil {
return nil, errors.WithMessage(err, "failed to load config for OrdererClient")
}
gClient, err := comm.NewGRPCClient(clientConfig)
if err != nil {
return nil, errors.WithMessage(err, "failed to create OrdererClient from config")
}
oClient := &OrdererClient{
CommonClient: CommonClient{
GRPCClient: gClient,
Address: address,
sn: override}}
return oClient, nil
}
func (oc *OrdererClient) Broadcast() (ab.AtomicBroadcast_BroadcastClient, error) {
conn, err := oc.CommonClient.NewConnection(oc.Address, comm.ServerNameOverride(oc.sn))
if err != nil {
return nil, errors.WithMessagef(err, "orderer client failed to connect to %s", oc.Address)
}
return ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
}
func (oc *OrdererClient) Deliver() (ab.AtomicBroadcast_DeliverClient, error) {
conn, err := oc.CommonClient.NewConnection(oc.Address, comm.ServerNameOverride(oc.sn))
if err != nil {
return nil, errors.WithMessagef(err, "orderer client failed to connect to %s", oc.Address)
}
return ab.NewAtomicBroadcastClient(conn).Deliver(context.TODO())
}
func (oc *OrdererClient) Certificate() tls.Certificate {
return oc.CommonClient.Certificate()
}