3. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
intro
Hyperledger Composer enables architects and developers to quickly create "full-stack" blockchain
solutions. I.e. business logic that runs on the blockchain, REST APIs that expose the blockchain logic to
web or mobile applications, as well as integrating the blockchain with existing enterprise systems of
record.
source : https://hyperledger.github.io/composer/latest/introduction/solution-architecture.html
20. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
Truck 모델 생성
hyper@hwy:~/fabric-tools/kopodeliverysvc/models$ more org.kopo.deliverysvc.truck.cto
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Write your model definitions here
*/
namespace org.kopo.deliverysvc.truck
participant User identified by email {
o String email
}
asset SampleAsset identified by assetId {
o String assetId
o String value
}
transaction ChangeAssetValue {
o String newValue
--> Asset relatedAsset
}
21. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
Truck 모델 수정
namespace org.kopo.deliverysvc.truck
/** Kopo has truck*/
asset Truck identified by truckId {
o String truckId // truck plate number
o Ownership ownershipType default="OWNED"
o String location // 차고지
o String fee
o Integer status // 0. not departed 100. departed 200. on delivery
o String memo optional
}
enum Ownership {
o LEASED
o OWNED
}
22. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
Participant 모델 생성
namespace org.kopo.deliverysvc.participant
abstract participant KOPOParticipant identified by parcelKey {
o String parcelKey
o String startingPoint
o String endPoint
o String estimatedPrice
o String fee
o Integer status // 0. not departed 100. departed 200. on delivery 300. arrived ...
o String memo optional
}
concept Contact {
o String fName
o String lname
o String email
o String mobile
o String tel
}
participant KOPONetworkAdmin extends KOPOParticipant {
}
participant KOPOCustomer extends KOPOParticipant {
o Contact senderContact
o Contact receiverContact
}
participant KOPOB2BPartner extends KOPOParticipant {
o String kind
}
24. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
CLI Tool의 활용 bna 생성
bna 파일 만들기
mkdir dist
composer archive create -a dist/kopodeliverysvc.bna --sourceType dir --
sourceName .
hyper@hwy:~/fabric-tools/kopodeliverysvc$ composer archive create -a dist/kopodeliverysvc1.bna --sourceType dir --sourceName .
Creating Business Network Archive
Looking for package.json of Business Network Definition
Input directory: /home/hyper/fabric-tools/kopodeliverysvc
Found:
Description: kopo delivery service
Name: kopodeliverysvc
Identifier: kopodeliverysvc@0.0.1
Written Business Network Definition Archive file to
Output file: dist/kopodeliverysvc1.bna
Command succeeded
package.json 이 위치한 경로에서 실행해야 함
46. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~/fabric-tools/kopodeliverysvc$ composer archive create -a dist/kopodeliverysvc.bna --sourceType dir --sourceName .
Creating Business Network Archive
Looking for package.json of Business Network Definition
Input directory: /home/hyper/fabric-tools/kopodeliverysvc
Found:
Description: kopo delivery service
Name: kopodeliverysvc
Identifier: kopodeliverysvc@0.0.1
Written Business Network Definition Archive file to
Output file: dist/kopodeliverysvc.bna
Command succeeded
사전 조건 : ./startFabric.sh 실행
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ pwd
/home/hyper/fabric-tools/kopodeliverysvc/dist
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ ll
total 16
drwxrwxr-x 2 hyper hyper 4096 Sep 27 11:36 ./
drwxrwxr-x 5 hyper hyper 4096 Sep 27 11:34 ../
-rw-rw-r-- 1 hyper hyper 8101 Sep 27 11:35 kopodeliverysvc.bna
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer network install -a ./kopodeliverysvc.bna -c PeerAdmin@hlfv1
✔ Installing business network. This may take a minute...
Successfully installed business network kopodeliverysvc, version 0.0.1
Command succeeded
47. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer network start -n kopodeliverysvc -c PeerAdmin@hlfv1 -V 0.0.1 -A admin -S adminpw
Starting business network kopodeliverysvc at version 0.0.1
Processing these Network Admins:
userName: admin
✔ Starting business network definition. This may take a minute...
Successfully created business network card:
Filename: admin@kopodeliverysvc.card
Command succeeded
Package.json
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer card import -f admin@kopodeliverysvc.card
Successfully imported business network card
Card file: admin@kopodeliverysvc.card
Card name: admin@kopodeliverysvc
Command succeeded
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ ll
total 20
drwxrwxr-x 2 hyper hyper 4096 Sep 27 11:44 ./
drwxrwxr-x 5 hyper hyper 4096 Sep 27 11:34 ../
-rw-rw-r-- 1 hyper hyper 1017 Sep 27 11:44 'admin@kopodeliverysvc.card'
-rw-rw-r-- 1 hyper hyper 8101 Sep 27 11:35 kopodeliverysvc.bna
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$
48. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~$ cd .composer
hyper@hwy:~/.composer$ ll
total 20
drwxrwxr-x 5 hyper hyper 4096 Sep 26 06:13 ./
drwxr-xr-x 10 hyper hyper 4096 Sep 26 08:07 ../
drwxrwxr-x 4 hyper hyper 4096 Sep 27 11:47 cards/
drwxrwxr-x 4 hyper hyper 4096 Sep 27 11:47 client-data/
drwxrwxr-x 2 hyper hyper 4096 Sep 26 06:12 logs/
hyper@hwy:~/.composer$ cd cards/
hyper@hwy:~/.composer/cards$ ll
total 16
drwxrwxr-x 4 hyper hyper 4096 Sep 27 11:47 ./
drwxrwxr-x 5 hyper hyper 4096 Sep 26 06:13 ../
drwxr-x--- 3 hyper hyper 4096 Sep 27 11:47 'admin@kopodeliverysvc'/
drwxr-x--- 3 hyper hyper 4096 Sep 26 06:13 'PeerAdmin@hlfv1'/
hyper@hwy:~/.composer/cards$ cd ~/fabric-tools/kopodeliverysvc/dist/
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer network ping -c admin@kopodeliverysvc
The connection to the network was successfully tested: kopodeliverysvc
Business network version: 0.0.1
Composer runtime version: 0.20.9
participant: org.hyperledger.composer.system.NetworkAdmin#admin
identity: org.hyperledger.composer.system.Identity#32a89531df78bf0ba5040216314687ba7c6837adf0c315b909da71ced1918cdc
Command succeeded
카드의 위치와 이름 확인
49. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer network list -c admin@kopodeliverysvc
✔ List business network from card admin@kopodeliverysvc
models:
- org.hyperledger.composer.system
- org.kopo.deliverysvc.dispatcher
- org.kopo.deliverysvc.participant
- org.kopo.deliverysvc.truck
scripts:
- lib/script.js
registries:
org.kopo.deliverysvc.dispatcher.Dispatcher:
id: org.kopo.deliverysvc.dispatcher.Dispatcher
name: Asset registry for org.kopo.deliverysvc.dispatcher.Dispatcher
registryType: Asset
org.kopo.deliverysvc.truck.Truck:
id: org.kopo.deliverysvc.truck.Truck
name: Asset registry for org.kopo.deliverysvc.truck.Truck
registryType: Asset
org.kopo.deliverysvc.participant.KOPOB2BPartner:
id: org.kopo.deliverysvc.participant.KOPOB2BPartner
name: Participant registry for org.kopo.deliverysvc.participant.KOPOB2BPartner
registryType: Participant
org.kopo.deliverysvc.participant.KOPOCustomer:
id: org.kopo.deliverysvc.participant.KOPOCustomer
name: Participant registry for org.kopo.deliverysvc.participant.KOPOCustomer
registryType: Participant
org.kopo.deliverysvc.participant.KOPONetworkAdmin:
id: org.kopo.deliverysvc.participant.KOPONetworkAdmin
name: Participant registry for org.kopo.deliverysvc.participant.KOPONetworkAdmin
registryType: Participant
Command succeeded
50. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~/fabric-tools/kopodeliverysvc/dist$ composer-rest-server -c admin@kopodeliverysvc -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 ...
Registering named query: AllDispatchers
Registering named query: AllDispatchersWithSkipLimit
Registering named query: DispatchersOriginAndDestination
Generated schemas for all types in business network definition
Adding schemas for all types to Loopback ...
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org_kopo_deliverysvc_dispatcher_Route".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Swagger: skipping unknown type "org.kopo.deliverysvc.dispatcher.Dispatcher".
Added schemas for all types to Loopback
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
localhost:3000/explorer
65. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
hyper@hwy:~/$ composer identity issue -u 092819-11111111 -a org.kopo.deliverysvc.participant.KOPONetworkAdmin#092819-11111111 -c
admin@kopodeliverysvc –x
Issue identity and create Network Card for: 092819-11111111
✔ Issuing identity. This may take a few seconds...
Successfully created business network card file to
Output file: 092819-11111111@kopodeliverysvc.card
Command succeeded
hyper@hwy:~/$ composer identity issue -u bespin -a org.kopo.deliverysvc.participant.KOPONetworkAdmin#092819-11111111 -c admin@kopodeliverysvc -x
Issue identity and create Network Card for: bespin
✔ Issuing identity. This may take a few seconds...
Successfully created business network card file to
Output file: bespin@kopodeliverysvc.card
Command succeeded hyper@hwy:~/fabric-tools/fabric-scripts/hlfv12/composer$ composer card import -f bespin@kopodeliverysvc.card
Successfully imported business network card
Card file: bespin@kopodeliverysvc.card
Card name: bespin@kopodeliverysvc
Command succeeded
hyper@hwy:~/fabric-tools/fabric-scripts/hlfv12/composer$ composer network ping -c bespin@kopodeliverysvc
The connection to the network was successfully tested: kopodeliverysvc
Business network version: 0.0.2
Composer runtime version: 0.20.9
participant: org.kopo.deliverysvc.participant.KOPONetworkAdmin#092819-11111111
identity: org.hyperledger.composer.system.Identity#88c9ec94bcf8e8bf05e4b31324e83a6e621f4e9b96c4d5a91a28d61d7ba7974f
Command succeeded
68. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
rule KopoNetworkAdminPermissionSystem {
description: "can READ the system registries"
participant: "ANY"
operation: READ
resource: "org.hyperledger.composer.system.**"
action: ALLOW
}
rule NetworkControlPermission {
description: "give admin ALL access to system resources"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.*"
action: ALLOW
}
rule ParticipantRegistryControlPermission {
description: "give admin ALL access to KOPO participant types"
participant: "org.hyperledger.composer.system.NetworkAdmin"
operation: ALL
resource: "org.kopo.deliverysvc.participant.*"
action: ALLOW
}
rule ParticipantRegistryControlPermission2 {
description: "give admin ALL access to KOPO participant types"
participant: "org.kopo.deliverysvc.participant.KOPONetworkAdmin"
operation: ALL
resource: "org.hyperledger.composer.system.*"
action: ALLOW
}
rule ParticipantRegistryControlPermission3 {
description: "give admin ALL access to KOPO participant types"
participant: "org.kopo.deliverysvc.participant.KOPONetworkAdmin"
operation: ALL
resource: "org.kopo.deliverysvc.participant.*"
action: ALLOW
}
1. ACL 추가
composer archive create -a dist/kopodeliverysvc.bna --sourceType dir --sourceName .
composer network install -a dist/kopodeliverysvc.bna -c PeerAdmin@hlfv1
composer network upgrade -n kopodeliverysvc -c PeerAdmin@hlfv1 -V 0.0.3
2. Package.json 버전 수정
3. Bna 재빌드 및 네트워크 배포
69. APCPCWM_4828539:WP_0000010WP_0000010APCPCWM_4828539:WP_0000010WP_000001
rule ParticipantRegistryControlPermission4 {
description: "give admin ALL access to KOPO
participant types"
participant: "org.kopo.deliverysvc.participan
t.KOPONetworkAdmin"
operation: ALL
resource: "org.kopo.deliverysvc.truck.*"
action: ALLOW
}
composer archive create -a dist/kopodeliverysvc.bna --sourceType dir --sourceName .
composer network install -a dist/kopodeliverysvc.bna -c PeerAdmin@hlfv1
composer network upgrade -n kopodeliverysvc -c PeerAdmin@hlfv1 -V 0.0.3
2. Package.json 버전 수정
3. Bna 재빌드 및 네트워크 배포
1. ACL 수정
4. Rest server 실행 (카드명 주의 issue한 카드로 지정)
5. Asset(Truck) 추가 테스트