首页 > 网络 > 云计算 > 正文
使用Postman开发BlockchainNetwork之Chaincode(智能合约)
2016-09-26       个评论      
收藏    我要投稿

使用 Postman 开发 Blockchain Network之 Chaincode (智能合约)

在开发区块链 (blockchain)之智能合约 (chaincode) 时,可以使用在 local machine 所建立或是Bluemix Blockchain service所提供的 Blockchain Network ,为了避免在建立local blockchain network 时所引发的挫折感,可先由IBM 所提供的 Blockchain service 切入(Blockchain Network 已事先建好) ;在测试 chaincode 都是使用 REST API; IBM blockchain service也提供了测试chaincode的工具(Swagger API),若觉得不好用,可以使用 Google 所提供的Postman;以下范例是在 Postman 使用REST API 测试 chaincode。

开发环境:Win7 (64 bit) ,Bluemix , Blockchain, Google Postman

1. 登录IBM Bluemix:https://console.ng.bluemix.net/ 点选 Sign Up; 注册后登 录 (30天试用期免费) 将 username及 password 记录。

 

\

 

建立 Organization 名称

 

\

 

建立 Space 名称 Organization, Space Region (US South)

 

\

 

2. 点选型录 (CATALOG) =>选择 [Blockchain IBM BETA] 服务

 

\

 

3. Service name: myblockchain => CREATE

 

\

 

4. 点选 Service Crendentials (记录 Service Crendentials 内容如附录 1)

 

\

 

5. 建立 github账号

