shitaibin.github.io
shitaibin.github.io copied to clipboard
利用工具解析fabric区块 | Go语言充电站
http://lessisbetter.site/2019/08/01/fabric-parse-block/
获取人类可读的区块内容分2步: 从账本里把区块取出来,格式为protobuf 把protobuf格式的区块,转换为JSON格式 所以这篇文章3步走: 获取区块 解析区块 常见区块类型样例 获取区块拉取应用通道区块peer channel fetch能够拉去某个通道最新、最老、特定高度的区块,只不过得到的区块是protobuf格式的,人眼不可读。 1234567891011121314151
大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
preprocessProtoBlock 这个函数有从block提取channelHeader的过程,你只需要模仿一下,然后从channelHeader里提取timestamp
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
首先非常感谢您不吝赐教。我今天看了一下,发现fabric-sdk-go 在其 internal 下提供了protoutil 这个包
github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil
通过调用 protoutil 包里面的 GetEnvelopeFromBlock 和 ChannelHeader 这两个函数应该是可以取到 timestamp的,然后我编写程序试了一下,在编译的时候报错
use of internal package github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil not allowed
想请问您,是不是 fabric-sdk-go不允许调用他下面 internal 中的包
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
首先非常感谢您不吝赐教。我今天看了一下,发现fabric-sdk-go 在其 internal 下提供了protoutil 这个包
github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil
通过调用 protoutil 包里面的 GetEnvelopeFromBlock 和 ChannelHeader 这两个函数应该是可以取到 timestamp的,然后我编写程序试了一下,在编译的时候报错
use of internal package github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil not allowed
想请问您,是不是 fabric-sdk-go不允许调用他下面 internal 中的包
这是Go的特性,internal代表只允许本模块使用,其他模块无法使用
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
首先非常感谢您不吝赐教。我今天看了一下,发现fabric-sdk-go 在其 internal 下提供了protoutil 这个包
github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil
通过调用 protoutil 包里面的 GetEnvelopeFromBlock 和 ChannelHeader 这两个函数应该是可以取到 timestamp的,然后我编写程序试了一下,在编译的时候报错
use of internal package github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil not allowed
想请问您,是不是 fabric-sdk-go不允许调用他下面 internal 中的包
这是Go的特性,internal代表只允许本模块使用,其他模块无法使用
之前 fabric-sdk-go 在他的 third_party 下是有包支持获取timestamp的,不过后来移除掉了。这样的话那是不是就无法获取timestamp了?
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
首先非常感谢您不吝赐教。我今天看了一下,发现fabric-sdk-go 在其 internal 下提供了protoutil 这个包
github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil
通过调用 protoutil 包里面的 GetEnvelopeFromBlock 和 ChannelHeader 这两个函数应该是可以取到 timestamp的,然后我编写程序试了一下,在编译的时候报错
use of internal package github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil not allowed
想请问您,是不是 fabric-sdk-go不允许调用他下面 internal 中的包
这是Go的特性,internal代表只允许本模块使用,其他模块无法使用
之前 fabric-sdk-go 在他的 third_party 下是有包支持获取timestamp的,不过后来移除掉了。这样的话那是不是就无法获取timestamp了?
可以想想办法找其他地方的接口
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui
@Shitaibin
@XUPTSunHui 大神,我又来向您请教了,我在注册完区块事件后,能监听到事件,能取到区块,但是不知道如何利用sdk-go去解析区块,想向您请教下,谢谢。
// BlockEvent contains the data for the block event type BlockEvent struct { // Block is the block that was committed Block *cb.Block // SourceURL specifies the URL of the peer that produced the event SourceURL string }
订阅区块事件,得到的就是结构体,不需要解析
我是想从区块里得到"timestamp",但是不知道怎么取出来
blcok没有timestamp,Transaction才有,你去看fabric代码,一个block创建的过程,或者看看这个函数怎么解析区块的,preprocessProtoBlock
block的结构中是包含head、data、metadata这三部分的,而data中又包含了"data->payload->head->channel_header->timestamp"的,我能获取到区块,但是不知道如何从区块的data中取得交易的timestamp.
这个函数可以从block的Envelope直接获取channelHeader
func ChannelHeader(env *cb.Envelope) (*cb.ChannelHeader, error)
首先非常感谢您不吝赐教。我今天看了一下,发现fabric-sdk-go 在其 internal 下提供了protoutil 这个包
github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil
通过调用 protoutil 包里面的 GetEnvelopeFromBlock 和 ChannelHeader 这两个函数应该是可以取到 timestamp的,然后我编写程序试了一下,在编译的时候报错
use of internal package github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protoutil not allowed
想请问您,是不是 fabric-sdk-go不允许调用他下面 internal 中的包
这是Go的特性,internal代表只允许本模块使用,其他模块无法使用
之前 fabric-sdk-go 在他的 third_party 下是有包支持获取timestamp的,不过后来移除掉了。这样的话那是不是就无法获取timestamp了?
可以想想办法找其他地方的接口
已经解决了,仿照之前版本中提供的方法重新写了一下就可以获取到了。我才接触fabric没多久,有好多知识还需要学习,非常感谢您的解惑,谢谢。