Tit*_*ese 5 go hyperledger hyperledger-fabric
我曾经使用 Fabric 和 Fabric GoLang SDK 设置 Fabric 网络并部署了 Fabric 网络和基本应用程序。我能够执行查询并写入链。有没有办法检索块信息?像块高度和当前哈希?
+ I'm unable to find out a documentation for GoLang Fabric SDK.
Run Code Online (Sandbox Code Playgroud)
我遵循以下代码和教程,
Fabric 基础应用程序 - 教程 https://chainhero.io/2017/07/tutorial-build-blockchain-app/
使用 GoLang SDK 的 Fabric 基本应用程序 - 代码 https://github.com/chainHero/heroes-service/
GoLang SDK - 官方 SDK https://github.com/hyperledger/fabric-sdk-go
一般sdk都会提供你说的GetBlockInfo的基本方法,我搜索了GoLang SDK,找不到。虽然 Java sdk 提供了这种方法,但请参考此 java 测试。
使用这些方法的另一种方式(你必须知道一点fabric源代码),实际上这些方法都包含在系统链码中,你可以像调用普通链码一样调用系统chancode。
一个例子如下: 从 go sdk 测试,你可以看到这个,
response, err := chClient.Query(chclient.Request{ChaincodeID: ccID, Fcn: "invoke", Args: integration.ExampleCCQueryArgs()})
Run Code Online (Sandbox Code Playgroud)
只需更改参数
response, err := chClient.Query(chclient.Request{ChaincodeID: "qscc", Fcn: "invoke", Args: integration.ExampleCCQueryArgs("GetChainInfo")})
Run Code Online (Sandbox Code Playgroud)
qscc是一个系统chancode,你可以下载fabric源码,从qscc文件中可以看到(它提供了很多调用服务):
GetChainInfo string = "GetChainInfo"
GetBlockByNumber string = "GetBlockByNumber"
GetBlockByHash string = "GetBlockByHash"
GetTransactionByID string = "GetTransactionByID"
GetBlockByTxID string = "GetBlockByTxID"
Run Code Online (Sandbox Code Playgroud)