63 Star 183 Fork 3

Gitee 极速下载/hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
extcc_handler.go 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package extcc
import (
"context"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/pkg/errors"
pb "github.com/hyperledger/fabric-protos-go/peer"
"google.golang.org/grpc"
)
var extccLogger = flogging.MustGetLogger("extcc")
// StreamHandler handles the `Chaincode` gRPC service with peer as client
type StreamHandler interface {
HandleChaincodeStream(stream ccintf.ChaincodeStream) error
}
type ExternalChaincodeRuntime struct {
}
// createConnection - standard grpc client creating using ClientConfig info (surprised there isn't
// a helper method for this)
func (i *ExternalChaincodeRuntime) createConnection(ccid string, ccinfo *ccintf.ChaincodeServerInfo) (*grpc.ClientConn, error) {
grpcClient, err := comm.NewGRPCClient(ccinfo.ClientConfig)
if err != nil {
return nil, errors.WithMessagef(err, "error creating grpc client to %s", ccid)
}
conn, err := grpcClient.NewConnection(ccinfo.Address)
if err != nil {
return nil, errors.WithMessagef(err, "error creating grpc connection to %s", ccinfo.Address)
}
extccLogger.Debugf("Created external chaincode connection: %s", ccid)
return conn, nil
}
func (i *ExternalChaincodeRuntime) Stream(ccid string, ccinfo *ccintf.ChaincodeServerInfo, sHandler StreamHandler) error {
extccLogger.Debugf("Starting external chaincode connection: %s", ccid)
conn, err := i.createConnection(ccid, ccinfo)
if err != nil {
return errors.WithMessagef(err, "error cannot create connection for %s", ccid)
}
defer conn.Close()
//create the client and start streaming
client := pb.NewChaincodeClient(conn)
stream, err := client.Connect(context.Background())
if err != nil {
return errors.WithMessagef(err, "error creating grpc client connection to %s", ccid)
}
//peer as client has to initiate the stream. Rest of the process is unchanged
sHandler.HandleChaincodeStream(stream)
extccLogger.Debugf("External chaincode %s client exited", ccid)
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v2.0.0-beta

搜索帮助