Email:[email protected](https://cygwin.com/install.html)
(https://www.virtualbox.org/)
进入Win7 command shell:
$
mkdir -p d:\GoProjects\src\github.com\hyperledger
$
cd d:\GoProjects\src\github.com\hyperledger
$
git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric (0.6 release)
$
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
修正 :
vb.name = “hyperledger” (hyperledger 为 virtualbox 虚拟机器名称)
$vagrant up (第一次在 virtual box 产生虚拟机器 hyperledger需要一段时间)
$
nvm use 6.7.0 (选择 node 版本)
$
node -v
v6.7.0
$ npm -v
3.10.3
$
go version (go version go1.6 linux/amd64)
$
git version (git version 1.9.1)
hyperledger挂载点 ($GOPATH/src/github.com/hyperledger/fabric)
已挂载 win 7 local machine目录
(d:\GoProjects\src\github.com\hyperledger\fabric)
可用 touch 指令新增 empty file (例如 touch abcd) 测试是否挂载成功
$cd /opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
$go build . (若 ok 则不会显示任何文字)
$ ls (显示输出chaincode_example02)
建立 github账号 (chenlinx)
登入github 建立账号 (https://github.com/ 纪录 username 及 password)
进入网址: https://github.com/IBM-Blockchain/learn-chaincode
点选fork
$GOPATH
$echo $GOPATH
/opt/gopath
$mkdir -p src/github.com/chenlinx/
$ cd src/github.com/chenlinx/
$ git clone -b v2.0 https://github.com/chenlinx/learn-chaincode.git
learn-chaincode共有 2 版本:
start: chaincode_start.go 骨架(开发用)
finished:已开发完成之chaincode
根据finished/chaincode_finished.go 修正chaincode_start.go
$cd $GOPATH/src/github.com/chenlinx/learn-chaincode/start
$go build ./ (若 ok 则不会显示任何文字)
$cd $GOPATH/src/github.com/chenlinx/learn-chaincode
$ git add start/chaincode_start.go
$ git commit -m "Compiled my code"
$ git push
chaincode 依据
/opt/gopath/src github.com/hyperledger/fabric/core/chaincode/shim
数据夹内定义的接口程序(.go)与分类帐交谈。
postman使用请参考: https://1drv.ms/b/s!AkBmzWP0h-Vxggw_dTKAaBXHNKah
//编辑 docker-compose.yml (文字要对齐)
membersrvc:
image: hyperledger/fabric-membersrvc
ports:
- "7054:7054"
command: membersrvc
vp0:
image: hyperledger/fabric-peer
ports:
- "7050:7050"
- "7051:7051"
- "7053:7053"
environment:
- CORE_PEER_ADDRESSAUTODETECT=true
- CORE_VM_ENDPOINT=unix:///var/run/docker.sock
- CORE_LOGGING_LEVEL=DEBUG
- CORE_PEER_ID=vp0
- CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
- CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
- CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
- CORE_SECURITY_ENABLED=true
- CORE_SECURITY_ENROLLID=test_vp0
- CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
links:
- membersrvc
command: sh -c "sleep 5; peer node start --peer-chaincodedev"
$docker-compose up -d
$ docker ps
$ cd $GOPATH/src/github.com/chenlinx/learn-chaincode/start
$ export CORE_CHAINCODE_ID_NAME=mycc
$ export CORE_PEER_ADDRESS=0.0.0.0:7051
$ ./start &
REST API字段输入:http://127.0.0.1:7050/network/peers
7050定义于docker-compose.yml
REST API字段输入: http://127.0.0.1:7050/registrar
{
"enrollId": "jim",
"enrollSecret": "6avZQLwcUe9b"
}
REST API字段输入: http://127.0.0.1:7050/chcincode
执行init function args:["hello_world"]
{
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"name" : "mycc"
},
"ctorMsg": {
"function": "init",
"args": [
"hello_world"
]
},
"secureContext": "jim"
},
"id": 1
}
设定为
REST API字段输入: http://127.0.01:7050/chcincode
执行 invoke function args:[” “hello_world”, “go away”]
{
“jsonrpc”: “2.0”,
“method”: “invoke”,
“params”: {
“type”: 1,
“chaincodeID”: {
“name”: “mycc”
},
“ctorMsg”: {
“function”: “write”,
“args”: [
“hello_world”,
“go away”
]
},
“secureContext”: “jim”
},
“id”: 3
}
key 之 value 是否为 go awayREST API字段输入: http://127.0.0.1:7050/chcincode
执行 function:query, args:[” hello_world “]
{
“jsonrpc”: “2.0”,
“method”: “query”,
“params”: {
“type”: 1,
“chaincodeID”: {
“name”: “mycc”
},
“ctorMsg”: {
“function”: “read”,
“args”: [
“hello_world”
]
},
“secureContext”: “jim”
},
“id”: 4
}
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..陈兆麟 facebook
https://zh-cn.facebook.com/chaolin.chen.18
1.https://github.com/IBM-Blockchain/learn-chaincode
2.https://github.com/IBM-Blockchain/learn-chaincode/blob/master/docs/setup.md
3.https://github.com/hyperledger/fabric/blob/master/docs/Setup/Chaincode-setup.md
4.https://github.com/IBM-Blockchain/chaincode-investigator
5.https://github.com/hyperledger/fabric/blob/master/docs/protocol-spec.md#3321-chaincode-deploy
6.https://github.com/IBM-Blockchain/learn-chaincode/blob/master/README_zh-cn.md
7.https://yeasy.gitbooks.io/blockchain_guide/content/hyperledger/chaincode.html
8.https://yeasy.gitbooks.io/blockchain_guide/content/hyperledger/chaincode.html
9.https://1drv.ms/f/s!AkBmzWP0h-Vxbr7h1uTNsTMcPWI
10.https://1drv.ms/b/s!AkBmzWP0h-VxazOBOsVz8nGMLpM
11.https://1drv.ms/b/s!AkBmzWP0h-VxbLK7FOjH9IL5HHc
12.https://www.youtube.com/watch?v=24JAF9Eu1mk&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=74
13.https://www.youtube.com/watch?v=wSmJ-rwUo8I&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=73
14.https://www.youtube.com/watch?v=SOsn6MvGH60&list=UUOTZe-b_jE_Ovy9K9UhZ4BA&index=72