-
Notifications
You must be signed in to change notification settings - Fork 2
/
ordererclient.go
47 lines (39 loc) · 1.52 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
/*
Copyright IBM Corp. 2016-2017 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fabchanger
import (
"context"
"crypto/tls"
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/core/comm"
"github.com/pkg/errors"
)
// OrdererClient represents a client for communicating with an ordering
// service
type OrdererClient struct {
CommonClient
}
// Broadcast returns a broadcast client for the AtomicBroadcast service
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)
}
// TODO: check to see if we should actually handle error before returning
return ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO())
}
// Deliver returns a deliver client for the AtomicBroadcast service
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)
}
// TODO: check to see if we should actually handle error before returning
return ab.NewAtomicBroadcastClient(conn).Deliver(context.TODO())
}
// Certificate returns the TLS client certificate (if available)
func (oc *OrdererClient) Certificate() tls.Certificate {
return oc.CommonClient.Certificate()
}