区块链教程Fabric1.0源代码分析PeerBroadcastClient(Broadcast客户端)

简介:

  兄弟连区块链教程Fabric1.0源代码分析PeerBroadcastClient(Broadcast客户端),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工具函数

//构造deliverClient
func newDeliverClient(conn *grpc.ClientConn, client ab.AtomicBroadcast_DeliverClient, chainID string) *deliverClient
//代码在peer/channel/deliverclient.go

2.2、deliverClientIntf接口定义及实现

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代码如下:

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

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

相关文章
|
2月前
|
安全 区块链
区块链积分商城系统开发详细指南//需求功能/指南教程/源码流程
Developing a blockchain points mall system involves multiple aspects such as blockchain technology, smart contracts, front-end development, and business logic design. The following is the general process for developing a blockchain points mall system
|
2月前
|
存储 算法 API
面向企业的区块链教程(一)(2)
面向企业的区块链教程(一)
63 6
|
2月前
|
安全 区块链
区块链游戏系统开发步骤需求丨功能逻辑丨规则玩法丨指南教程丨源码详细
Developing blockchain game systems has been a highly anticipated field in recent years. By combining blockchain technology and game mechanics, players can enjoy a brand new gaming experience and higher game credibility.
Minecraft Fabric 教程 #8 添加附魔书
这就创建了一个FireBoom附魔书 onTargetDamaged //当目标被攻击 在mc FireballEntity类有一个 方法就是当火球碰撞了就创建一个火焰爆炸的效果
54 0
Minecraft Fabric 教程 #4 添加分组
在 ItemGroup 显示 使用 FabricItemGroupBuilder
44 0
|
10月前
|
SQL 安全 区块链
交易所系统开发(案例项目)丨区块链交易所系统开发(稳定版)/成熟技术/步骤逻辑/源码教程
The development of a blockchain exchange system involves complex technologies and functions.
Minecraft Fabric 教程 #9 添加盔甲
参数一 材料名字 参数二 耐久倍数 参数三 盔甲数也就是穿上盔甲加的盔甲值 参数四 使用的时候发出的声音 参数五 耐性
53 0
Minecraft Fabric 教程 #9 添加盔甲
Minecraft Fabric 教程 #3 添加方块
创建方块,注册,创建方块物品,添加纹理,掉落物,创建一个Block类
64 0
Minecraft Fabric 教程 #3 添加方块

热门文章

最新文章