Fetch the repository succeeded.
/*
Copyright IBM Corp. 2016 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package common
import (
cb "github.com/hyperledger/fabric-protos-go/common"
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/pkg/errors"
)
type BroadcastClient interface {
//Send data to orderer
Send(env *cb.Envelope) error
Close() error
}
type BroadcastGRPCClient struct {
Client ab.AtomicBroadcast_BroadcastClient
}
// GetBroadcastClient creates a simple instance of the BroadcastClient interface
func GetBroadcastClient() (BroadcastClient, error) {
oc, err := NewOrdererClientFromEnv()
if err != nil {
return nil, err
}
bc, err := oc.Broadcast()
if err != nil {
return nil, err
}
return &BroadcastGRPCClient{Client: bc}, nil
}
func (s *BroadcastGRPCClient) getAck() error {
msg, err := s.Client.Recv()
if err != nil {
return err
}
if msg.Status != cb.Status_SUCCESS {
return errors.Errorf("got unexpected status: %v -- %s", msg.Status, msg.Info)
}
return nil
}
//Send data to orderer
func (s *BroadcastGRPCClient) Send(env *cb.Envelope) error {
if err := s.Client.Send(env); err != nil {
return errors.WithMessage(err, "could not send")
}
err := s.getAck()
return err
}
func (s *BroadcastGRPCClient) Close() error {
return s.Client.CloseSend()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。