在 Win7 环境使用 hyperledger fabric source code 模拟 IBM Bluemix Blockchain Service
来源:互联网 发布:电脑手写板软件下载 编辑:程序博客网 时间:2024/05/16 23:44
在 Win7 环境使用 hyperledger/fabric source code 模拟 IBM Bluemix Blockchain Service
作者:陳兆麟
Email:chenlin2@ms9.hinet.net
当美国联准会(Fed)主席叶伦力挺区块链 (blockchain) 后,区块链如野火燎原般风靡了整个地球,它将改变人类传统生活习惯;唯一 IBM bluemix所提供的 bloclcahain service 最近几乎塞到爆,常出现用量超出负荷的讯息,幸好IBM佛心提供了4 万行 hyperledger/fabric source code如果没有这些 source code, 区块链的应用将会被口袋深的大厂把持;目前企业只要有支持 Docker 云端平台都可以自行开发区块链的应用系统,有兴趣的企业可私讯联系共同开发。以下范例是以 hyperledger/fabric source code在local machine 仿真 IBM Bluemix bloclcahain service 的功能,也就是不必登录至 IBM bluemix 就可以执行IBM 所提供的範例blockchain marbles。
開發環境:Win7 (64 bit, RAM >=8G) , vagrant , blockchain, docker,golang
1. win7 安装 cygwin (https://cygwin.com/install.html)
将安装之执行文件目录 (C:\cygwin64\bin) 设定在控制台系统 path 变量
win7 安装 virtualbox (VirtualBox-5.1.6-110634-Win.exe) (https://www.virtualbox.org/)
win7 安装 git (https://git-scm.com/downloads)
2.建立 github账号
登入github 建立账号 (https://github.com/ 纪录 username 及 password)
fork hyperledger/fabric
浏览器入以下网址:
https://github.com/hyperledger/fabric/blob/master/docs/Gerrit/gerrit.md#Working-with-a-local-clone-of-the-repository
(点选 fork )
3. 确认 fabric 安装至你的 guthub repository,
4.将 xxxxxx/fabric clone 至 Win7 local machine
进入Win7 command shell:
$mkdir -p d:\GoProjects\src\github.com\hyperledger
$cd d:\GoProjects\src\github.com\hyperledger
$git clone https://github.com/xxxxxxx/fabric
$cd d:\GoProjects\src\github.com\hyperledger\fabric\devenv
修正 Vagrantfile (D:\GoProjects\src\github.com\hyperledger\fabric\devenv)
新增 :
config.vm.network “forwarded_port”, guest: 22, host: 22
config.vm.network “forwarded_port”, guest: 3000, host: 3000
$vagrant up (第一次在 virtual box 产生虚拟机器 hyperledger需要一段时间)
5.使用 putty (附录 1) 登录 hyperledger VM
(username: vagrant,password:vagrant)
6.在hyperledger VM 使用 nvm 安装 node 最新版 (参考附录 2)
$ nvm use 6.7.0 (选择 node 版本)
$ node -v
v6.7.0
$ npm -v
3.10.3
7. 验证hyperledger已挂载 Win7 目录
hyperledger挂载点 ($GOPATH/src/github.com/hyperledger/fabric)
已挂载 win 7 local machine目录(d:\GoProjects\src\github.com\hyperledger\fabric)
可用 touch 指令新增 empty file (例如 touch abcd) 测试是否挂载成功
8. 下载编辑 marbles 范例相关档案
将 marbles 范例安装至local machine (https://github.com/IBM-Blockchain/marbles)
cd GOPATH/src/github.com/hyperledger/fabric
$ git clone https://github.com/IBM-Blockchain/marbles.git
$ cd marbles
将附录 3之app.js, mycreds.json覆盖原先档案,因不使用bluemix blockchain
service,就必须使用hyperledger chaincode,先将marbles-chaincode fork至
我的repository, 再clone至hyperledger VM,修改以下档案:
(*shim.ChaincodeStub 修正 shim.ChaincodeStubInterface)
https://github.com/chenlin2/marbles-chaincode/tree/master/hyperledger/part1/part1_chaincode.go
https://github.com/chenlin2/marbles-chaincode/tree/master/hyperledger/part2/part2_chaincode.go
修改后再回存至我的 github repository。以下 app.js 所含zip_url,git_url
已修正为 chenlin2/marbles-chaincode (不可使用系统默认值,user可尝试使用
自己的github repository)
IBM-Blockchain/marbles-chaincode fork 至 user repository
marbles-chaincode下载经 hyperledger VM修改后上传的chaincode
9. 在hyperledger VM 建立 node vp0,vp1 (以 putty 重新开启另一 terminal)
mkdir GOPATH/src/github.com/hyperledger/fabric/vagrant_marbles
cd GOPATH/src/github.com/hyperledger/fabric/vagrant_marbles
$ docker pull hyperledger/fabric-baseimage:x86_64-0.1.0
$ docker images (记录 image id: db53d04b117c)
$ docker tag db53d04b117c hyperledger/fabric-baseimage:latest(更改 tag)
$ docker images (验证 hyperledger/fabric-baseimage:latest)
$ vi docker-compose.yaml (编辑 docker-compose.yaml如附件 3)
$ docker-compose up (过程需要 hyperledger/fabric-baseimage:latest)
10 执行 marbles 范例 (另一 terminal)
cd GOPATH/src/github.com/hyperledger/fabric/marbles
$sudo npm install gulp -g (安装 gulp 套件)
$sudo npm install (根据package.json 在node modules数据夹安装 dependences)
以上执行若无错误则执行 $gulp (执行 gulpfile.js 内所定义的工作)
sudonpminstall(若发生错误则执行 node app.js)
若 (
有关,请关闭窗口内不必要的程序)
若执行成功出现以下画面
11. 浏览器输入http://localhost:3000, 点选 CREATE (每一步骤代表transaction)
12. 选择 颜色,大小,使用者 => create
13.将Bob’s 之 marble 拖曳置至 Leroy’s
14. 将 Red Mable 拖曳至垃圾桶
15. 浏览器输入http://localhost:3000/p2, (2 peer) 点选 CREATE
Bob 及 Leroy 可建立自己的 marble 并拖曳至另不同 user, 且user可以所持 marble 交易不同颜色的 marble。
16. 指定 User 为 BOB 将 white marble 拖曳至 Leroy’s (非 BOB 无法拖曳)
17. 在 BOB 之下点选 TRADE (交易 marbles 使用)
18. 选择交易对象
19. 显示正在等待的交易,点选 x (删除等待的交易)
20.正在等待的交易将消失
若将 Bob之 red marble 拖曳至垃圾桶, 正在等待的交易也会消失
21. 本例可修改为夺宝游戏
a 可增加参与者人数 ( 2 -> 5)b 建立宝藏库, marble可改为宝物, 每一种宝物都有不同颜色组合, 根据 user所付出劳务的多寡,可至宝藏库换得不同价值的宝物.相同宝物不同颜色全拿,可至宝藏库交换更高价值的宝物,也可与其它参与者交换。c 参予者不积极参与游戏,先前的宝物,将自动退还至宝藏库,积极度的计算与目前所获宝物价值有关,所获宝物愈多,积极度愈严格 (一定时间未取得相对应。d 等级宝物就需退回原有取得之宝物;当所有宝物都被退回,即中止该user 参与取宝游戏)。
22. 夺宝游戏可应用在广告代理商, user 所看广告多寡视为劳务支出,夺宝冠军后可向代理商得现金作为报酬;游戏与个人能力无关; user只要肯花时间看广告就能取得报酬。
附录:
1.Win7 安装 putty
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
http://download.ithome.com.tw/article/index/id/1649
2.hyperledger VM 安装 nvm & node
http://www.liquidweb.com/kb/how-to-install-nvm-node-version-manager-for-node-js-on-ubuntu-14-04-lts/
https://www.liquidweb.com/kb/how-to-install-node-js-via-nvm-node-version-manager-on-ubuntu-14-04-lts/
3.docker-compose.yaml, app.js, mycreds.json
https://1drv.ms/u/s!AkBmzWP0h-VxghFdrcW_nVX1GpgO
4.陈兆麟 facebook
https://zh-cn.facebook.com/chaolin.chen.18
參考文獻:
1.https://github.com/chenlin2/marbles2/blob/master/local_blockchain.md
2.http://www.wealth.com.tw/article_in.aspx?nid=8450
3.https://github.com/hyperledger/fabric/blob/master/docs/dev-setup/devenv.md
4.https://github.com/diegomasini/hyperledger-fabric/blob/master/docs/dev-setup/devnet-setup.md
5.https://github.com/IBM-Blockchain/marbles
6.https://github.com/IBM-Blockchain/learn-chaincode
7.https://github.com/hyperledger/fabric/blob/master/docs/Setup/Network-setup.md
8.https://console.ng.bluemix.net/docs/services/blockchain/ibmblockchain_tutorials.html
9.https://1drv.ms/b/s!AkBmzWP0h-VxggcKD76DVuLZ92ky
10.https://1drv.ms/f/s!AkBmzWP0h-Vxbr7h1uTNsTMcPWI
11.https://1drv.ms/b/s!AkBmzWP0h-VxazOBOsVz8nGMLpM
12.https://1drv.ms/b/s!AkBmzWP0h-VxbLK7FOjH9IL5HHc
13.https://www.youtube.com/watch?v=24JAF9Eu1mk&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=74
14.https://www.youtube.com/watch?v=wSmJ-rwUo8I&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=73
15.https://www.youtube.com/watch?v=SOsn6MvGH60&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=72
- 在 Win7 环境使用 hyperledger fabric source code 模拟 IBM Bluemix Blockchain Service
- 在 Win7 环境使用 Docker Images模拟 IBM Bluemix Blockchain Service
- 在 Win7 使用 hyperledger fabric source code建构 Local Blockchain Network System
- 在Win7使用IBM Bluemix 之Blockchain Service 建立区块链应用App开发环境
- 使用IBM Bluemix Blockchain Service在 Blockchain Network 开发 chaincode
- IBM HyperLedger fabric
- IBM HyperLedger fabric 详解
- IBM HyperLedger fabric基础
- IBM HyperLedger fabric 基础知识
- IBM HyperLedger fabric 详解
- IBM HyperLedger fabric
- IBM区块链BlockChain开源项目Hyperledger/Fabric初体验
- IBM Hyperledger Fabric 开发环境搭建(windows环境)
- 区块链在中国(1):IBM HyperLedger fabric
- 区块链在中国(1):IBM HyperLedger fabric
- 区块链在中国(1):IBM HyperLedger fabric
- Hyperledger Fabric 环境搭建
- 使用 IBM Bluemix 容器构建 Django 环境
- 段时间会尽快速度速度集合圣诞节快发货考试的话
- Daydream VR 开发
- 第二章 2.6 线性表的第三类:纯链表及可能的缺点
- 光的本质(一)之光的产生
- 三天康复颈椎-序言2
- 在 Win7 环境使用 hyperledger fabric source code 模拟 IBM Bluemix Blockchain Service
- 逻辑运算
- 328. Odd Even Linked List
- spring cloud比较不错的文章
- UVA 1325 Hypertransmission(枚举)
- Android-Style样式表
- 关于如何在同一台电脑上的两个安卓模拟器之间的socket通信(图片传输)
- HDU#2304:Electrical Outlets
- HDU#2504:又见GCD