区块链教程

兄弟连区块链教程Fabric1.0源代码分析Peer Endor

2018-11-06  本文已影响0人  ab6973df9221

  兄弟连区块链教程Fabric1.0源代码分析Peer EndorserClient(Endorser客户端),2018年下半年,区块链行业正逐渐褪去发展之初的浮躁、回归理性,表面上看相关人才需求与身价似乎正在回落。但事实上,正是初期泡沫的渐退,让人们更多的关注点放在了区块链真正的技术之上。

# Fabric 1.0源代码笔记 之 Peer #EndorserClient(Endorser客户端)

## 1、EndorserClient概述

EndorserClient相关代码分布如下:

* protos/peer/peer.pb.go,EndorserClient接口及实现。

* peer/common/common.go,EndorserClient相关工具函数。

## 2、EndorserClient接口定义

```go

type EndorserClient interface {

    //处理Proposal

    ProcessProposal(ctx context.Context, in *SignedProposal, opts ...grpc.CallOption) (*ProposalResponse, error)

}

//代码在protos/peer/peer.pb.go

```

## 3、EndorserClient接口实现

EndorserClient接口实现,即endorserClient结构体及方法。

```go

type endorserClient struct {

    cc *grpc.ClientConn

}

func NewEndorserClient(cc *grpc.ClientConn) EndorserClient {

    return &endorserClient{cc}

}

func (c *endorserClient) ProcessProposal(ctx context.Context, in *SignedProposal, opts ...grpc.CallOption) (*ProposalResponse, error) {

    out := new(ProposalResponse)

    err := grpc.Invoke(ctx, "/protos.Endorser/ProcessProposal", in, out, c.cc, opts...)

    return out, nil

}

//代码在protos/peer/peer.pb.go

```

## 4、EndorserClient工具函数

```go

//获取Endorser客户端

func GetEndorserClient() (pb.EndorserClient, error) {

    clientConn, err := peer.NewPeerClientConnection()

    endorserClient := pb.NewEndorserClient(clientConn)

    return endorserClient, nil

}

//代码在peer/common/common.go

```

感谢关注兄弟连区块链教程分享!

上一篇 下一篇

猜你喜欢

热点阅读