返回
北京兄弟连IT
置顶
该校与厚学网暂未合作,平台不保证课程的真实有效性,如有侵权等争议,请及时与厚学网联系处理
招生热线:400-800-2178

学校地址:北京市昌平区回龙观文华西路育荣教育园区兄弟连IT教育

兄弟连区块链教程(Deliver客户端)

165 2018-11-07 20:21:47

学习笔记

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

# Fabric1.0源代码笔记之Peer DeliverClient(Deliver客户端)

 

## 1、DeliverClient概述

 

DeliverClient代码分布如下:

 

* peer/channel/deliverclient.go,deliverClientIntf接口定义及实现,以及DeliverClient工具函数。

* protos/orderer/ab.pb.go,AtomicBroadcast_DeliverClient接口定义和实现。

 

## 2、deliverClientIntf接口定义及实现

 

### 2.1、DeliverClient工具函数

 

```go

//构造deliverClient

func newDeliverClient(conn *grpc.ClientConn, client ab.AtomicBroadcast_DeliverClient, chainID string) *deliverClient

//代码在peer/channel/deliverclient.go

```

 

### 2.2、deliverClientIntf接口定义及实现

 

```go

type deliverClientIntf interface {

    getSpecifiedBlock(num uint64) (*common.Block, error)

    getOldestBlock() (*common.Block, error)

    getNewestBlock() (*common.Block, error)

    Close() error

}

 

type deliverClient struct {

    conn    *grpc.ClientConn

    client  ab.AtomicBroadcast_DeliverClient

    chainID string

}

 

//构造查询Envelope

func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope

//r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Specified{Specified: &ab.SeekSpecified{Number: blockNumber}}}))

func (r *deliverClient) seekSpecified(blockNumber uint64) error

//r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Oldest{Oldest: &ab.SeekOldest{}}}))

func (r *deliverClient) seekOldest() error

//return r.client.Send(seekHelper(r.chainID, &ab.SeekPosition{Type: &ab.SeekPosition_Newest{Newest: &ab.SeekNewest{}}}))

func (r *deliverClient) seekNewest() error

//r.client.Recv()读取块

func (r *deliverClient) readBlock() (*common.Block, error)

//r.seekSpecified(num)和r.readBlock()

func (r *deliverClient) getSpecifiedBlock(num uint64) (*common.Block, error)

//r.seekOldest()和r.readBlock()

func (r *deliverClient) getOldestBlock() (*common.Block, error)

//r.seekNewest()和r.readBlock()

func (r *deliverClient) getNewestBlock() (*common.Block, error)

//r.conn.Close()

func (r *deliverClient) Close() error

//cf.DeliverClient.getSpecifiedBlock(0)获取创世区块

func getGenesisBlock(cf *ChannelCmdFactory) (*common.Block, error)

//代码在peer/channel/deliverclient.go

```

 

func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope代码如下:

 

```go

func seekHelper(chainID string, position *ab.SeekPosition) *common.Envelope {

    seekInfo := &ab.SeekInfo{

        Start:    position,

        Stop:     position,

        Behavior: ab.SeekInfo_BLOCK_UNTIL_READY,

    }

 

    msgVersion := int32(0)

    epoch := uint64(0)

    env, err := utils.CreateSignedEnvelope(common.HeaderType_CONFIG_UPDATE, chainID, localmsp.NewSigner(), seekInfo, msgVersion, epoch)

    return env

}

//代码在peer/channel/deliverclient.go

```

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

文中图片素材来源网络,如有侵权请联系删除
来源:北京兄弟连IT
热门课程 全部课程

热门动态

申请免费试听

只要一个电话

我们为您免费回电

立即申请
刷新
图形验证
关闭
>>
拖动左边滑块完成上方拼图
机器人