1. 체인코드 개발환경 구축
페이지 정보
작성자 관리자 댓글 4건 조회 15,788회 작성일 19-08-26 13:03본문
1. 체인코드 개발환경 구축
root@client:~# apt-get remove golang
패키지 목록을 읽는 중입니다... 완료
의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료
다음 패키지가 자동으로 설치되었지만 더 이상 필요하지 않습니다:
golang-1.10 golang-1.10-doc golang-1.10-go golang-1.10-race-detector-runtime
golang-1.10-src golang-doc golang-go golang-race-detector-runtime golang-src
pkg-config
Use 'apt autoremove' to remove them.
다음 패키지를 지울 것입니다:
golang
0개 업그레이드, 0개 새로 설치, 1개 제거 및 94개 업그레이드 안 함.
이 작업 후 11.3 k바이트의 디스크 공간이 비워집니다.
계속 하시겠습니까? [Y/n]
(데이터베이스 읽는중 ...현재 181881개의 파일과 디렉터리가 설치되어 있습니다.)
Removing golang (2:1.10~4ubuntu1) ...
root@client:~# apt autoremove
root@client:~# wget https://storage.googleapis.com/golang/go1.10.4.linux-amd64.tar.gz
--2019-11-05 10:52:30-- https://storage.googleapis.com/golang/go1.10.4.linux-amd64.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.161.80, 2404:6800:4004:80b::2010
접속 storage.googleapis.com (storage.googleapis.com)|172.217.161.80|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 92794622 (88M) [application/octet-stream]
Saving to: ‘go1.10.4.linux-amd64.tar.gz’
go1.10.4.linux-amd6 100%[===================>] 88.50M 9.23MB/s in 8.8s
2019-11-05 10:52:40 (10.1 MB/s) - ‘go1.10.4.linux-amd64.tar.gz’ saved [92794622/92794622]
root@client:~# tar xvfz go1.10.4.linux-amd64.tar.gz
GOPATH와 GOROOT을 설정한다.
root@client:~# mkdir /root/gopath
root@client:~# vi /etc/profile
export GOPATH=/root/gopath
export GOROOT=/root/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
앤 아래에 위와 같이 추가한다.
저장하고 종료한 후 설정한 환경변수를 시스템에 업데이트 한다.
root@client:~# source /etc/profile
root@client:~# mkdir hyperledger
root@client:~# cd hyperledger/
root@client:~/hyperledger# git clone git://github.com/hyperledger/fabric-samples.git
'fabric-samples'에 복제합니다...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 3986 (delta 0), reused 10 (delta 0), pack-reused 3976
오브젝트를 받는 중: 100% (3986/3986), 1.39 MiB | 1.39 MiB/s, 완료.
델타를 알아내는 중: 100% (1945/1945), 완료.
root@client:~/hyperledger# ls fabric-samples/
CODE_OF_CONDUCT.md basic-network first-network
CONTRIBUTING.md chaincode high-throughput
Jenkinsfile chaincode-docker-devmode interest_rate_swaps
LICENSE ci.properties off_chain_data
MAINTAINERS.md commercial-paper scripts
README.md docs
balance-transfer fabcar
root@client:~/hyperledger#
root@client:~/hyperledger# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hyperledger/fabric-testenv amd64-1.3.1-snapshot-d942308df 474d50233dcb 20 hours ago 1.4GB
hyperledger/fabric-testenv amd64-latest 474d50233dcb 20 hours ago 1.4GB
hyperledger/fabric-testenv latest 474d50233dcb 20 hours ago 1.4GB
hyperledger/fabric-buildenv amd64-1.3.1-snapshot-d942308df 9a32072f3ad1 20 hours ago 1.35GB
hyperledger/fabric-buildenv amd64-latest 9a32072f3ad1 20 hours ago 1.35GB
hyperledger/fabric-buildenv latest 9a32072f3ad1 20 hours ago 1.35GB
hyperledger/fabric-ccenv amd64-1.3.1-snapshot-d942308df 1a75be83a3f5 20 hours ago 1.38GB
hyperledger/fabric-ccenv amd64-latest 1a75be83a3f5 20 hours ago 1.38GB
hyperledger/fabric-ccenv latest 1a75be83a3f5 20 hours ago 1.38GB
hyperledger/fabric-tools amd64-1.3.1-snapshot-d942308df 2bcbc07aeb56 20 hours ago 1.45GB
hyperledger/fabric-tools amd64-latest 2bcbc07aeb56 20 hours ago 1.45GB
hyperledger/fabric-tools latest 2bcbc07aeb56 20 hours ago 1.45GB
hyperledger/fabric-orderer amd64-1.3.1-snapshot-d942308df 9840436885c4 20 hours ago 145MB
hyperledger/fabric-orderer amd64-latest 9840436885c4 20 hours ago 145MB
hyperledger/fabric-orderer latest 9840436885c4 20 hours ago 145MB
hyperledger/fabric-peer amd64-1.3.1-snapshot-d942308df 60a85493de80 20 hours ago 151MB
hyperledger/fabric-peer amd64-latest 60a85493de80 20 hours ago 151MB
hyperledger/fabric-peer latest 60a85493de80 20 hours ago 151MB
hyperledger/fabric-zookeeper latest 20c6045930c8 5 months ago 1.43GB
hyperledger/fabric-kafka latest b4ab82bbaf2f 5 months ago 1.44GB
hyperledger/fabric-baseimage amd64-0.4.13 27240288889f 10 months ago 1.34GB
hyperledger/fabric-baseos amd64-0.4.13 f0fe49196c40 10 months ago 124MB
root@client:~/hyperledger#
Docker 이미지 확인 사이트입니다.
https://hub.docker.com/r/hyperledger/fabric-orderer/tags
터미널1. 네트워크 시작
root@client:~/hyperledger# cd fabric-samples/
root@client:~/hyperledger/fabric-samples# cd chaincode-docker-devmode/
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode#
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# ls
README.rst docker-compose-simple.yaml msp myc.tx orderer.block script.sh
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# vi docker-compose-simple.yaml
version: '2'
services:
orderer:
container_name: orderer
image: hyperledger/fabric-orderer:1.4.0
environment:
- FABRIC_LOGGING_SPEC=debug
- ORDERER_GENERAL_LISTENADDRESS=orderer
- ORDERER_GENERAL_GENESISMETHOD=file
- ORDERER_GENERAL_GENESISFILE=orderer.block
- ORDERER_GENERAL_LOCALMSPID=DEFAULT
- ORDERER_GENERAL_LOCALMSPDIR=/etc/hyperledger/msp
- GRPC_TRACE=all=true,
- GRPC_VERBOSITY=debug
working_dir: /opt/gopath/src/github.com/hyperledger/fabric
command: orderer
volumes:
- ./msp:/etc/hyperledger/msp
- ./orderer.block:/etc/hyperledger/fabric/orderer.block
ports:
- 7050:7050
peer:
container_name: peer
image: hyperledger/fabric-peer:1.4.0
environment:
- CORE_PEER_ID=peer
- CORE_PEER_ADDRESS=peer:7051
- CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer:7051
- CORE_PEER_LOCALMSPID=DEFAULT
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=DEBUG
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp
volumes:
- /var/run/:/host/var/run/
- ./msp:/etc/hyperledger/msp
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
command: peer node start --peer-chaincodedev=true
ports:
- 7051:7051
- 7053:7053
depends_on:
- orderer
cli:
container_name: cli
image: hyperledger/fabric-tools:1.4.0
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=DEBUG
- CORE_PEER_ID=cli
- CORE_PEER_ADDRESS=peer:7051
- CORE_PEER_LOCALMSPID=DEFAULT
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp
working_dir: /opt/gopath/src/chaincodedev
command: /bin/bash -c './script.sh'
volumes:
- /var/run/:/host/var/run/
- ./msp:/etc/hyperledger/msp
- ./../chaincode:/opt/gopath/src/chaincodedev/chaincode
- ./:/opt/gopath/src/chaincodedev/
depends_on:
- orderer
- peer
chaincode:
container_name: chaincode
image: hyperledger/fabric-ccenv:1.4.0
tty: true
environment:
- GOPATH=/opt/gopath
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
- FABRIC_LOGGING_SPEC=DEBUG
- CORE_PEER_ID=example02
- CORE_PEER_ADDRESS=peer:7051
- CORE_PEER_LOCALMSPID=DEFAULT
- CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp
working_dir: /opt/gopath/src/chaincode
command: /bin/sh -c 'sleep 6000000'
volumes:
- /var/run/:/host/var/run/
- ./msp:/etc/hyperledger/msp
- ./../chaincode:/opt/gopath/src/chaincode
depends_on:
- orderer
- peer
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# docker-compose -f docker-compose-simple.yaml up
터미널2. chaincode 빌드 및 시작
root@client:~# cd hyperledger/fabric-samples/chaincode-docker-devmode/
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# docker exec -it chaincode bash
chaincode를 컴파일한다.
root@bb96c42ed026:/opt/gopath/src/chaincode# cd chaincode_example02/go
root@bb96c42ed026:/opt/gopath/src/chaincode/chaincode_example02/go# go build -o chaincode_example02
root@bb96c42ed026:/opt/gopath/src/chaincode/chaincode_example02/go# ls
chaincode_example02 chaincode_example02.go
chaincode를 실행한다.
root@bb96c42ed026:/opt/gopath/src/chaincode/chaincode_example02/go# CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
2019-08-28 12:03:39.070 UTC [shim] setupChaincodeLogging -> INFO 001 Chaincode log level not provided; defaulting to: INFO
2019-08-28 12:03:39.070 UTC [shim] setupChaincodeLogging -> INFO 002 Chaincode (build level: ) starting up ...
2019-08-28 12:03:39.071 UTC [bccsp] initBCCSP -> DEBU 001 Initialize BCCSP [SW]
2019-08-28 12:03:39.071 UTC [grpc] DialContext -> DEBU 002 parsed scheme: ""
2019-08-28 12:03:39.071 UTC [grpc] DialContext -> DEBU 003 scheme "" not registered, fallback to default scheme
2019-08-28 12:03:39.072 UTC [grpc] watcher -> DEBU 004 ccResolverWrapper: sending new addresses to cc: [{peer:7052 0 <nil>}]
2019-08-28 12:03:39.072 UTC [grpc] switchBalancer -> DEBU 005 ClientConn switching balancer to "pick_first"
2019-08-28 12:03:39.072 UTC [grpc] HandleSubConnStateChange -> DEBU 006 pickfirstBalancer: HandleSubConnStateChange: 0xc0002be2a0, CONNECTING
2019-08-28 12:03:39.076 UTC [grpc] HandleSubConnStateChange -> DEBU 007 pickfirstBalancer: HandleSubConnStateChange: 0xc0002be2a0, READY
터미널3. chaincode 사용
root@client:~# cd hyperledger/fabric-samples/chaincode-docker-devmode/
root@client:~/hyperledger/fabric-samples/chaincode-docker-devmode# docker exec -it cli bash
root@7dc28db79b36:/opt/gopath/src/chaincodedev# peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0
root@7dc28db79b36:/opt/gopath/src/chaincodedev# peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
root@7dc28db79b36:/opt/gopath/src/chaincodedev# peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
root@7dc28db79b36:/opt/gopath/src/chaincodedev# peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
터미널 2번에서 로그를 보면 아래와 같이 보인다.
ex02 Init
Aval = 100, Bval = 200
ex02 Invoke
Aval = 90, Bval = 210
ex02 Invoke
Query Response:{"Name":"a","Amount":"90"}
댓글목록
관리자님의 댓글
관리자 작성일
기존 docker 이미지 삭제하기
docker images -q | xargs docker rmi -f
관리자님의 댓글
관리자 작성일
root@client:~# mkdir -p $GOPATH/src/github.com/hyperledger
root@client:~# cd $GOPATH/src/github.com/hyperledger
root@client:~/gopath/src/github.com/hyperledger# git clone -b master https://github.com/hyperledger/fabric-samples.git
'fabric-samples'에 복제합니다...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 4230 (delta 1), reused 3 (delta 0), pack-reused 4221
오브젝트를 받는 중: 100% (4230/4230), 1.51 MiB | 1.46 MiB/s, 완료.
델타를 알아내는 중: 100% (2084/2084), 완료.
root@client:~/gopath/src/github.com/hyperledger#
root@client:~/gopath/src/github.com/hyperledger# cd fabric-samples/
root@client:~/gopath/src/github.com/hyperledger/fabric-samples# git checkout v1.4.0
주의: 'v1.4.0' 체크아웃하기.
지금 'HEAD가 분리된' 상태입니다. 이 상태에서는 여기저기 돌아보고,
실험적으로 바꾸고 커밋하더라도, 체크아웃할 수 있는 다른 브랜치에
영향을 미치지 않고 변경 사항을 잃어버릴 수 있습니다.
커밋을 유지하는 브랜치를 새로 만드려면, (지금이든 나중이든) 체크아웃
명령을 다시 하면서 -b 옵션을 사용하면 됩니다. 예를 들어:
git checkout -b <새-브랜치-이름>
HEAD의 현재 위치는 bb39b6e [FAB-13570] Align fabric-samples with 1.4.0 release
root@client:~/gopath/src/github.com/hyperledger/fabric-samples# git branch
* (HEAD v1.4.0 위치에서 분리됨)
master
root@client:~/gopath/src/github.com/hyperledger/fabric-samples# curl -sSL https://goo.gl/6wtTN5 | sudo bash -s 1.4.0
관리자님의 댓글
관리자 작성일
root@client:~/gopath/src/github.com/hyperledger/fabric-samples# cd first-network
root@client:~/gopath/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh -m generate
root@client:~/gopath/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh -m up
관리자님의 댓글
관리자 작성일root@client:~/gopath/src/github.com/hyperledger/fabric-samples/first-network# ./byfn.sh -m down