登入github 建立账号 (https://github.com/ 纪录 username 及 password) 安装范例 learn-chaincode

浏览器:https://github.com/IBM-Blockchain/learn-chaincode (点选 fork )

 

\

 

6. 确认learn-chaincode 已 clone 至你的 repository, 在Bluemix blockchainservice 环境必须使用安装在 github 内之 chaincode.

 

\

 

7. 在 win7下载安装 Postman (Postman-win64-4.7.1-Setup.exe) https://www.getpostman.com/apps

 

\

 

8. 安装文件执行后桌面显示 [Postman] 图示并启动注册

 

\

 

9. [Postman]启动后点选 [import]

 

\

 

10. 选择汇入档案Blockchain.postman_collection_chen.json (blockchain样板,附录 2)

 

\

 

汇入后内容, User 可根据步骤 4自建的Service Crendentials 修正内容

 

\

 

11. 点选 post /register (login) [User 至 vp1 (validating peer 1) 注册登录]:填写 REST API (以下为样板)

{

"enrollId": "user_type1_274d12e38f",

"enrollSecret": "85af9da5d9"

}

 

\

 

回复 login success

 

\

 

12.显示 blockchain network VP (validating peer) 内容

 

\

 

13. 点选 post /blockchain (deploy) 填写 REST API 将 github之 chaincode_finished.go deploy至 VP1,执行init function args=”hello rhere”

path: https://github.com/xxxxxxx/learn-chaincode/finished (根据步骤6修改)

 

\

 

14. 传回 chaincode ID (128 character)

若要执行已安装在 peer之 chaincode 则参考 chaincode ID 即可

 

\

 

15. 点选 post /blockchain (query) 填写 REST API 呼叫chaincode_finished.go read function args=”hello_world”

 

\

 

16. 回应”hello there”是先前chaincode deploy的结果,即[key value of hello_world]设定为 “hello there”

 

\

 

17. 点选 post /blockchain (invoke) 填写 REST API 呼叫chaincode_finished.go,invoke function args=”hello_world”,”go away”

 

\

 

回应如下

 

\

 

18. 重复步骤 15点选 post /blockchain (query) 填写 REST API 呼叫 chaincode_finished.go query function args=”hello_world”; 点选 [send] ,此时 [key value of hello_world] 设定已改为 “go way”

 

\

 

19. postman 具有user friendly的使用接口,比Bluemix 内建的Swagger API 好用。

附录:

1.blockchain service 之 Service Crendentials 之内容 (样板格式)

{

“credentials”: {

“peers”: [

{

“discovery_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp0.us.blockchain.ibm.com”,

“discovery_port”: 30303,

“api_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp0.us.blockchain.ibm.com”,

“api_port_tls”: 443,

“api_port”: 443,

“type”: “peer”,

“network_id”: “a42168d2-2d4b-4a09-af38-af73efbfc091”,

“container_id”: “86fb78ab9aa4fb11d9d1b8bd92c6d160afe6661d228430202a5ec675cbcfa41a”,

“id”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp0”,

“api_url”: “http://a42168d2-2d4b-4a09-af38-af73efbfc091_vp0.us.blockchain.ibm.com:443”

},

{

“discovery_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp1.us.blockchain.ibm.com”,

“discovery_port”: 30303,

“api_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp1.us.blockchain.ibm.com”,

“api_port_tls”: 443,

“api_port”: 443,

“type”: “peer”,

“network_id”: “a42168d2-2d4b-4a09-af38-af73efbfc091”,

“container_id”: “8d05a97ec08b7556d5716dc176acb611abdf0cb56d58c8307fd320ce81c4cc51”,

“id”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp1”,

“api_url”: “http://a42168d2-2d4b-4a09-af38-af73efbfc091_vp1.us.blockchain.ibm.com:443”

},

{

“discovery_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp2.us.blockchain.ibm.com”,

“discovery_port”: 30303,

“api_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp2.us.blockchain.ibm.com”,

“api_port_tls”: 443,

“api_port”: 443,

“type”: “peer”,

“network_id”: “a42168d2-2d4b-4a09-af38-af73efbfc091”,

“container_id”: “feb00576275c0875dfffdfbb6467d06e716a60939883095ea190955405741d1a”,

“id”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp2”,

“api_url”: “http://a42168d2-2d4b-4a09-af38-af73efbfc091_vp2.us.blockchain.ibm.com:443”

},

{

“discovery_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp3.us.blockchain.ibm.com”,

“discovery_port”: 30303,

“api_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp3.us.blockchain.ibm.com”,

“api_port_tls”: 443,

“api_port”: 443,

“type”: “peer”,

“network_id”: “a42168d2-2d4b-4a09-af38-af73efbfc091”,

“container_id”: “6dc096f0443c5f6306bb69c1e033617a5de034c0c2296336fe33fa06adb77272”,

“id”: “a42168d2-2d4b-4a09-af38-af73efbfc091_vp3”,

“api_url”: “http://a42168d2-2d4b-4a09-af38-af73efbfc091_vp3.us.blockchain.ibm.com:443”

}

],

“ca”: {

“a42168d2-2d4b-4a09-af38-af73efbfc091_ca”: {

“url”: “a42168d2-2d4b-4a09-af38-af73efbfc091_ca.us.blockchain.ibm.com:30303”,

“discovery_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_ca.us.blockchain.ibm.com”,

“discovery_port”: 30303,

“api_host”: “a42168d2-2d4b-4a09-af38-af73efbfc091_ca.us.blockchain.ibm.com”,

“api_port_tls”: 30303,

“api_port”: 443,

“type”: “ca”,

“network_id”: “a42168d2-2d4b-4a09-af38-af73efbfc091”,

“container_id”: “74f8a8e89da5e3241c1042f9eab92c4bc2a83da9415e3412894dda984ce02315”

}

},

“users”: [

{

“username”: “admin”,

“secret”: “67415ec617”,

“enrollId”: “admin”,

“enrollSecret”: “67415ec617”

},

{

“username”: “WebAppAdmin”,

“secret”: “2de6e569fb”,

“enrollId”: “WebAppAdmin”,

“enrollSecret”: “2de6e569fb”

},

{

“username”: “user_type1_274d12e38f”,

“secret”: “85af9da5d9”,

“enrollId”: “user_type1_274d12e38f”,

“enrollSecret”: “85af9da5d9”

},

{

“username”: “user_type1_d22e381b83”,

“secret”: “4c5c6599ac”,

“enrollId”: “user_type1_d22e381b83”,

“enrollSecret”: “4c5c6599ac”

},

{

“username”: “user_type1_1c0f15ca44”,

“secret”: “7d6bb4aab5”,

“enrollId”: “user_type1_1c0f15ca44”,

“enrollSecret”: “7d6bb4aab5”

},

{

“username”: “user_type1_0e5e244982”,

“secret”: “f3c8a447d5”,

“enrollId”: “user_type1_0e5e244982”,

“enrollSecret”: “f3c8a447d5”

},

{

“username”: “user_type1_b122fc510b”,

“secret”: “7a75368a80”,

“enrollId”: “user_type1_b122fc510b”,

“enrollSecret”: “7a75368a80”

},

{

“username”: “user_type2_e9016322bc”,

“secret”: “8d274e1609”,

“enrollId”: “user_type2_e9016322bc”,

“enrollSecret”: “8d274e1609”

},

{

“username”: “user_type2_31099e3ee5”,

“secret”: “b47332934e”,

“enrollId”: “user_type2_31099e3ee5”,

“enrollSecret”: “b47332934e”

},

{

“username”: “user_type2_45825d2b2a”,

“secret”: “930a499b56”,

“enrollId”: “user_type2_45825d2b2a”,

“enrollSecret”: “930a499b56”

},

{

“username”: “user_type2_6f2ae3c26f”,

“secret”: “d88055d3ef”,

“enrollId”: “user_type2_6f2ae3c26f”,

“enrollSecret”: “d88055d3ef”

},

{

“username”: “user_type2_3342cc39bf”,

“secret”: “5865bcbcf8”,

“enrollId”: “user_type2_3342cc39bf”,

“enrollSecret”: “5865bcbcf8”

},

{

“username”: “user_type4_5848eeb539”,

“secret”: “962f57f521”,

“enrollId”: “user_type4_5848eeb539”,

“enrollSecret”: “962f57f521”

},

{

“username”: “user_type4_6fc69c0d81”,

“secret”: “405275781c”,

“enrollId”: “user_type4_6fc69c0d81”,

“enrollSecret”: “405275781c”

},

{

“username”: “user_type4_a9d38e8e82”,

“secret”: “1d6da1c441”,

“enrollId”: “user_type4_a9d38e8e82”,

“enrollSecret”: “1d6da1c441”

},

{

“username”: “user_type4_aad9112619”,

“secret”: “1b2c2c9790”,

“enrollId”: “user_type4_aad9112619”,

“enrollSecret”: “1b2c2c9790”

},

{

“username”: “user_type4_2c87866824”,

“secret”: “bde437fce6”,

“enrollId”: “user_type4_2c87866824”,

“enrollSecret”: “bde437fce6”

},

{

“username”: “user_type8_43aca18a98”,

“secret”: “8e7874e6ef”,

“enrollId”: “user_type8_43aca18a98”,

“enrollSecret”: “8e7874e6ef”

},

{

“username”: “user_type8_f9ae482f40”,

“secret”: “85fc476f56”,

“enrollId”: “user_type8_f9ae482f40”,

“enrollSecret”: “85fc476f56”

},

{

“username”: “user_type8_d0218d5be8”,

“secret”: “e8ab9d3d32”,

“enrollId”: “user_type8_d0218d5be8”,

“enrollSecret”: “e8ab9d3d32”

},

{

“username”: “user_type8_8c4c2accb8”,

“secret”: “b0411b5e58”,

“enrollId”: “user_type8_8c4c2accb8”,

“enrollSecret”: “b0411b5e58”

},

{

“username”: “user_type8_fcfc0208a8”,

“secret”: “a7f6c12607”,

“enrollId”: “user_type8_fcfc0208a8”,

“enrollSecret”: “a7f6c12607”

}

],

“cert”: “https://blockchain-certs.mybluemix.net/us.blockchain.ibm.com.cert”

}

}

点击复制链接 与好友分享!回本站首页
上一篇:【Consul】多数据中心
下一篇:最后一页
相关文章
图文推荐
文章
推荐
热门新闻

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训
版权所有: 红黑联盟--致力于做实用的IT技术学习网站