在Win7使用IBM Bluemix 之Blockchain Service 建立区块链应用App开发环境

在Win7使用IBM Bluemix 之Blockchain Service 建立区块链应用App开发环境

作者:陳兆麟 Email:chenlin2@ms9.hinet.net

比特币 (bitcoin) 交易系统使用了区块链 (Blockchain) 的技术, 而IBM支持的 hyperledger project 是一项在Linux Foundation之下开发 Blockchain 技术的开源计划。微软也推出自己的开源计划 Bletchley;Hyperledger项目的目的是要共同建立区块链及分类帐技术的跨产业开放标准,因此以 hyperledger project 作为研究对象。开发 Blockchain 的应用系统最重要者在于建立系统的 Blockchain Network。IBM 为协助 User开发 Blockchain App,已在 Bluemix 提供 Blockchain service ,让开发者无须辛苦建立自己的Blockchain Network,可先在 local测试App 再将其安装至云端平台。Blockchain 可应用在金融交易及物联网系统,因为刚起步,商用系统极为少见,其规模适合研究所实验室团队开发,好点子外加运气,也许毕业后就能开公司。以下为 IBM 所提供的 marbles 范例,每一次移动marble都是一次交易,它以 Bluemix 内之 [Blockchain] Service 建立Blockchain Network, marble App可在本地或云端执行,本例可修改为不同的商业应用系统。

開發環境:Win7 (64 bit) ,Bluemix , Blockchain

1.win7 安装 nodejs, npm (https://nodejs.org/en/ )

$node -v
 v6.5.0
$npm -v
 2.15.9

win7 安装 git (https://git-scm.com/download/win)

$git version
 git version 2.9.3

2.安装超级分类帐(Hyperledger)的垫片码(shim code)

$cd D:\GoProjects
$go get github.com/hyperledger/fabric/core/chaincode/shim

3. 安装范例 marbles App

登入github 建立账号 (https://github.com/)
$https://api.github.com/users/<account name> 取得 githubId
$cd :\GoProjects
$mkdir -p src\github.com\<yourgithubid>\
$cd src\github.com\<yourgithubid>\
$git clone https://github.com/IBM-Blockchain/marbles.git
$ ls src\github.com\<yourgithubid>\

4. 进入IBM Bluemix: https://console.ng.bluemix.net/ 点选 Sign Up

注册后登录 (30天试用期免费) 将 username 及 password 记录

建立 Organization 名称

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

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

6. Service name: myblockchain => CREATE

7. 点选 Service Crendentials (显示 Service Crendentials 内容)

8. 更新 mycreds.json (使用 bluemix 内之blockchain network)

$cd src\github.com\\marbles
$vi mycreds.json (将内容置换为步骤 7 之Service Crendentials)

9. 安装 marbles App 所需之dependences

$npm install gulp -g (安装 gulp 套件)
$npm install (根据 package.json 在node_modules数据夹安装 dependences)

10. 启动 marbles App

$gulp (执行 gulpfile.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. 将 marble app 移至 Bluemix 云端平台执行

$cd src\github.com\<yourgithubid>\marbles
修正manifest.yml  (更名App Name)
name: marbles => name: xxxxxx   
$ cf login -a https://api.ng.bluemix.net (必须与步骤 4 同一 Region)
    API endpoint: https://api.ng.bluemix.net
    Email> liuchenwang1234567xxxx@gmail.com
    Password>
    Authenticating...
    OK
    Targeted org testchen
    Targeted space test
    API endpoint:   https://api.ng.bluemix.net (API version: 2.54.0)
    User:           liuchenwang1234567xxxx@gmail.com
    Org:            testchen
    Space:          test

22. 上传 App至云端平台,并与步骤 6 myblockchain service结合

$ cf push

#0 running 2016-09-06 08:51:47 AM 9.9% 63.2M of 512M 57.8M of 1G
至 Bluemix dashboard 点选 marblexxxx.mybluemix.net

23. 比较云端平台执行 App与 local 执行 App:浏览器显示皆相同 (同一 service)


24. 使用 Bluemix [Blockchain service] 开发 [区块链] App 的优点在于开发者不必建立 [blockchain Network],只要用心在应用程序,可快速开发 App;缺点是必须 依赖此一 service;开发者若要建立自己的[local Blockchain network]可参考:

 https://github.com/hyperledger/fabric/blob/master/docs/Setup/Network-setup.md

测试后再以Docker image 的方式移至云端平台执行。目前 Bluemix [Blockchain service]为Beta版,因使用的人过多,星期六,日常常 crash, User 必须注意。

25. 本例可修改为夺宝游戏

a 可增加参与者人数 ( 2 -> 5)
b 建立宝藏库, marble可改为宝物, 每一种宝物都有不同颜色组合, 根据 user所付出劳务的多寡,可至宝藏库换得不同价值的宝物.相同宝物不同颜色全拿,可至宝藏库交换更高价值的宝物,也可与其它参与者交换。
c 参予者不积极参与游戏,先前的宝物,将自动退还至宝藏库,积极度的计算与目前所获宝物价值有关,所获宝物愈多,积极度愈严格 (一定时间未取得相对应。
d 等级宝物就需退回原有取得之宝物;当所有宝物都被退回,即中止该user 参与取宝游戏)。

26. 夺宝游戏可应用在广告代理商, user 所看广告多寡视为劳务支出,夺宝冠军后可向代理商得现金作为报酬;游戏与个人能力无关; user只要肯花时间看广告就能取得报酬。

附录:

1.putty安装及使用:
http://www.ascc.sinica.edu.tw/putty
2.bluemix 全球系统维护现况
https://developer.ibm.com/bluemix/support/#status
3.Bluemix Command line interfaces (cf)安装
https://github.com/cloudfoundry/cli/releases
4.Bluemix 可选择 Region
api.ng.bluemix.net (US South)
api.eu-gb.bluemix.net (United Kingdom)
api.au-syd.bluemix.net (Sydney)

參考文獻:

1.https://github.com/IBM-Blockchain/marbles
2.https://github.com/IBM-Blockchain/marbles/blob/master/tutorial_part1.md
3.https://github.com/IBM-Blockchain/marbles/blob/master/tutorial_part2.md
4.https://github.com/hyperledger/fabric/blob/master/docs/Setup/Network-setup.md
5.https://console.ng.bluemix.net/docs/services/blockchain/ibmblockchain_tutorials.html
6.https://github.com/IBM-Blockchain/learn-chaincode
7.https://www.gitbook.com/book/kejyuntw/gulp-learning-notes/details
8.https://github.com/ibm-blockchain/marbles-chaincode
9.https://github.com/IBM-Blockchain
10.https://read01.com/x8gRPz.html
11.https://kknews.cc/tech/y2okak.html
12.https://kknews.cc/finance/gzm6py.html
13.https://1drv.ms/f/s!AkBmzWP0h-Vxbr7h1uTNsTMcPWI
14.https://1drv.ms/b/s!AkBmzWP0h-VxazOBOsVz8nGMLpM
15.https://1drv.ms/b/s!AkBmzWP0h-VxbLK7FOjH9IL5HHc
16.https://www.youtube.com/watch?v=24JAF9Eu1mk&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=74
17.https://www.youtube.com/watch?v=wSmJ-rwUo8I&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=73
18.https://www.youtube.com/watch?v=SOsn6MvGH60&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=72

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值