https://lists.hyperledger.org/g/composer/message/125
开头放IBM大佬写的话,composer团队已经去做fabric的开发了。
?
启动和停止Hyperledger Fabric
您可以使用一组脚本控制运行时,~/fabric-dev-servers如果您遵循建议的默认值,则可以找到这些脚本。
第一次启动新运行时,您需要运行启动脚本,然后生成PeerAdmin卡:
cd ~/fabric-dev-servers
export FABRIC_VERSION=hlfv11
./startFabric.sh
./createPeerAdminCard.sh
这里第二句export的意思是设置启动的版本。有hlfv1、hlfv11、hlfv12.具体区别我不太记得了。
您可以使用启动和停止运行时
~/fabric-dev-servers/stopFabric.sh,
然后再次启动它
~/fabric-dev-servers/startFabric.sh。
在开发会议结束时,您运行
~/fabric-dev-servers/stopFabric.sh,
然后
~/fabric-dev-servers/teardownFabric.sh。
请注意,如果您运行拆卸脚本,则下次启动运行时时,您需要创建一个新的PeerAdmin卡,就像您第一次启动时一样。
【实验证明,teardownFabric并不会删掉你的card和链码。还是说我不明白官方的意思?这个下午我重装了images。使用的是teardownAllFabric这个脚本本】
【我必须振作起来,不能丧,不要老是讲丧气话,要给自己打气】
题外话。
要运行playground很简单。
在bash下面输入:
composer-playground
即可。
唉。
playground的作用是测试你的model、transaction还有ACL,其实还挺好的。
只需要打包成bna,之后apply到playground就可以了。
这里有点说明。
https://hyperledger.github.io/composer/v0.19/playground/playground-index
打包成bna 用
composer archive create --sourceType dir --sourceName ../
这个注意是在你的项目目录下的文件夹中。教程是把bna放在项目目录中的dist文件夹里面。bash需要进入到dist目录下再运行上面那条命令。
然后在playground里面导入bna文件,deploy即可。
NB,我docker都重新下载了啊,为啥原来的card啥的都还在啊。
迷诶。
(1)创建一个project
yo hyperledger-composer
输入这个命令,在你的工作目录下面创建一个新的项目。
cielo@cielo-ThinkPad-E550:~/cprogrames$ yo hyperledger-composer
Welcome to the Hyperledger Composer project generator
? Please select the type of project: Business Network
You can run this generator using: 'yo hyperledger-composer:businessnetwork'
Welcome to the business network generator
? Business network name: airlinev10
? Description: this is the airlinev10
? Author name: cielo
? Author email: 手动打码
? License: Apache-2.0
? Namespace: org.acme.airline.aircraft
? Do you want to generate an empty template network? Yes: generate an empty template network
create package.json
create README.md
create models/org.acme.airline.aircraft.cto
create permissions.acl
create .eslintrc.yml
如上,我创建了一个空的business network application。
不过你们要测试的话弄一个不空的吧。
接下来archive install start三连。
composer archive create --sourceType dir --sourceName ../
composer network install -a ./[email protected] -c PeerAdmin@hlfv1
composer network start -n test-bna -c PeerAdmin@hlfv1 -V 0.0.2 -A admin -S adminpw
看!这个dev开头的container才是对的container!我之前生成的到底是什么!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
都succeed之后,会随着项目生成一个admin card,在当前目录下面。
之后需要import一下这个card。
cielo@cielo-ThinkPad-E550:~/cprogrames/test-bna/dist$ composer card import -f [email protected]
composer-rest-server -c admin@airlinev8 -n always -w true
正确运行结果:
cielo@cielo-ThinkPad-E550:~/cprogrames/test-bna/dist$ composer-rest-server -c admin@test-bna -n always -w true
Discovering types from business network definition ...
Discovering the Returning Transactions..
Discovered types from business network definition
Generating schemas for all types in business network definition ...
Generated schemas for all types in business network definition
Adding schemas for all types to Loopback ...
Added schemas for all types to Loopback
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
有angular程序的,在angular的文件夹里面 ng serve一下就ok。
成功的命令行的样子。
cielo@cielo-ThinkPad-E550:~/cprogrames/test-bna/angular-test$ ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-04-17T10:26:54.200Z
Hash: d00d7186277861054414
Time: 33716ms
chunk {main} main.js, main.js.map (main) 550 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 437 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 402 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 987 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.69 MB [initial] [rendered]
ℹ 「wdm」: Compiled successfully.
# org.acme.airline
# Airline v9
https://hyperledger.github.io/composer/reference/acl_language.html
Refer to lecture on Access Control Language
#1 Create the BNA archive
composer archive create --sourceType dir --sourceName ../
#2.1 Install the archive
composer network install -a ./[email protected] -c PeerAdmin@hlfv
#2.2 Strart the network
composer network start -n airlinev9 -c PeerAdmin@hlfv1 -V 0.0.1 -A admin -S adminpw
admin>> org.hyperledger.composer.system.NetworkAdmin#admin
#3 DO NOT - Import the card
composer card delete -n admin@airlinev9
composer card import -f [email protected]
#4 Add a new participants
- John Doe (johnd) is the Network Administrator
composer participant add -d '{"$class":"org.acme.airline.participant.ACMENetworkAdmin","participantKey":"johnd","contact":{"$class":"org.acme.airline.participant.Contact","fName":"John","lname":"Doe","email":"[email protected]"}}' -c admin@airlinev9
- Will Smith (wills) works in the Logistics department
composer participant add -d '{"$class":"org.acme.airline.participant.ACMEPersonnel","participantKey":"wills","contact":{"$class":"org.acme.airline.participant.Contact","fName":"Will","lname":"Smith","email":"[email protected]"}, "department":"Logistics"}' -c admin@airlinev9
#5 Issue the identities
composer identity issue -u johnd -a org.acme.airline.participant.ACMENetworkAdmin#johnd -c admin@airlinev9
composer card delete -n johnd@airlinev9
composer card import -f [email protected]
composer identity issue -u wills -a org.acme.airline.participant.ACMEPersonnel#wills -c admin@airlinev9
composer card delete -n wills@airlinev9
composer card import -f [email protected]
#6 Ping BNA using the johnd & wills cards
- composer network ping -c johnd@airlinev9
- composer network ping -c wills@airlinev9
#6 Setup the permissions.acl
- johnd Is the Network Administrator for airlinev9
Should be able to execute network commands
- wills Works for the Logistics department
Should NOT be able to execute any network command
#7 Rebuild the archive
composer archive create --sourceType dir --sourceName ../
#8 Update the Network
composer network upgrade -n -V -c
composer network update -a ./[email protected] -c admin@airlinev9
composer-rest-server -c johnd@airlinev9 -n always -w true