首页 > 解决方案 > How retrieve all block transactions in the Hyperledger fabric?

问题描述

As you know there is chance to have multiple transaction in one block , depend on the batch size and orderer configuration. I need to make only one call to return all transaction inside the block not one by one.

I could retrieve one transaction with queryTransaction by using fabric SDK. like

let response_payload = await channel.queryTransaction(trxnID, peer);

First Approach: implement a chanincode function and pass the block number which comes from eventHub along the method then inside the chaincode retrieve all transaction Ids and then make a query to find all transaction then stitch all together as result.

Second Approach: retrieve the block inside with fabric sdk then parse all signed proposal in the payload of the block content.

Third Approach: retrieve the block inside with fabric sdk then retrieve the transaction ids or keys in the payload and then make a couch db query to retrieve all content .

Which approach do you think is more reasonable if not what is your suggestion?

标签: hyperledger-fabrichyperledger

解决方案


如果您的客户端设置正确,则应该有一个

LedgerClient它具有类似的功能

QueryBlock(blockNumber uint64, options ...ledger.RequestOption) (*common.Block, error)

获得块后,您可以从中提取数据

block, _ := QueryBlock(37)
data := block.GetData().GetData()

data是一个[][]byte,每个条目是一个事务。


推荐阅读