Skip to content

Commit

Permalink
restore missing orderer.New func
Browse files Browse the repository at this point in the history
  • Loading branch information
bogatyr285 committed Nov 26, 2021
1 parent 090d0db commit 6d59b37
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions orderer/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (

"github.com/hyperledger/fabric-protos-go/common"
fabricOrderer "github.com/hyperledger/fabric-protos-go/orderer"
"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/s7techlab/hlf-sdk-go/v2/api"
"github.com/s7techlab/hlf-sdk-go/v2/api/config"
"github.com/s7techlab/hlf-sdk-go/v2/util"
)

type ErrUnexpectedStatus struct {
Expand All @@ -25,6 +28,7 @@ type orderer struct {
uri string
conn *grpc.ClientConn
ctx context.Context
cancel context.CancelFunc
connMx sync.Mutex
broadcastClient fabricOrderer.AtomicBroadcastClient
grpcOptions []grpc.DialOption
Expand Down Expand Up @@ -128,6 +132,24 @@ func (o *orderer) initBroadcastClient() error {
return nil
}

func New(c config.ConnectionConfig, log *zap.Logger) (api.Orderer, error) {
l := log.Named(`New`)
opts, err := util.NewGRPCOptionsFromConfig(c, log)
if err != nil {
l.Error(`Failed to get GRPC options`, zap.Error(err))
return nil, fmt.Errorf(`get GRPC options: %w`, err)
}

ctx, _ := context.WithTimeout(context.Background(), c.Timeout.Duration)
conn, err := grpc.DialContext(ctx, c.Host, opts...)
if err != nil {
l.Error(`Failed to initialize GRPC connection`, zap.Error(err))
return nil, fmt.Errorf(`initialize GRPC connection: %w`, err)
}

return NewFromGRPC(ctx, conn, opts...)
}

// NewFromGRPC allows to initialize orderer from existing GRPC connection
func NewFromGRPC(ctx context.Context, conn *grpc.ClientConn, grpcOptions ...grpc.DialOption) (api.Orderer, error) {
obj := &orderer{
Expand Down

0 comments on commit 6d59b37

Please sign in to comment.