博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hyperledger Fabric 客户端开发五
阅读量:6888 次
发布时间:2019-06-27

本文共 1881 字,大约阅读时间需要 6 分钟。

hot3.png

这里介绍Chaincode的查询功能, 从前面的介绍得知, Fabric SDK提供了多种查询功能, 具体包括Channel, Block, Transaction, Chaincode 等信息, 而这个功能, 都是通过Channel对象实现的。

因此, 首先创建channel对象。

// setup the fabric networkvar channel = fabric_client.newChannel('mychannel');var peer = fabric_client.newPeer('grpc://localhost:7051');channel.addPeer(peer);

然后调用channel的方法实现相应的查询及其其他功能。例如使用queryByChaincode来查询Blockchain中存储的数据。

// queryCar chaincode function - requires 1 argument, ex: args: ['CAR4'],        // queryAllCars chaincode function - requires no arguments , ex: args: [''],        const request = {                //targets : --- letting this default to the peers assigned to the channel                chaincodeId: 'fabcar',                fcn: 'queryAllCars',                args: ['']        };        // send the query proposal to the peer        return channel.queryByChaincode(request);}).then((query_responses) => {        console.log("Query has completed, checking results");        // query_responses could have more than one  results if there multiple peers were used as targets        if (query_responses && query_responses.length == 1) {                if (query_responses[0] instanceof Error) {                        console.error("error from query = ", query_responses[0]);                } else {                        console.log("Response is ", query_responses[0].toString());                }        } else {                console.log("No payloads were returned from query");        }

关于queryByChaincode方法的具体文档见:。其他关于Channel的文档见:  。

 

此外, Channel 还提供了几个比较常用的用于查询的方法:

queryBlock(blockNumber, target, useAdmin, skipDecode)

queryBlockByHash(block, target, useAdmin, skipDecode)

queryBlockByTxID(tx_id, target, useAdmin, skipDecode)

 

queryTransaction(tx_id, target, useAdmin, skipDecode)

 

queryInstantiatedChaincodes(target, useAdmin)

使用以上几个方法, 可以帮助查看Blockchain的状态。

转载于:https://my.oschina.net/kingwjb/blog/1861496

你可能感兴趣的文章
java的强制类型转换想到的
查看>>
简要介绍cookie与session的区别与联系
查看>>
mysql flush用法
查看>>
response.setHeader()的用法
查看>>
一位前辈的经验,给正在思考的自己
查看>>
分享一篇关于lucene原理的文章
查看>>
基于 HTML5 结合互联网+ 的 3D 隧道
查看>>
Win10下 80端口被system(pid=4)占用的解决方法
查看>>
使用SubVersion+TortoiseSVN多仓库方式进行版本控制
查看>>
Nginx虚拟目录alias和root目录
查看>>
MySQL(Extends)
查看>>
Android KeyboardView实现App内置键盘开发
查看>>
解决iOS因为网络卡顿点击button或者cell多次push的bug
查看>>
iOS-应用跳转
查看>>
怎么使用Vin码识别sdk/车架号识别sdk?
查看>>
实现许多图片编辑软件都支持的“填充颜色”功能
查看>>
鼠标点击后,所有div掉下来
查看>>
十二年IT职业生涯心得--致我们终将逝去的青春(连载)
查看>>
我的友情链接
查看>>
初学Redis(2)——用Redis作为Mysql数据库的缓存
查看>>