Hyperledger Fabric 개발환경구축및예제networking.khu.ac.kr/html/lecture_data/2019_03... ·...
Transcript of Hyperledger Fabric 개발환경구축및예제networking.khu.ac.kr/html/lecture_data/2019_03... ·...
-
Intelligent Networking Lab
Hyperledger Fabric 개발환경구축및예제
-
2/64
• 개발환경 구축
1. Docker installation
2. Golang installation
3. Node.Js installation(LTS)
4. Git besh installation
• 예제
1. Building My First Network
2. Chaincode-docker-devmode example
Outline
-
3/64
• Warning
BIOS에 가상화 기능이 꺼져 있다면 Window 부팅 시 가상화를키고 실습을 진행하시기 바랍니다.
Notification
-
4/64Before it starts
재부팅화면에서 F12(연타) ( intel 컴퓨터기준)
-
5/64Before it starts
가상화기능을 Enabled 로변경후
-
6/64Save and Restart
-
7/64
설치및개발환경구축
-
8/64Docker download and execute.
https://docs.docker.com/docker-for-windows/install/
Download 후실행
https://docs.docker.com/docker-for-windows/install/
-
9/64개발환경 구축 (Docker 설치)
-
10/64Docker install
-
11/64Docker install succeeded.
-
12/64Hyper-V 가 안켜져있다면켜기
도커는최신버전에윈도우에서만동작하기때문에업데이트를 작업을한다.(자동)
-
13/64Hyper-V ON
-
14/64Hyper –V ON 켜기.
-
15/64Hyperledger fabric 개발환경 구축
-
16/64개발환경 구축
https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
• Hyperledger fabric 도큐먼트에서 go다운로드 link로이동해서다운로드한다.
https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
-
17/64개발환경 구축 (golang 설치)
https://golang.org/dl/
Default 설정으로설치하기
https://golang.org/dl/
-
18/64개발환경 구축 (golang 설치)
Golang 설치완료
-
19/64개발환경 구축 (go lang 환경변수 변경)
• 환경변수까지 Setting 하면 Golang 설치완료
-
20/64개발환경 구축 (Node.Js설치)
https://nodejs.org/en/download/Node.js 설치. (LTS version으로다운받아야한다.)
https://nodejs.org/en/download/
-
21/64개발환경 구축
• Default 설정으로설치하면완료
-
22/64개발환경 구축
• Windows-build-tools를통해서 python 설치가되어야한다.• 그래서 Git bash를사용한다. • Google 검색창에 “windows git”을검색하고최상단에있는것을 Click한다.
-
23/64개발환경 구축
https://git-scm.com/download/win
• 사이트에접속하면자동으로운영체제에맞는 setup file이다운받아진다.• Default 설정으로설치한다.
https://git-scm.com/download/win
-
24/64개발환경 구축
-
25/64개발환경 구축
check
• 환경변수 Setting을위해재부팅
-
26/64개발환경 구축
For Node.js you also need the necessary Visual Studio C++
Build Tools which are freely available and can be installed
with the following command:
※Docker 가제대로동작하고있어야한다.
-
27/64개발환경 구축
• All done! 이나왔다면 완료.
-
28/64개발환경 구축
Once this is done, you should also install the NPM GRPC module with the following command:
종료후관리자권한으로 git bash 다시실행.
NPM은 Node Package Module의약자이다. Node.js에서사용가능한모듈들을패키지화하여모아두었다.라이브러리가필요할경우, 웹에서하나하나전부검색할필요없어개발자들에게편리함을제공한다.
-
29/64개발환경 구축
• Run git bash as administrator again.• Install Platform-specific Binaries.
Curl : Client URL 프로토콜등에의해전송되는파일을위한 command line tool이다.
1.4.1
-
30/64First network 구축
-
31/64개발환경 구축
• ls –ltr : 디렉토리목록확인
((v1.4.1))
((v1.4.1))
-
32/64
1. pwd 명령어를통해자신의현재디렉토리를확인한다. 2. 본디렉토리로실습환경구축을위해서환경변수를추가해야한다.
-
33/64개발환경 구축
1
2
3
4
-
34/64First Network 구축
• Git bash를닫고다시한번관리자권한으로실행
-
35/64개발환경 구축
• Check the path
((v1.4.1))
((v1.4.1))
((v1.4.1))
((v1.4.1))
((v1.4.1))
-
36/64개발환경 구축
Git bash 관리자권한으로재시작
-
37/64네트워크 구축
./byfn.sh up
Byfn.sh(Build your first network) 를업로드시킨다.
-
38/64개발환경 구축
((v1.4.1))
-
39/64개발환경 구축
• Complete
-
40/64Docker 이미지 확인
This is the Chaincodemycc: mychaincode
-
41/64
Next, we need to tell the configtxgen tool where to look for the configtx.yaml file that it needs to ingest. We will tell it look in our present working directory:
Then, we’ll invoke the configtxgen tool to create the orderer genesis block:
((v1.4.1))
((v1.4.1))
((v1.4.1))
-
42/64Create a Channel Configuration Transaction
You should see an output similar to the following in your terminal:
Cut and Pasteexport CHANNEL_NAME=mychannel && ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
Now, we will define the anchor peer for Org2 on the same channel:
((v1.4.1))
((v1.4.1))
-
43/64Start the network
If you ran the byfn.sh example above previously, be sure that you have brought down the test network before you proceed
-
44/64Chaincode-docker-devmode 예제First. 예제시작전가장먼저 실행중인 Docker 이미지를다삭제해준다. Cut and Paste : docker rm –f $(docker ps –a -q)docker rmi –f $(docker images -q)
-
45/64Go to Github
https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
-
46/64Open three terminals
cd chaincode-docker-devmode①
②
-
47/64Terminal 2 - Build & start the chaincode
① winpty docker exec –it chaincode bashYou should see following :
②Now compile your chaincode :
-
48/64
③Now Run the chaincode :
Terminal 2 – Run the chaincode
-
49/64Terminal 3 - Use the chaincode
peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0
① ②
-
50/64Now issue an invoke to move 10 from a to b.
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
①
②
-
51/64Testing New Chaincode 를 위해서 개발 Tool Install
https://code.visualstudio.com/
https://code.visualstudio.com/
-
52/64New chaincode (Register)
실습내용:Chaincode 를사용해임의의인물을생성해서계좌를개설해서돈을입금/ 출금해보는예제.
Go to “chaincode_example02.go” 추가
-
53/64Chaincode 작성
• 코드를작성하고 Ctrl +S
-
54/64Blockchain Network shut down새로운 chaincode 컴파일실행을위해
((v1.4.1))
((v1.4.1))
-
55/64Blockchain Network Running (Terminal 1)
Terminal 1 을다시 run시켜준다. Cut and paste : docker-compose docker-compose-simple.yaml up
-
56/64Terminal 2
• 전에컴파일한파일을지운다.
-
57/64Chaincode compile (RE) –Terminal 2
go build -o chaincode_example02①
② CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
-
58/64Chaincode install –Terminal 3
peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0
-
59/64계좌에 잔액 부여 –Terminal 3
전에 chaincode 와동일하게실습
Terminal 2에서확인가능
-
60/64잔액확인
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc // A 에잔액이얼마가있는지확인
Terminal 3에입력
Terminal 2에서확인가능
-
61/64구현한 Register chaincode 확인
• peer chaincode invoke -n mycc -c '{"Args":["reg","tablo","1000"]}' -C myc• 이름이 tablo인사람을잔액 1000원으로등록
Terminal 3에서입력하고
Terminal 2에서확인
-
62/64Register 한 user에 잔액확인
Terminal 3에입력
Terminal 2에서확인가능
peer chaincode query -n mycc -c '{"Args":["query","tablo"]}' -C myc
-
63/64
Thank you!!