SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Downloaden Sie, um offline zu lesen
hyperledger fabric
V1.4
environment setup
! ubuntu 16.04 or higher
! root 권한으로 설치
! apt-get update
! apt-get install curl
! apt-get install python-pip
! apt-get install libltdl-dev
! apt-get install make gcc g++ libtool
! apt-get install tree
environment setup
! git
apt-get install -y git
git version
! Python: 2.7.x
python –version
(apt-get install -y python)
! Go lang Version 1.11.x
wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
tar -C /usr/local/ -xvf go1.11.4.linux-amd64.tar.gz
! Go 환경변수 설정 vi /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
source /etc/profile
go version
source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
environment setup
! Docker Engine: Version 17.06.2-ce or higher
wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker-
ce_17.06.2~ce-0~ubuntu_amd64.deb
dpkg -i docker-ce_17.06.2~ce-0~ubuntu_amd64.deb
docker --version
! Docker-Compose: Version 1.14 or higher
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-
`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
! Node.js (Version 8.9 or higher (no version 9.0 support) / npm (Version 6.x)
curl -sL http://deb.nodesource.com/setup_8.x | bash -
apt-get install nodejs
node -v
npm -v
source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
environment setup
! Hyperledger Fabric
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.0 1.4.0 0.4.10
(curl -sSL https://goo.gl/6wtTN5 | bash -s 1.4.1 1.4.1 0.4.10)
(curl -sSL https://bit.ly/2KLpv5d | bash -s 1.4.0 –d -s)
!
! vi /etc/profile
export FABRIC_HOME=/home/fabric/fabric-samples
export PATH=$PATH:$FABRIC_HOME/bin
source /etc/profile
[참고] 최신 버전 설치시(2.0) 아래 명령으로 실행
(V2.0에서는 본 교안에서 설명하는 예제가 정상 실행되지 않음. 예제의 버전이 2.0 기준으로 수정되어야 함)
v2.0은 체인코드 라이프싸이클이 더 상세해짐
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s
https://hyperledger-fabric.readthedocs.io/en/release-1.4/samples.html#binaries
| bash -s <fabric> <fabric-ca> <thirdparty>
source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html
Build your first network
개요
! The build your first network (BYFN) scenario provisions a sample Hyperledger
Fabric network consisting of two organizations, each maintaining two peer
nodes. It also will deploy a “Solo” ordering service by default, though other
ordering service implementations are available.
source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html
configtx.yaml
! 채널 생성을 위한 Peer 정보 ( Host, Port), MSP 정보,
Consortiums(몇 개의 Org로 구성할 것인지) 설정

- 블럭 생성 크기 등과 관련된 설정

BatchTimeout, 

BatchSize - MaxMessageCount

AbsoluteMaxBytes

PreferredMaxBytes
! 3가지 파일을 결과적으로 생성

- 최초 블록 정보 genesis.block
- 앵커 피어 정보 anchor.tx
(Org1MSPanchor.tx, Org2MSPanchor.tx)
- 채널 구성 정보 channel.tx
crypto-config.yaml
! 인증서 생성을 위한 조직과 Peer 개수, 사용자(어드민 제외) 수 설정
byfn.sh
./byfn.sh generate
root@ubuntu:~/fabric-samples/first-network# ./byfn.sh generate
Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n] Y
proceeding ...
/root/fabric-samples/first-network/../bin/cryptogen
##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
+ cryptogen generate --config=./crypto-config.yaml
org1.example.com
org2.example.com
+ res=0
+ set +x
/root/fabric-samples/first-network/../bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
CONSENSUS_TYPE=solo
+ '[' solo == solo ']'
+ configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2020-02-03 22:57:08.847 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-02-03 22:57:08.905 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2020-02-03 22:57:08.906 KST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml
2020-02-03 22:57:08.961 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2020-02-03 22:57:08.962 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml
2020-02-03 22:57:08.965 KST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2020-02-03 22:57:08.966 KST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block
+ res=0
+ set +x
#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
2020-02-03 22:57:09.005 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2020-02-03 22:57:09.048 KST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml
2020-02-03 22:57:09.089 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2020-02-03 22:57:09.090 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml
2020-02-03 22:57:09.090 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2020-02-03 22:57:09.092 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
제네시스 블록 생성
채널 환결설정
앵커피어 설정
모두/channel-artifacts/ 하위에 결과파일로 저장
[results] ./byfn.sh generate
CA 심화
! 인증기관(CA), 공개키, 개인키, 인증서(CRT)
source : http://soul0.tistory.com/372
intro
CA 살펴보기
hyperledger의 인증
! 하이러페저는 모든 노드들이 자신들의 인증을 CA를 통해 받는다.
! Root CA ! 자식 CA ! *
! 앞서 살펴본 cryptogen 을 통해서 CA를 구성할 수 있음

(Fabric CA Server를 통해서도 CA구성 가능, Fabric-CA Client 또는 Fabric SDK를 통해
서도 인증서 발급 및 조회 등의 서비스 이용가능)
! 인증 대상

- 전체 네트워크, 채널, 조직(Org), 조직 관리자(Admin),
사용자(User), Peer
source : https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html
CA 살펴보기
hyperledger MSP
! MSP (Membership Service Provider)는 멤버쉽 서비스 제공 목적의 컴포넌트
! 인증서를 발급/조회/검증하는 등 사용자 및 서비스의 인증에 대한 작업
! 조직마다 보통 하나의 MSP가 있으며 MSP ID로 구분된다.
- 전체 네트워크, 채널, 조직(Org), 조직 관리자(Admin),
사용자(User), Peer
// mspID 와 certCN 을 조건으로 검사하여 함수의 사용가능 여부를 판단할 수 있음
func authenticateOrg(mspID string, certCN string) bool {
return (mspID == "Org1MSP") && (certCN == "ca.example.com")
}
CA 살펴보기
source : https://github.com/hyperledger/fabric/blob/release-1.4/msp/msp.go
check private key
! root@ubuntu:~/fabric-samples/first-network# find | grep -E '/ca.*_sk' | sort
./crypto-config/ordererOrganizations/example.com/ca/d6c3aff453b6947f13e189a3d3cb60f1d42addf2295acca28aed14f3d4827c21_sk
./crypto-config/peerOrganizations/org1.example.com/ca/c9681f8d01403a2be7a2df7b2bd2ebdc691288d64ae0209b6270facf822fa7e1_sk
./crypto-config/peerOrganizations/org2.example.com/ca/36ea9dbed56ffa19a337c3f3b838682ebd11edd84b51fe6e0f700f7e1a3a4044_sk
CA 살펴보기
├── ordererOrganizations
│   └── example.com
│   ├── ca
│   │   ├── 5a4cfffc67e06260ef685ffa0559975f54912df5127d9bbf0ece4c7b83f9caeb_sk
│   │   └── ca.example.com-cert.pem
│   ├── msp
│   │   ├── admincerts
│   │   │   └── Admin@example.com-cert.pem
│   │   ├── cacerts
│   │   │   └── ca.example.com-cert.pem
│   │   └── tlscacerts
│   │   └── tlsca.example.com-cert.pem
│   ├── orderers
│   │   └── orderer.example.com
│   │   ├── msp
│   │   │   ├── admincerts
│   │   │   │   └── Admin@example.com-cert.pem
│   │   │   ├── cacerts
│   │   │   │   └── ca.example.com-cert.pem
│   │   │   ├── keystore
│   │   │   │   └── 829584340955b187ecc5b1cef386736fd3666ffcd0600ef3f4bc2015c2e36d34_sk
│   │   │   ├── signcerts
│   │   │   │   └── orderer.example.com-cert.pem
│   │   │   └── tlscacerts
│   │   │   └── tlsca.example.com-cert.pem
│   │   └── tls
│   │   ├── ca.crt
│   │   ├── server.crt
│   │   └── server.key
│   ├── tlsca
│   │   ├── 419de30afd02a9ac15cc62acf07509c9497c792cc938d19cbac7484c6ff7455b_sk
│   │   └── tlsca.example.com-cert.pem
│   └── users
│   └── Admin@example.com
│   ├── msp
│   │   ├── admincerts
│   │   │   └── Admin@example.com-cert.pem
│   │   ├── cacerts
│   │   │   └── ca.example.com-cert.pem
│   │   ├── keystore
│   │   │   └── cbd8cba235aafc20622a3056b153129a8dd7efea1a11c0b9b3d75cd94ea47ebd_sk
│   │   ├── signcerts
│   │   │   └── Admin@example.com-cert.pem
│   │   └── tlscacerts
│   │   └── tlsca.example.com-cert.pem
│   └── tls
│   ├── ca.crt
│   ├── client.crt
│   └── client.key
example.com의 비밀키와 인증서
[MSP] 관리자용 인증서
[MSP] CA식별 인증서
[MSP] TLS 통신용 인증서
orderer.example.com
example.com
상위 조직의 어드민 인증서와
CA 인증서를 복사
org.example.com의 비밀키와 인증서
각 노드의 HTTPS 통신용 인증서와 비밀키
각 사용자의의 HTTPS 통신용 인증서와 비밀키
동일 파일
동일 파일
CA 살펴보기
└── peerOrganizations
├── org1.example.com
│   ├── ca
│   │   ├── b6f3f5b3d200ec42cbbe11cff35d7d588b680a0fa10d650d99a7ef1b8470f855_sk
│   │   └── ca.org1.example.com-cert.pem
│   ├── msp
│   │   ├── admincerts
│   │   │   └── Admin@org1.example.com-cert.pem
│   │   ├── cacerts
│   │   │   └── ca.org1.example.com-cert.pem
│   │   ├── config.yaml
│   │   └── tlscacerts
│   │   └── tlsca.org1.example.com-cert.pem
│   ├── peers
│   │   ├── peer0.org1.example.com
│   │   │   ├── msp
│   │   │   │   ├── admincerts
│   │   │   │   │   └── Admin@org1.example.com-cert.pem
│   │   │   │   ├── cacerts
│   │   │   │   │   └── ca.org1.example.com-cert.pem
│   │   │   │   ├── config.yaml
│   │   │   │   ├── keystore
│   │   │   │   │   └── 81d0884d3094c1a56799c113a76a1ddb9989fda14d96e0f793d3e696f23dca2b_sk
│   │   │   │   ├── signcerts
│   │   │   │   │   └── peer0.org1.example.com-cert.pem
│   │   │   │   └── tlscacerts
│   │   │   │   └── tlsca.org1.example.com-cert.pem
│   │   │   └── tls
│   │   │   ├── ca.crt
│   │   │   ├── server.crt
│   │   │   └── server.key
│   │   └── peer1.org1.example.com
│   │   ├── msp
│   │   │   ├── admincerts
│   │   │   │   └── Admin@org1.example.com-cert.pem
│   │   │   ├── cacerts
│   │   │   │   └── ca.org1.example.com-cert.pem
│   │   │   ├── config.yaml
│   │   │   ├── keystore
│   │   │   │   └── dfc4d5a95b62a6fa6aa0a45f822d068139756b2b40e8b392173491e3f768f6f9_sk
│   │   │   ├── signcerts
│   │   │   │   └── peer1.org1.example.com-cert.pem
│   │   │   └── tlscacerts
│   │   │   └── tlsca.org1.example.com-cert.pem
│   │   └── tls
│   │   ├── ca.crt
│   │   ├── server.crt
│   │   └── server.key
│   ├── tlsca
org*.example.com
example.com
peer*.org*.example.com
└── users
│   ├── Admin@org1.example.com
│   │   ├── msp
│   │   │   ├── admincerts
│   │   │   │   └── Admin@org1.example.com-cert.pem
│   │   │   ├── cacerts
│   │   │   │   └── ca.org1.example.com-cert.pem
│   │   │   ├── keystore
│   │   │   │   └── 9e3ebb8985cc6f6c053297825d6bbef822f4c43ea5a7e7d277dd96be1f80e9ec_sk
│   │   │   ├── signcerts
│   │   │   │   └── Admin@org1.example.com-cert.pem
│   │   │   └── tlscacerts
│   │   │   └── tlsca.org1.example.com-cert.pem
│   │   └── tls
│   │   ├── ca.crt
│   │   ├── client.crt
│   │   └── client.key
│   └── User1@org1.example.com
│   ├── msp
│   │   ├── admincerts
│   │   │   └── User1@org1.example.com-cert.pem
│   │   ├── cacerts
│   │   │   └── ca.org1.example.com-cert.pem
│   │   ├── keystore
│   │   │   └── 0a9f665b540e722ea214dd280904f9a92cbac7b647b4853124174ecf2973c898_sk
│   │   ├── signcerts
│   │   │   └── User1@org1.example.com-cert.pem
│   │   └── tlscacerts
│   │   └── tlsca.org1.example.com-cert.pem
│   └── tls
│   ├── ca.crt
│   ├── client.crt
│   └── client.key
NodeOUs:
Enable: true
ClientOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: client
PeerOUIdentifier:
Certificate: cacerts/ca.org1.example.com-cert.pem
OrganizationalUnitIdentifier: peer
CA 살펴보기
[참고] 인증서 살펴보기
root@fabric:/home/fabric/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/ca# openssl x509 -text -noout -in ca.example.com-cert.pem
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
d9:d9:d3:61:6d:0d:28:6f:e2:5d:30:05:82:01:cd:38
Signature Algorithm: ecdsa-with-SHA256
Issuer: C = US, ST = California, L = San Francisco, O = example.com, CN = ca.example.com
Validity
Not Before: Mar 12 03:40:00 2020 GMT
Not After : Mar 10 03:40:00 2030 GMT
Subject: C = US, ST = California, L = San Francisco, O = example.com, CN = ca.example.com
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:c1:e2:fd:33:bc:3d:b9:6b:1b:6a:da:5e:a0:36:
9a:dd:c2:23:9c:c8:7a:ec:b9:e7:54:c4:72:11:19:
85:33:1f:6a:62:e4:1d:c9:ae:e4:e0:2e:12:a0:5e:
7a:d6:c5:51:5c:70:21:29:27:5d:59:d0:17:2b:f9:
4c:0b:f6:9f:d4
ASN1 OID: prime256v1
NIST CURVE: P-256
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature, Key Encipherment, Certificate Sign, CRL Sign
X509v3 Extended Key Usage:
TLS Web Client Authentication, TLS Web Server Authentication
X509v3 Basic Constraints: critical
CA:TRUE
X509v3 Subject Key Identifier:
A6:EE:42:3F:D2:81:13:DB:1A:12:3E:5D:57:75:92:43:BD:D8:C4:AE:8C:51:3D:86:28:F9:69:BD:B4:F7:37:0A
Signature Algorithm: ecdsa-with-SHA256
30:44:02:20:77:12:a9:2b:27:dd:7e:d7:a5:1f:f4:44:c2:00:
b5:e8:ff:b4:cf:07:aa:e4:e5:d2:68:0f:f3:f2:0b:6c:17:c4:
02:20:28:cc:a1:82:4b:e1:0c:38:fa:9e:e8:a9:62:27:29:16:
5a:20:e2:58:bb:b9:2d:ea:f9:f9:5f:a1:b8:c7:2e:e4
CA 살펴보기
[참고] hyperledger fabric ca 실습
! CA Server, Client 설치 및 실습
https://ovila.tistory.com/68
! Hyperledger Fabric 멀티호스트 환경 구축 
https://leejonggun.tistory.com/15
CA 살펴보기
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile
~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
[채널 생성 요청] orderer에 생성 요청시 TLS 통신 사용하며
TLS인증서 위치를 지정함(tlsca.example.com-cert.pem)
CORE_PEER_MSPCONFIGPATH =~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
peer channel join -b mychannel.block
[채널 조인 요청]
CORE_PEER_MSPCONFIGPATH =~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE =~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CHANNEL_NAME=mychannel
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile 
~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
[채널 업데이트 요청 ] orderer에 채널 업데이트 요청
org1의 peer0, peer1
org2의 peer0, peer1
방식 동일하게 모두 수행
/scripts/util.sh 의 setGlobals함수내
설정 코드 참조
전체 실행 순서 (1/2)
CA 살펴보기
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile 
~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel 
-n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('''Org1MSP.peer''','''Org2MSP.peer''')'
[체인코드 인스턴스화] orderer를 통해 수행
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile 
~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc 
--peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles ~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 
--peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles ~중략~/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt –c 
'{"Args":["invoke","a","b","10"]}'
[체인코드 실행] orderer를 통해 수행
CORE_PEER_MSPCONFIGPATH=~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt 
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
[체인코드 인스톨] peer를 통해 설치
각 org의 anchor peer에 설치

org1의 peer0
org2의 peer0
방식 동일하게 모두 수행
전체 실행 순서 (2/2)
CA 살펴보기
docker-compose 설정 파일 확인
docker-compose-cli.yaml의
base가 되는 base/docker-compose-base.yaml에서는
./byfn.sh generat를 통해 생성된 인증서 정보를 볼륨 마운트하고
마운트된 도커 이미지의 해당 디렉토리로 환경변수 설정을 함
./byfn.sh up
===================== Chaincode is installed on peer0.org2 =====================
Instantiating chaincode on peer0.org2...
+ res=0
+ set +x
+ peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile 
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel 
-n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('''Org1MSP.peer''','''Org2MSP.peer''')'
…. 생략 …
===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' =====================
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
+ res=0
+ set +x
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer0.org1 ...3 secs
+ res=0
+ set +x
100
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
Sending invoke transaction on peer0.org1 peer0.org2...
+ peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile 
/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel 
-n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/
tls/ca.crt 
--peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
–c 
'{"Args":["invoke","a","b","10"]}'
2020-02-04 06:05:19.250 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
Installing chaincode on peer1.org2...
+ res=0
+ set +x
+ peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
…. 생략 …
===================== Chaincode is installed on peer1.org2 =====================
Querying chaincode on peer1.org2...
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
+ res=0
+ set +x
docker-compose-cli 살펴보기
Org1의 Peer0인 피어에 접속하도록 환경변수가 설정됨
해당 피어에 채널 생성, 참가, 앵커 피어 갱신, 체인코드 설치/초기화/질의/호출을 수행한다.
(createChannel, joinChannel, updateAnchorPeers, installChaincode, instantiateChaincode, chaincodeQuery, chaincodeInvoke)
createChannel, joinChannel, updateAnchorPeers, installChaincode, instantiateChaincode, chaincodeQuery, chaincodeInvoke
명령은 byfn.sh의 networkUp함수내에서
docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE 로 호출됨
scripts.sh은 cli 도커에 볼륨 마운트됨으로 cli 에서 수행 가능함
chaincode 위치 확인
environment:
- GOPATH=/opt/gopath
volumes:
- /var/run/:/host/var/run/
- ./../chaincode/:/opt/gopath/src/github.com/chaincode
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
- ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/"
peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >&log.txt
peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -l ${LANGUAGE} -v 1.0
-c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')
util.sh
script.sh
chaincode 수정 및 배포하기
./bynf.sh 에서 script.sh을 docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE
로 실행함. 즉, cli 도커에서 체인코드 install/instantiate를 수행함
체인코드를 수정
- invoke(stub shim.ChaincodeStubInterface, args []string) 함수에서

우측 그림과 같이 -10 을 추가
./byfn.sh down
./byfn.sh up
===================== Querying on peer1.org2 on channel 'mychannel'... =====================
+ res=0
+ set +x
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
Attempting to Query peer1.org2 ...3 secs
+ res=0
+ set +x
80
!!!!!!!!!!!!!!! Query result on peer1.org2 is INVALID !!!!!!!!!!!!!!!!
수행결과
util.sh의 chaincodeQuery함수에서
기대한 결과인 90을 충족하지 못하므로
에러로 표시하였으나,
체인코드를 수정한 의도와 부합하는 결과를 확인할 수 있음
docker-compose-cli.yaml에 cli 컨테이너 정의부분에
volumes:
../../chaincode/:/opt/gopath/src/github.com/chaincode
으로 변경한 체인코드를 그대로 cli 컨테이너에 볼륨 마운트하므로
도커를 시작하면 변경된 코드를 cli에서 install할 수 있음
couchdb 사용하기
! ./byfn.sh up -c mychannel -s couchdb
값 ’90’ 확인가능
couch db+fabric tutorial : https://hyperledger-fabric.readthedocs.io/en/release-1.4/couchdb_tutorial.html
4개의 couch db가 4개의 peer에 연결되는 구조로 컨테이너 기동
chaincode docker devmode
사전 준비
! docker rm –f $(docker ps –a -q)
! 샘플예제가 있는 디렉토리로 이동(fabric-samples/chaincode-docker-devmode)
! 3개의 터미널을 오픈하여 상기 디렉토리로 이동
! docker-compose-simple.yaml 구성 확인

- orderer, peer, cli(체인코드 인스톨 및 인터랙션),
chaincode(체인코드 개발 환경) 컨테이너로 구성
cli:
container_name: cli
image: hyperledger/fabric-tools
tty: true
…중략…
working_dir: /opt/gopath/src/chaincodedev
command: /bin/bash -c './script.sh'
volumes:
…중략…
- ./../chaincode:/opt/gopath/src/chaincodedev/chaincode
- ./:/opt/gopath/src/chaincodedev/
chaincode:
container_name: chaincode
image: hyperledger/fabric-ccenv
tty: true
environment:
…중략…
- CORE_PEER_ADDRESS=peer:7051
…중략…
working_dir: /opt/gopath/src/chaincode
command: /bin/bash -c 'sleep 6000000'
volumes:
…중략…
- ./../chaincode:/opt/gopath/src/chaincode
source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
Terminal 1 - Start the network
! docker-compose -f docker-compose-simple.yaml up
source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
Terminal 2 - Build & start the
chaincode
! docker exec -it chaincode sh
! cd /opt/gopath/src/chaincode
! cd chaincode_example02/go
! go build -o chaincode_example02
! CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02
docker exec –it chaincode /bin/bash
source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
Normally chaincodes are started and maintained by peer. However in “dev mode",
chaincode is built and started by the user.
! BYFN 에서는 peer를 통해 시작/관리하고 cli 컨테이너에서 체인코드 설치 및 초기화를 하였으나,
본 예제에서는 사용자가 위 명령을 통해 체인코드를 먼저 실행 상태로 만든다.
docker-compose-simple.yaml 의 peer 컨테이너
Command 섹션에 —peer-chaincodedev = true 라고 설정됨
Terminal 3 - Use the chaincode
! docker exec -it cli bash
! peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0
! peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
! peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
! peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
source : https://nick-fabric.readthedocs.io/en/latest/commands/peerchaincode.html
여기까지는 Build Your First Network 체인코드와 동일하다.
이제 일부 코드를 추가하여 다시 배포해 보자.
terminal2 에서 chaincode를 실행하지 않으면 에러발생
local development env.
! visual studio code 설치 + GO addon 추가 설치
! visual studio code 에서 소스 추적 및 빌드 가능
$GOROOT/src/ 에서 다음과 같이 hlf 라이브러리 추가
mkdir -p github.com/hyperledger
cd github.com/hyperledger/
git clone -b release-1.4 https://github.com/wonyongHwang/fabric.git
우측 그림의 소스는 $GOPATH/src/[임의 폴더명]/chiancode_example.go에 위치시킴
% pwd
/Users/hwang-won-yong/go/src/sacc
% ls
chaincode_example02.go
Visual studio
Go extension의 settings.jon 설정내용:
{
"go.formatTool": "goimports",
"go.useLanguageServer": true
}
상기 설정 이후 VS 재시작
—> 라이브러리에 밑 줄이 보이고, 해당 정의부로 이동도 가능하게 됨
chaincode download/upload via sftp
! ftp root access/login 허용
! Visual Studio Code에 ftp simple plugin 설치
! F1을 누른 다음  ftp-simple:Config - FTP connection setting 를 선택하고 우측

그림과 같이 편집
! F1을 누른 다음 tp-simple:Open - Open the file directly from FTP server를 선택

하고 localhost를 클릭하면 접속됨
! 접속 이후 체인코드 클릭하여 편집창에서 오픈
! $GOPATHSRCchaincode_example02 폴더를 생성하고

해당 폴더 하위에 chaincode_example02.go 파일로 save as… 한다. (소스 분석용)
visual studio code 플러그인 설치 출처 : https://www.manualfactory.net/10964
chaincode 수정
! 공식 튜토리얼을 참조하여 아래와 같이 수정
공식 튜토리얼 : https://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html#terminal-1-start-the-network
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
    fmt.Println("ex02 Invoke")
    function, args := stub.GetFunctionAndParameters()
    if function == "invoke" {
        // Make payment of X units from A to B
        return t.invoke(stub, args)
    } else if function == "delete" {
        // Deletes an entity from its state
        return t.delete(stub, args)
    } else if function == "query" {
        // the old "Query" is now implemtned in invoke
        return t.query(stub, args)
    } else if function == "set" {
        // the old "Query" is now implemtned in invoke
        return t.set(stub, args)
    }
    return shim.Error("Invalid invoke function name. Expecting "invoke" "delete" "query"")
}
func (t *SimpleChaincode) set(stub shim.ChaincodeStubInterface, args []string) pb.Response {
    var A string
    var Aval int
    var err error
    if len(args) != 2 {
        return shim.Error("Incorrect number of arguments. Expecting 2")
    }
    A = args[0]
    Aval, err = strconv.Atoi(args[1])
    fmt.Printf("################### Aval = %d", Aval)
    if err != nil {
        return shim.Error("IT IS NOT AN INTEGER VALUE")
    }
    err = stub.PutState(A, []byte(args[1]))
    if err != nil {
        return shim.Error(err.Error())
    }
    return shim.Success(nil)
}
코드 수정 후 빌드 테스트
chaincode 배포 및 테스트
! docker-compose –f docker-compose-simple.yaml down
! docker-compose –f docker-compose-simple.yaml up
! 이전 terminal2, terminal3에서 수행했던 내용 동일 반복하고 코드에서 추가한 set 명령
에 대해 추가로 확인
peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["set","a","1000"]}' -C myc
peer chaincode query -n mycc -c '{"Args":["query",“a"]}' -C myc
Aval = 100, Bval = 200
ex02 Invoke
Aval = 80, Bval = 210
ex02 Invoke
Query Response:{"Name":"a","Amount WOW":"80"}
ex02 Invoke
################### Aval = 1000
ex02 Invoke
Query Response:{"Name":"a","Amount WOW":"1000"}
terminal2
terminal3
[참고] peer chaincode upgrade
! 모든 컨테이너 기동 상태에서 체인코드 업그레이드 실시
! VS CODE 에서 소스 변경 및 저장/업로드
terminal2
go build -o chaincode_example02
CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:1 ./chaincode_example02
terminal3
peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 1
peer chaincode upgrade -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v1 -C myc -c '{"Args":["init","a","100","b","200"]}'
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["set","a","1000"]}' -C myc
소스 수정 -> 로컬 빌드 -> FTP 업로드
새로운 terminal을 띄워서 위 terminal2의 내용을 수행함
기존 terminal2는 업그레이드 완료시 peer에 대한 응답을 더 이상 하지 않게 됨
[chaincode dev.]
PutState 실습
func (t *SimpleChaincode) more(stub shim.ChaincodeStubInterface, param []string) pb.Response {
if len(param) != 3 {
return shim.Error("# of parameter mismatching")
}
title, text, code := param[0], param[1], param[2]
codeNum, err := strconv.ParseInt(code, 10, 32)
if err != nil {
return shim.Error("code error")
}
if len(title) == 0 || len(text) == 0 || len(code) == 0 {
return shim.Error("value of paramter is not properly formatted")
}
// make my data of AdditionalInfo
addInfo := &AdditionalInfo{Title: title, Text: text, code: codeNum}
addInfoBytes, err := json.Marshal(addInfo)
if err != nil {
return shim.Error("failed to convert bytes " + err.Error())
}
err = stub.PutState(title, addInfoBytes) // key value에 공백 들어가면 조회시 값을 찾지 못함
if err != nil {
return shim.Error("PutState failure " + err.Error())
}
return shim.Success([]byte("invoke success"))
}
invoke에 more 함수 추가하고
로컬빌드 -> ftp 업로드 ->
Terminal2에서 서버빌드 및 실행 ->
Terminal3에서 CC인스톨 및 업그레이드 ->
아래와 같이 테스트
peer chaincode invoke -n mycc -c
'{"Args":["more","tt","Here your are,
this is a book 2","1200"]}' -C myc
type AdditionalInfo struct {
Title string "json:"title""
Text string "json:"text""
code int64 "json:"code""
}
[chaincode dev.]
GetState 실습
func (t *SimpleChaincode) morequery(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var A string // Entities
var err error
if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting name of the person to query")
}
A = args[0]
// Get the state from the ledger
valbytes, err := stub.GetState(A)
if err != nil {
jsonResp := "{"Error":"Failed to get state for " + A + ""}"
return shim.Error(jsonResp)
}
valueStr := &AdditionalInfo{}
err = json.Unmarshal(valbytes, &valueStr)
if err != nil {
jsonResp := "{"Error":"Failed to Unmarshal " + A + ""}"
return shim.Error(jsonResp)
}
jsonResp := "{"Title":"" + A + "","Text":"" + string(valueStr.Text) + ""}"
fmt.Printf("Query Response:%sn", jsonResp)
// history
iter, _ := stub.GetHistoryForKey(A)
fmt.Println("Here is History for " + A)
for iter.HasNext() {
kv, _ := iter.Next()
fmt.Println(string(kv.GetValue()) + " " + kv.GetTimestamp().String())
}
return shim.Success([]byte(string(valueStr.code)))
}
query에 morequery 함수 추가하고
로컬빌드 -> ftp 업로드 ->
Terminal2에서 서버빌드 및 실행 ->
Terminal3에서 CC인스톨 및 업그레이드 ->
아래와 같이 테스트
peer chaincode query -n mycc -c '{"Args":["morequery","tt"]}' -C myc
GetHistoryForKey 함수로 변경 이력 조회
Git hub : https://github.com/wonyongHwang/chaincode-tutorial/blob/master/kopoChainCode.go
[참고] 공식 튜토리얼 체인코드에서…
source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html#terminal-1-start-the-network
main 함수에서 fabric chaincode의 Start 함수를 호출
이 때 전달되는 파라미터는 type SimpleAsset struct{} 의
객체임. 소스코드상 SimpleAsset의 Init,Invoke 함수를
구현하였으므로 ChainCode 객체로 전달 가능
[참고] 체인코드 호출
! 동일 채널에서 같은/다른 Chaincode 호출(invoke/query) 가능
! 다른 채널의 chaincode는 조회(query)만 가능
-예시-
channel := stub.GetChannelID()
stub.InvokeChaincode(chaincodeName, args, channel)
Hyperledger fabric SDK
Balance transfer example (개요)
! 2 CA, x Orderer, 2 Peer 로 구성
! 기본적으로는 Build Your Network First와 유사한 구조이나, 여기서는 cli 컨테이너가 없음.
대신 Hyperledger fabric SDK를 이용한 node.js구현체를 통해서 채널생성, 체인코드 설치 등을
진행하게 됨.
! Build Your Network First의 기본 실행 구조에서는 CA 서버 없이 cryptogen을 통해 미리 생성해 놓은
인증서를 사용하여 통신 하였으나, 이번 예제는 미리 생성한 인증서 정보를 토대로 CA서버를 기동하고,
Node.js Client에서 요청하는 사용자 등록을 CA 서버에서 인증하고 처리하도록 구성 되었음
* 해당 예제 폴더에 위치한 ~e2e.yaml 로 실행시 ca 서버 기동됨
Balance transfer example (실행 준비)
! 노드 버전 확인(node -v)
balance transfer 예제는 노드 버전 10.x 이상에서 오류 발생 -> 8.* 또는 9.* 설치
기존 node.js 삭제시 : apt-get --purge remove nodejs
node.js 설치 : curl -sL http://deb.nodesource.com/setup_9.x | bash -
apt-get install node.js
* 해당 예제는 fabric 2.0 기본 샘플예제에서 삭제됨(fabric 1.4에서 실행권장)
! 컨테이너 및 이미지 등 도커관련 파일 삭제 (충돌방지)
docker rm -f $(docker ps -a -q)
docker rmi -f $(docker images -a -q)
docker volume prune
docker system prune
docker network prune
Balance transfer example (fabric 실행)
! ./runApp.sh 실행
Balance transfer example (REST 호출)
./testAPIs.sh 을 실행하여 사용자 등록~체인코드 실행까지 정상 진행 되는지 확인
* chaincode instantiate 실행시 time out 으로 오류발생되는 경우,
아래 그림과 같이 testAPIs.sh의 일부분을 수정 (timeout 옵션 추가)
[심화] 더 살펴볼 포인트
! ./testAPIs.sh 의 REST CALL 호출 순서와 내용을 확인
! Node 소스는 app.js가 시작점
! 사용자 등록을 위해 /users 호출시에는 fabric ca server를 통해 신규 사용자 등록을 하고 토큰을 부여함
! /users 이외의 호출 주소는 JWT 토큰 유효성 검사가 이루어짐
! Proposal을 먼저 endorsing peer에 보내고, 해당 피어에서 사전
검증한 결과를 확인하고 orderer에게 검증결과와 트랜잭션
반영요청을 하는 부분
—> invoke-tansaction.js의 sendTransactionProposal 및
sendTransaction 호출 코드 참조

[심화] sdk를 이용한 사용자 등록 과정
! 기 발급받은 인증서를 이용
!
app.post('/users', async function(req, res) {
…
let response = await helper.getRegisteredUser(username, orgName, true);
…}
app.js
Network-config.yaml과 org1.yaml 설정파일을 로딩하여
initCredential을 수행
등록된 사용자 없는 경우;
config.json의 admin/adminpw 계정정보를 이용해
새로운 사용자를 등록(getCertificateAuthority로 인증서 로딩)
[심화] fabric ca container
Node sdk client의 config.js에 설정된 계정정보와 일치해야 함
"admins":[
{
"username":"admin",
"secret":"adminpw"
}
]
[참고] fabric server <-> node.js(SDK) local
—> 로컬에서 node.js 디버깅을 visual studio로 편하게 진행 가능함
[참고] fabric server <-> node.js(SDK) local
사전 준비사항
- local pc
visual studio code 설치
nvm 설치(https://gofnrk.tistory.com/32)
balance transfer 예제 local 복사 + npm rebuild
virtual box 포트 오픈
(유저 등록을 위해서 ca 서버 접속필요—> 7054 포트 연결 설정)
(체인코드 실행 및 쿼리 등을 위해서 오더러(7050) 등 필요시 추가로 포트 연결 설정해야 함)
- 수행 순서
fabric server 기동(./runApp.sh) -> 로컬에서 node 실행해야 하므로 서버측에서는 node 실행부분 주석처리
local의 balance transfer 예제 폴더 중 인증토큰과 관련된 폴더 삭제
rm -rf fabric-client-kv-org*
REST 호출 수행
hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST 
http://localhost:4000/users 
-H "content-type: application/x-www-form-urlencoded" 
-d 'username=Jim&orgName=Org1'
{"success":true,"secret":"","message":"Jim enrolled
Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjU1NjMsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxODk1NjN9.h2v6HzQJdDSUryGEsqPyUbV9SK91GGgTF4_7LCzg
"}%
사용자 등록
hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST 
http://localhost:4000/channels 
-H "authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v
cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" 
-H "content-type: application/json" 
-d '{
"channelName":"mychannel",
"channelConfigPath":"../artifacts/channel/mychannel.tx"
}'
{"success":true,"message":"Channel 'mychannel' created Successfully"}%
hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST 
http://localhost:4000/channels/mychannel/peers 
-H "authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v
cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" 
-H "content-type: application/json" 
-d '{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"]
}'
{"success":true,"message":"Successfully joined peers in organization Org1 to the channel:mychannel"}
Create channel을 위해서 오더러에 해당하는
7050 포트 설정 필요
Join channel을 위해서 피어에 해당하는
7051와 7056 포트 설정 필요
[참고] fabric server <-> node.js(SDK) local
hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST 
http://localhost:4000/channels/mychannel/anchorpeers 
-H "authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v
cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" 
-H "content-type: application/json" 
-d '{
"configUpdatePath":"../artifacts/channel/Org1MSPanchors.tx"
}'
{"success":true,"message":"Successfully update anchor peers in organization Org1 to the channel 'mychannel'"}%
[참고] fabric server <-> node.js(SDK) local
Anchor Peer Update
hwang-won-yong@hwang-won-yong-ui-MacBookPro node % curl -s -X POST 
http://localhost:4000/chaincodes 
-H "authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4vcQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0"

-H "content-type: application/json" 
-d "{
"peers": ["peer0.org1.example.com","peer1.org1.example.com"],
"chaincodeName":"mycc",
"chaincodePath":"/github.com/example_cc/node",
"chaincodeType": "golang",
"chaincodeVersion":"v0"
}"
{"success":true,"message":"Successfully installed chaincode"}%
Install Chaincode
—> 나머지 REST Call도 필요시 포트 설정해가면서 테스트 및 디버깅 진행~
Thanks…
wyhwang@kopo.ac.kr
chaincode dev. setup
from docs
FAILED
source : https://openblockchain.readthedocs.io/en/latest/dev-setup/devenv/#setting-up-the-development-environment
FAILED
git clone -b release-1.4 https://github.com/wonyongHwang/fabric.git
FAILED
v2.0 부터 devenv 디렉토리 없음
vagrant 디렉토리에서 수행해야 함
FAILED
v1.4 v2.0에서는 deprecated
make 로 바로 빌드 수행
vagrant@vagrant:~/go/src/github.com/hyperledger/fabric$ cd build/bin
vagrant@vagrant:~/go/src/github.com/hyperledger/fabric/build/bin$ ll
total 160944
drwxrwxrwx 1 vagrant vagrant 4096 Feb 11 12:44 ./
drwxrwxrwx 1 vagrant vagrant 0 Feb 11 12:53 ../
-rwxrwxrwx 1 vagrant vagrant 20399368 Feb 11 12:44 configtxgen*
-rwxrwxrwx 1 vagrant vagrant 17444176 Feb 11 12:44 configtxlator*
-rwxrwxrwx 1 vagrant vagrant 13358893 Feb 11 12:44 cryptogen*
-rwxrwxrwx 1 vagrant vagrant 19139370 Feb 11 12:44 discover*
-rwxrwxrwx 1 vagrant vagrant 12375285 Feb 11 12:44 idemixgen*
-rwxrwxrwx 1 vagrant vagrant 32163704 Feb 11 12:44 orderer*
-rwxrwxrwx 1 vagrant vagrant 49909440 Feb 11 12:33 peer*
vagrant@vagrant:~/go/src/github.com/hyperledger/fabric/build/bin$ ./peer
FAILED
sudo mkdir -p /var/hyperledger/production
sudo chown -R $(whoami):$(whoami) /var/hyperledger
FAILED
local development setting
FAILED
! https://golang.org/dl/
! https://hub.docker.com/editions/community/docker-ce-desktop-windows
window-build-tools
IBM Blockchain Platform 설치는 가장 나중에 해야 함
FAILED
visual studio code 설정 편집 및 

샘플 프로젝트 생성
! create project ! go ! browse
chaincode.go 의 init, invoke 함수 확인
FAILED
패키지명, 버전명 : 1
fabric 기동
FAILED

Weitere ähnliche Inhalte

Was ist angesagt?

[오픈소스컨설팅]Zabbix Installation and Configuration Guide
[오픈소스컨설팅]Zabbix Installation and Configuration Guide[오픈소스컨설팅]Zabbix Installation and Configuration Guide
[오픈소스컨설팅]Zabbix Installation and Configuration GuideJi-Woong Choi
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료TIMEGATE
 
[오픈소스컨설팅] RPM 만들기
[오픈소스컨설팅] RPM 만들기[오픈소스컨설팅] RPM 만들기
[오픈소스컨설팅] RPM 만들기Ji-Woong Choi
 
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1Ji-Woong Choi
 
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOSConfd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS충섭 김
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3Ji-Woong Choi
 
도커(Docker) 메트릭스 & 로그 수집
도커(Docker) 메트릭스 & 로그 수집도커(Docker) 메트릭스 & 로그 수집
도커(Docker) 메트릭스 & 로그 수집Daegwon Kim
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축Ji-Woong Choi
 
Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2XpressEngine
 
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편Ji-Woong Choi
 
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3XpressEngine
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조Logpresso
 
[오픈소스컨설팅]Docker on Kubernetes v1
[오픈소스컨설팅]Docker on Kubernetes v1[오픈소스컨설팅]Docker on Kubernetes v1
[오픈소스컨설팅]Docker on Kubernetes v1Ji-Woong Choi
 
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기KTH, 케이티하이텔
 
도커없이 컨테이너 만들기 1편
도커없이 컨테이너 만들기 1편도커없이 컨테이너 만들기 1편
도커없이 컨테이너 만들기 1편Sam Kim
 
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHub
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHubXECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHub
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHubXpressEngine
 
Openstack Instance Resize
Openstack Instance ResizeOpenstack Instance Resize
Openstack Instance Resizeymtech
 
도커 없이 컨테이너 만들기 2편
도커 없이 컨테이너 만들기 2편도커 없이 컨테이너 만들기 2편
도커 없이 컨테이너 만들기 2편Sam Kim
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQLI Goo Lee
 
Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Keon Ahn
 

Was ist angesagt? (20)

[오픈소스컨설팅]Zabbix Installation and Configuration Guide
[오픈소스컨설팅]Zabbix Installation and Configuration Guide[오픈소스컨설팅]Zabbix Installation and Configuration Guide
[오픈소스컨설팅]Zabbix Installation and Configuration Guide
 
하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료하이퍼레저 패브릭 실습자료
하이퍼레저 패브릭 실습자료
 
[오픈소스컨설팅] RPM 만들기
[오픈소스컨설팅] RPM 만들기[오픈소스컨설팅] RPM 만들기
[오픈소스컨설팅] RPM 만들기
 
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
[오픈소스컨설팅]Nginx 1.2.7 설치가이드__v1
 
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOSConfd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS
Confd, systemd, fleet을 이용한 어플리케이션 배포 in CoreOS
 
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
[오픈소스컨설팅]Docker기초 실습 교육 20181113_v3
 
도커(Docker) 메트릭스 & 로그 수집
도커(Docker) 메트릭스 & 로그 수집도커(Docker) 메트릭스 & 로그 수집
도커(Docker) 메트릭스 & 로그 수집
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
 
Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2Docker 기반 개발환경 구축 - XE Open seminar #2
Docker 기반 개발환경 구축 - XE Open seminar #2
 
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편
[오픈소스컨설팅]레드햇계열리눅스7 운영자가이드 - 기초편
 
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3
XECon2015 :: [2-4] 오승현 - Chak 서비스 구축기 with XE3
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조
 
[오픈소스컨설팅]Docker on Kubernetes v1
[오픈소스컨설팅]Docker on Kubernetes v1[오픈소스컨설팅]Docker on Kubernetes v1
[오픈소스컨설팅]Docker on Kubernetes v1
 
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
[H3 2012] 내컴에선 잘되던데? - vagrant로 서버와 동일한 개발환경 꾸미기
 
도커없이 컨테이너 만들기 1편
도커없이 컨테이너 만들기 1편도커없이 컨테이너 만들기 1편
도커없이 컨테이너 만들기 1편
 
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHub
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHubXECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHub
XECon2015 :: [1-3] 김덕홍 - Git Workflow with GitHub
 
Openstack Instance Resize
Openstack Instance ResizeOpenstack Instance Resize
Openstack Instance Resize
 
도커 없이 컨테이너 만들기 2편
도커 없이 컨테이너 만들기 2편도커 없이 컨테이너 만들기 2편
도커 없이 컨테이너 만들기 2편
 
Fluentd with MySQL
Fluentd with MySQLFluentd with MySQL
Fluentd with MySQL
 
Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리
 

Ähnlich wie Hyperledger fabric practice(pdf)

1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기
1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기
1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기Hyperledger Korea User Group
 
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드Apache Tomcat ( 아파치 톰캣 ) 설치 가이드
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드Opennaru, inc.
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제Tae Young Lee
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요Jo Hoon
 
이스티오 (Istio) 자습서 v0.5.0
이스티오 (Istio) 자습서 v0.5.0이스티오 (Istio) 자습서 v0.5.0
이스티오 (Istio) 자습서 v0.5.0Jo Hoon
 
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"리얼리눅스
 
Deploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxDeploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxwonyong hwang
 
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)Ubuntu Korea Community
 
resource on openstack
 resource on openstack resource on openstack
resource on openstackjieun kim
 
ARTIK 710 IoT class 02
ARTIK 710 IoT class 02ARTIK 710 IoT class 02
ARTIK 710 IoT class 02정출 김
 
[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅NAVER D2
 
Apache httpd ( 아파치 웹서버 ) 설치 가이드
Apache httpd ( 아파치 웹서버 ) 설치 가이드Apache httpd ( 아파치 웹서버 ) 설치 가이드
Apache httpd ( 아파치 웹서버 ) 설치 가이드Opennaru, inc.
 
Build the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHouseBuild the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHousejieun kim
 
망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324종인 전
 
Hm10 Research sheets
Hm10 Research sheetsHm10 Research sheets
Hm10 Research sheetsyyooooon
 
[2018] Java를 위한, Java에 의한 도구들
[2018] Java를 위한, Java에 의한 도구들[2018] Java를 위한, Java에 의한 도구들
[2018] Java를 위한, Java에 의한 도구들NHN FORWARD
 
안드로이드 플랫폼 설명
안드로이드 플랫폼 설명안드로이드 플랫폼 설명
안드로이드 플랫폼 설명Peter YoungSik Yun
 
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoLinux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoMario Cho
 

Ähnlich wie Hyperledger fabric practice(pdf) (20)

1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기
1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기
1908 Hyperledger Fabric 소개 및 첫 네트워크 구축하기
 
Kafka slideshare
Kafka   slideshareKafka   slideshare
Kafka slideshare
 
KAFKA 3.1.0.pdf
KAFKA 3.1.0.pdfKAFKA 3.1.0.pdf
KAFKA 3.1.0.pdf
 
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드Apache Tomcat ( 아파치 톰캣 ) 설치 가이드
Apache Tomcat ( 아파치 톰캣 ) 설치 가이드
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
 
이스티오 (Istio) 자습서 v0.5.0
이스티오 (Istio) 자습서 v0.5.0이스티오 (Istio) 자습서 v0.5.0
이스티오 (Istio) 자습서 v0.5.0
 
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"
리얼리눅스 제 1 회 세미나: "리눅스, 제대로 알고 코딩하자!"
 
Deploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxDeploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptx
 
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)
이호민 - 우분투 환경에서의 임베디드 개발환경 구축 및 어플리케이션 개발 (2010Y06M24D)
 
resource on openstack
 resource on openstack resource on openstack
resource on openstack
 
ARTIK 710 IoT class 02
ARTIK 710 IoT class 02ARTIK 710 IoT class 02
ARTIK 710 IoT class 02
 
[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅[232] 성능어디까지쥐어짜봤니 송태웅
[232] 성능어디까지쥐어짜봤니 송태웅
 
Apache httpd ( 아파치 웹서버 ) 설치 가이드
Apache httpd ( 아파치 웹서버 ) 설치 가이드Apache httpd ( 아파치 웹서버 ) 설치 가이드
Apache httpd ( 아파치 웹서버 ) 설치 가이드
 
Build the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHouseBuild the OpenStack Cloud with Neutron Networing, IceHouse
Build the OpenStack Cloud with Neutron Networing, IceHouse
 
망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324
 
Hm10 Research sheets
Hm10 Research sheetsHm10 Research sheets
Hm10 Research sheets
 
[2018] Java를 위한, Java에 의한 도구들
[2018] Java를 위한, Java에 의한 도구들[2018] Java를 위한, Java에 의한 도구들
[2018] Java를 위한, Java에 의한 도구들
 
안드로이드 플랫폼 설명
안드로이드 플랫폼 설명안드로이드 플랫폼 설명
안드로이드 플랫폼 설명
 
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoLinux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
 

Mehr von wonyong hwang

Hyperledger Explorer.pptx
Hyperledger Explorer.pptxHyperledger Explorer.pptx
Hyperledger Explorer.pptxwonyong hwang
 
하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회wonyong hwang
 
토큰 증권 개요.pptx
토큰 증권 개요.pptx토큰 증권 개요.pptx
토큰 증권 개요.pptxwonyong hwang
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptxwonyong hwang
 
k8s practice 2023.pptx
k8s practice 2023.pptxk8s practice 2023.pptx
k8s practice 2023.pptxwonyong hwang
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfwonyong hwang
 
Ngrok을 이용한 Nginx Https 적용하기.pptx
Ngrok을 이용한 Nginx Https 적용하기.pptxNgrok을 이용한 Nginx Https 적용하기.pptx
Ngrok을 이용한 Nginx Https 적용하기.pptxwonyong hwang
 
Nginx Https 적용하기.pptx
Nginx Https 적용하기.pptxNginx Https 적용하기.pptx
Nginx Https 적용하기.pptxwonyong hwang
 
Kafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxKafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxwonyong hwang
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxwonyong hwang
 
Kafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and GrafanaKafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and Grafanawonyong hwang
 
주가 정보 다루기.pdf
주가 정보 다루기.pdf주가 정보 다루기.pdf
주가 정보 다루기.pdfwonyong hwang
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)wonyong hwang
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composerwonyong hwang
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by pythonwonyong hwang
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slidesharewonyong hwang
 

Mehr von wonyong hwang (19)

Hyperledger Explorer.pptx
Hyperledger Explorer.pptxHyperledger Explorer.pptx
Hyperledger Explorer.pptx
 
하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회
 
토큰 증권 개요.pptx
토큰 증권 개요.pptx토큰 증권 개요.pptx
토큰 증권 개요.pptx
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptx
 
k8s practice 2023.pptx
k8s practice 2023.pptxk8s practice 2023.pptx
k8s practice 2023.pptx
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdf
 
Ngrok을 이용한 Nginx Https 적용하기.pptx
Ngrok을 이용한 Nginx Https 적용하기.pptxNgrok을 이용한 Nginx Https 적용하기.pptx
Ngrok을 이용한 Nginx Https 적용하기.pptx
 
Nginx Https 적용하기.pptx
Nginx Https 적용하기.pptxNginx Https 적용하기.pptx
Nginx Https 적용하기.pptx
 
Kafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxKafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptx
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptx
 
Kafka Rest.pptx
Kafka Rest.pptxKafka Rest.pptx
Kafka Rest.pptx
 
Kafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and GrafanaKafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and Grafana
 
주가 정보 다루기.pdf
주가 정보 다루기.pdf주가 정보 다루기.pdf
주가 정보 다루기.pdf
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)
 
kubernetes practice
kubernetes practicekubernetes practice
kubernetes practice
 
Docker practice
Docker practiceDocker practice
Docker practice
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composer
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by python
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slideshare
 

Hyperledger fabric practice(pdf)

  • 2. environment setup ! ubuntu 16.04 or higher ! root 권한으로 설치 ! apt-get update ! apt-get install curl ! apt-get install python-pip ! apt-get install libltdl-dev ! apt-get install make gcc g++ libtool ! apt-get install tree
  • 3. environment setup ! git apt-get install -y git git version ! Python: 2.7.x python –version (apt-get install -y python) ! Go lang Version 1.11.x wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz tar -C /usr/local/ -xvf go1.11.4.linux-amd64.tar.gz ! Go 환경변수 설정 vi /etc/profile export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin source /etc/profile go version source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
  • 4. environment setup ! Docker Engine: Version 17.06.2-ce or higher wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker- ce_17.06.2~ce-0~ubuntu_amd64.deb dpkg -i docker-ce_17.06.2~ce-0~ubuntu_amd64.deb docker --version ! Docker-Compose: Version 1.14 or higher curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose- `uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose version ! Node.js (Version 8.9 or higher (no version 9.0 support) / npm (Version 6.x) curl -sL http://deb.nodesource.com/setup_8.x | bash - apt-get install nodejs node -v npm -v source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/prereqs.html
  • 5. environment setup ! Hyperledger Fabric curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.0 1.4.0 0.4.10 (curl -sSL https://goo.gl/6wtTN5 | bash -s 1.4.1 1.4.1 0.4.10) (curl -sSL https://bit.ly/2KLpv5d | bash -s 1.4.0 –d -s) ! ! vi /etc/profile export FABRIC_HOME=/home/fabric/fabric-samples export PATH=$PATH:$FABRIC_HOME/bin source /etc/profile [참고] 최신 버전 설치시(2.0) 아래 명령으로 실행 (V2.0에서는 본 교안에서 설명하는 예제가 정상 실행되지 않음. 예제의 버전이 2.0 기준으로 수정되어야 함) v2.0은 체인코드 라이프싸이클이 더 상세해짐 curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s https://hyperledger-fabric.readthedocs.io/en/release-1.4/samples.html#binaries | bash -s <fabric> <fabric-ca> <thirdparty> source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html
  • 7. 개요 ! The build your first network (BYFN) scenario provisions a sample Hyperledger Fabric network consisting of two organizations, each maintaining two peer nodes. It also will deploy a “Solo” ordering service by default, though other ordering service implementations are available. source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html
  • 8. configtx.yaml ! 채널 생성을 위한 Peer 정보 ( Host, Port), MSP 정보, Consortiums(몇 개의 Org로 구성할 것인지) 설정
 - 블럭 생성 크기 등과 관련된 설정
 BatchTimeout, 
 BatchSize - MaxMessageCount
 AbsoluteMaxBytes
 PreferredMaxBytes ! 3가지 파일을 결과적으로 생성
 - 최초 블록 정보 genesis.block - 앵커 피어 정보 anchor.tx (Org1MSPanchor.tx, Org2MSPanchor.tx) - 채널 구성 정보 channel.tx
  • 9. crypto-config.yaml ! 인증서 생성을 위한 조직과 Peer 개수, 사용자(어드민 제외) 수 설정
  • 11. ./byfn.sh generate root@ubuntu:~/fabric-samples/first-network# ./byfn.sh generate Generating certs and genesis block for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds Continue? [Y/n] Y proceeding ... /root/fabric-samples/first-network/../bin/cryptogen ########################################################## ##### Generate certificates using cryptogen tool ######### ########################################################## + cryptogen generate --config=./crypto-config.yaml org1.example.com org2.example.com + res=0 + set +x /root/fabric-samples/first-network/../bin/configtxgen ########################################################## ######### Generating Orderer Genesis block ############## ########################################################## CONSENSUS_TYPE=solo + '[' solo == solo ']' + configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block 2020-02-03 22:57:08.847 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-02-03 22:57:08.905 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo 2020-02-03 22:57:08.906 KST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml 2020-02-03 22:57:08.961 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo 2020-02-03 22:57:08.962 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml 2020-02-03 22:57:08.965 KST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block 2020-02-03 22:57:08.966 KST [common.tools.configtxgen] doOutputBlock -> INFO 007 Writing genesis block + res=0 + set +x ################################################################# ### Generating channel configuration transaction 'channel.tx' ### ################################################################# + configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel 2020-02-03 22:57:09.005 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration 2020-02-03 22:57:09.048 KST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml 2020-02-03 22:57:09.089 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo 2020-02-03 22:57:09.090 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/fabric-samples/first-network/configtx.yaml 2020-02-03 22:57:09.090 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx 2020-02-03 22:57:09.092 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx + res=0 제네시스 블록 생성 채널 환결설정 앵커피어 설정 모두/channel-artifacts/ 하위에 결과파일로 저장
  • 13.
  • 15. ! 인증기관(CA), 공개키, 개인키, 인증서(CRT) source : http://soul0.tistory.com/372 intro CA 살펴보기
  • 16. hyperledger의 인증 ! 하이러페저는 모든 노드들이 자신들의 인증을 CA를 통해 받는다. ! Root CA ! 자식 CA ! * ! 앞서 살펴본 cryptogen 을 통해서 CA를 구성할 수 있음
 (Fabric CA Server를 통해서도 CA구성 가능, Fabric-CA Client 또는 Fabric SDK를 통해 서도 인증서 발급 및 조회 등의 서비스 이용가능) ! 인증 대상
 - 전체 네트워크, 채널, 조직(Org), 조직 관리자(Admin), 사용자(User), Peer source : https://hyperledger-fabric-ca.readthedocs.io/en/latest/users-guide.html CA 살펴보기
  • 17. hyperledger MSP ! MSP (Membership Service Provider)는 멤버쉽 서비스 제공 목적의 컴포넌트 ! 인증서를 발급/조회/검증하는 등 사용자 및 서비스의 인증에 대한 작업 ! 조직마다 보통 하나의 MSP가 있으며 MSP ID로 구분된다. - 전체 네트워크, 채널, 조직(Org), 조직 관리자(Admin), 사용자(User), Peer // mspID 와 certCN 을 조건으로 검사하여 함수의 사용가능 여부를 판단할 수 있음 func authenticateOrg(mspID string, certCN string) bool { return (mspID == "Org1MSP") && (certCN == "ca.example.com") } CA 살펴보기 source : https://github.com/hyperledger/fabric/blob/release-1.4/msp/msp.go
  • 18. check private key ! root@ubuntu:~/fabric-samples/first-network# find | grep -E '/ca.*_sk' | sort ./crypto-config/ordererOrganizations/example.com/ca/d6c3aff453b6947f13e189a3d3cb60f1d42addf2295acca28aed14f3d4827c21_sk ./crypto-config/peerOrganizations/org1.example.com/ca/c9681f8d01403a2be7a2df7b2bd2ebdc691288d64ae0209b6270facf822fa7e1_sk ./crypto-config/peerOrganizations/org2.example.com/ca/36ea9dbed56ffa19a337c3f3b838682ebd11edd84b51fe6e0f700f7e1a3a4044_sk CA 살펴보기
  • 19. ├── ordererOrganizations │   └── example.com │   ├── ca │   │   ├── 5a4cfffc67e06260ef685ffa0559975f54912df5127d9bbf0ece4c7b83f9caeb_sk │   │   └── ca.example.com-cert.pem │   ├── msp │   │   ├── admincerts │   │   │   └── Admin@example.com-cert.pem │   │   ├── cacerts │   │   │   └── ca.example.com-cert.pem │   │   └── tlscacerts │   │   └── tlsca.example.com-cert.pem │   ├── orderers │   │   └── orderer.example.com │   │   ├── msp │   │   │   ├── admincerts │   │   │   │   └── Admin@example.com-cert.pem │   │   │   ├── cacerts │   │   │   │   └── ca.example.com-cert.pem │   │   │   ├── keystore │   │   │   │   └── 829584340955b187ecc5b1cef386736fd3666ffcd0600ef3f4bc2015c2e36d34_sk │   │   │   ├── signcerts │   │   │   │   └── orderer.example.com-cert.pem │   │   │   └── tlscacerts │   │   │   └── tlsca.example.com-cert.pem │   │   └── tls │   │   ├── ca.crt │   │   ├── server.crt │   │   └── server.key │   ├── tlsca │   │   ├── 419de30afd02a9ac15cc62acf07509c9497c792cc938d19cbac7484c6ff7455b_sk │   │   └── tlsca.example.com-cert.pem │   └── users │   └── Admin@example.com │   ├── msp │   │   ├── admincerts │   │   │   └── Admin@example.com-cert.pem │   │   ├── cacerts │   │   │   └── ca.example.com-cert.pem │   │   ├── keystore │   │   │   └── cbd8cba235aafc20622a3056b153129a8dd7efea1a11c0b9b3d75cd94ea47ebd_sk │   │   ├── signcerts │   │   │   └── Admin@example.com-cert.pem │   │   └── tlscacerts │   │   └── tlsca.example.com-cert.pem │   └── tls │   ├── ca.crt │   ├── client.crt │   └── client.key example.com의 비밀키와 인증서 [MSP] 관리자용 인증서 [MSP] CA식별 인증서 [MSP] TLS 통신용 인증서 orderer.example.com example.com 상위 조직의 어드민 인증서와 CA 인증서를 복사 org.example.com의 비밀키와 인증서 각 노드의 HTTPS 통신용 인증서와 비밀키 각 사용자의의 HTTPS 통신용 인증서와 비밀키 동일 파일 동일 파일 CA 살펴보기
  • 20. └── peerOrganizations ├── org1.example.com │   ├── ca │   │   ├── b6f3f5b3d200ec42cbbe11cff35d7d588b680a0fa10d650d99a7ef1b8470f855_sk │   │   └── ca.org1.example.com-cert.pem │   ├── msp │   │   ├── admincerts │   │   │   └── Admin@org1.example.com-cert.pem │   │   ├── cacerts │   │   │   └── ca.org1.example.com-cert.pem │   │   ├── config.yaml │   │   └── tlscacerts │   │   └── tlsca.org1.example.com-cert.pem │   ├── peers │   │   ├── peer0.org1.example.com │   │   │   ├── msp │   │   │   │   ├── admincerts │   │   │   │   │   └── Admin@org1.example.com-cert.pem │   │   │   │   ├── cacerts │   │   │   │   │   └── ca.org1.example.com-cert.pem │   │   │   │   ├── config.yaml │   │   │   │   ├── keystore │   │   │   │   │   └── 81d0884d3094c1a56799c113a76a1ddb9989fda14d96e0f793d3e696f23dca2b_sk │   │   │   │   ├── signcerts │   │   │   │   │   └── peer0.org1.example.com-cert.pem │   │   │   │   └── tlscacerts │   │   │   │   └── tlsca.org1.example.com-cert.pem │   │   │   └── tls │   │   │   ├── ca.crt │   │   │   ├── server.crt │   │   │   └── server.key │   │   └── peer1.org1.example.com │   │   ├── msp │   │   │   ├── admincerts │   │   │   │   └── Admin@org1.example.com-cert.pem │   │   │   ├── cacerts │   │   │   │   └── ca.org1.example.com-cert.pem │   │   │   ├── config.yaml │   │   │   ├── keystore │   │   │   │   └── dfc4d5a95b62a6fa6aa0a45f822d068139756b2b40e8b392173491e3f768f6f9_sk │   │   │   ├── signcerts │   │   │   │   └── peer1.org1.example.com-cert.pem │   │   │   └── tlscacerts │   │   │   └── tlsca.org1.example.com-cert.pem │   │   └── tls │   │   ├── ca.crt │   │   ├── server.crt │   │   └── server.key │   ├── tlsca org*.example.com example.com peer*.org*.example.com └── users │   ├── Admin@org1.example.com │   │   ├── msp │   │   │   ├── admincerts │   │   │   │   └── Admin@org1.example.com-cert.pem │   │   │   ├── cacerts │   │   │   │   └── ca.org1.example.com-cert.pem │   │   │   ├── keystore │   │   │   │   └── 9e3ebb8985cc6f6c053297825d6bbef822f4c43ea5a7e7d277dd96be1f80e9ec_sk │   │   │   ├── signcerts │   │   │   │   └── Admin@org1.example.com-cert.pem │   │   │   └── tlscacerts │   │   │   └── tlsca.org1.example.com-cert.pem │   │   └── tls │   │   ├── ca.crt │   │   ├── client.crt │   │   └── client.key │   └── User1@org1.example.com │   ├── msp │   │   ├── admincerts │   │   │   └── User1@org1.example.com-cert.pem │   │   ├── cacerts │   │   │   └── ca.org1.example.com-cert.pem │   │   ├── keystore │   │   │   └── 0a9f665b540e722ea214dd280904f9a92cbac7b647b4853124174ecf2973c898_sk │   │   ├── signcerts │   │   │   └── User1@org1.example.com-cert.pem │   │   └── tlscacerts │   │   └── tlsca.org1.example.com-cert.pem │   └── tls │   ├── ca.crt │   ├── client.crt │   └── client.key NodeOUs: Enable: true ClientOUIdentifier: Certificate: cacerts/ca.org1.example.com-cert.pem OrganizationalUnitIdentifier: client PeerOUIdentifier: Certificate: cacerts/ca.org1.example.com-cert.pem OrganizationalUnitIdentifier: peer CA 살펴보기
  • 21. [참고] 인증서 살펴보기 root@fabric:/home/fabric/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/ca# openssl x509 -text -noout -in ca.example.com-cert.pem Certificate: Data: Version: 3 (0x2) Serial Number: d9:d9:d3:61:6d:0d:28:6f:e2:5d:30:05:82:01:cd:38 Signature Algorithm: ecdsa-with-SHA256 Issuer: C = US, ST = California, L = San Francisco, O = example.com, CN = ca.example.com Validity Not Before: Mar 12 03:40:00 2020 GMT Not After : Mar 10 03:40:00 2030 GMT Subject: C = US, ST = California, L = San Francisco, O = example.com, CN = ca.example.com Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (256 bit) pub: 04:c1:e2:fd:33:bc:3d:b9:6b:1b:6a:da:5e:a0:36: 9a:dd:c2:23:9c:c8:7a:ec:b9:e7:54:c4:72:11:19: 85:33:1f:6a:62:e4:1d:c9:ae:e4:e0:2e:12:a0:5e: 7a:d6:c5:51:5c:70:21:29:27:5d:59:d0:17:2b:f9: 4c:0b:f6:9f:d4 ASN1 OID: prime256v1 NIST CURVE: P-256 X509v3 extensions: X509v3 Key Usage: critical Digital Signature, Key Encipherment, Certificate Sign, CRL Sign X509v3 Extended Key Usage: TLS Web Client Authentication, TLS Web Server Authentication X509v3 Basic Constraints: critical CA:TRUE X509v3 Subject Key Identifier: A6:EE:42:3F:D2:81:13:DB:1A:12:3E:5D:57:75:92:43:BD:D8:C4:AE:8C:51:3D:86:28:F9:69:BD:B4:F7:37:0A Signature Algorithm: ecdsa-with-SHA256 30:44:02:20:77:12:a9:2b:27:dd:7e:d7:a5:1f:f4:44:c2:00: b5:e8:ff:b4:cf:07:aa:e4:e5:d2:68:0f:f3:f2:0b:6c:17:c4: 02:20:28:cc:a1:82:4b:e1:0c:38:fa:9e:e8:a9:62:27:29:16: 5a:20:e2:58:bb:b9:2d:ea:f9:f9:5f:a1:b8:c7:2e:e4 CA 살펴보기
  • 22. [참고] hyperledger fabric ca 실습 ! CA Server, Client 설치 및 실습 https://ovila.tistory.com/68 ! Hyperledger Fabric 멀티호스트 환경 구축  https://leejonggun.tistory.com/15 CA 살펴보기
  • 23. peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile ~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem [채널 생성 요청] orderer에 생성 요청시 TLS 통신 사용하며 TLS인증서 위치를 지정함(tlsca.example.com-cert.pem) CORE_PEER_MSPCONFIGPATH =~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_TLS_ROOTCERT_FILE=~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt peer channel join -b mychannel.block [채널 조인 요청] CORE_PEER_MSPCONFIGPATH =~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_TLS_ROOTCERT_FILE =~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt export CHANNEL_NAME=mychannel peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile ~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem [채널 업데이트 요청 ] orderer에 채널 업데이트 요청 org1의 peer0, peer1 org2의 peer0, peer1 방식 동일하게 모두 수행 /scripts/util.sh 의 setGlobals함수내 설정 코드 참조 전체 실행 순서 (1/2) CA 살펴보기
  • 24. peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile ~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('''Org1MSP.peer''','''Org2MSP.peer''')' [체인코드 인스턴스화] orderer를 통해 수행 peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile ~중략~/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles ~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles ~중략~/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt –c '{"Args":["invoke","a","b","10"]}' [체인코드 실행] orderer를 통해 수행 CORE_PEER_MSPCONFIGPATH=~중략~/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp CORE_PEER_ADDRESS=peer0.org1.example.com:7051 CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_TLS_ROOTCERT_FILE=~중략~/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/ [체인코드 인스톨] peer를 통해 설치 각 org의 anchor peer에 설치
 org1의 peer0 org2의 peer0 방식 동일하게 모두 수행 전체 실행 순서 (2/2) CA 살펴보기
  • 25. docker-compose 설정 파일 확인 docker-compose-cli.yaml의 base가 되는 base/docker-compose-base.yaml에서는 ./byfn.sh generat를 통해 생성된 인증서 정보를 볼륨 마운트하고 마운트된 도커 이미지의 해당 디렉토리로 환경변수 설정을 함
  • 26. ./byfn.sh up ===================== Chaincode is installed on peer0.org2 ===================== Instantiating chaincode on peer0.org2... + res=0 + set +x + peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P 'AND ('''Org1MSP.peer''','''Org2MSP.peer''')' …. 생략 … ===================== Chaincode is instantiated on peer0.org2 on channel 'mychannel' ===================== Querying chaincode on peer0.org1... ===================== Querying on peer0.org1 on channel 'mychannel'... ===================== + res=0 + set +x + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' Attempting to Query peer0.org1 ...3 secs + res=0 + set +x 100 ===================== Query successful on peer0.org1 on channel 'mychannel' ===================== Sending invoke transaction on peer0.org1 peer0.org2... + peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/ tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt –c '{"Args":["invoke","a","b","10"]}' 2020-02-04 06:05:19.250 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200 ===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' ===================== Installing chaincode on peer1.org2... + res=0 + set +x + peer chaincode install -n mycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/ …. 생략 … ===================== Chaincode is installed on peer1.org2 ===================== Querying chaincode on peer1.org2... ===================== Querying on peer1.org2 on channel 'mychannel'... ===================== + res=0 + set +x
  • 27. docker-compose-cli 살펴보기 Org1의 Peer0인 피어에 접속하도록 환경변수가 설정됨 해당 피어에 채널 생성, 참가, 앵커 피어 갱신, 체인코드 설치/초기화/질의/호출을 수행한다. (createChannel, joinChannel, updateAnchorPeers, installChaincode, instantiateChaincode, chaincodeQuery, chaincodeInvoke) createChannel, joinChannel, updateAnchorPeers, installChaincode, instantiateChaincode, chaincodeQuery, chaincodeInvoke 명령은 byfn.sh의 networkUp함수내에서 docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE 로 호출됨 scripts.sh은 cli 도커에 볼륨 마운트됨으로 cli 에서 수행 가능함
  • 28. chaincode 위치 확인 environment: - GOPATH=/opt/gopath volumes: - /var/run/:/host/var/run/ - ./../chaincode/:/opt/gopath/src/github.com/chaincode - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/ - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts CC_SRC_PATH="github.com/chaincode/chaincode_example02/go/" peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >&log.txt peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -l ${LANGUAGE} -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer') util.sh script.sh
  • 29. chaincode 수정 및 배포하기 ./bynf.sh 에서 script.sh을 docker exec cli scripts/script.sh $CHANNEL_NAME $CLI_DELAY $LANGUAGE $CLI_TIMEOUT $VERBOSE 로 실행함. 즉, cli 도커에서 체인코드 install/instantiate를 수행함 체인코드를 수정 - invoke(stub shim.ChaincodeStubInterface, args []string) 함수에서
 우측 그림과 같이 -10 을 추가 ./byfn.sh down ./byfn.sh up ===================== Querying on peer1.org2 on channel 'mychannel'... ===================== + res=0 + set +x + peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' Attempting to Query peer1.org2 ...3 secs + res=0 + set +x 80 !!!!!!!!!!!!!!! Query result on peer1.org2 is INVALID !!!!!!!!!!!!!!!! 수행결과 util.sh의 chaincodeQuery함수에서 기대한 결과인 90을 충족하지 못하므로 에러로 표시하였으나, 체인코드를 수정한 의도와 부합하는 결과를 확인할 수 있음 docker-compose-cli.yaml에 cli 컨테이너 정의부분에 volumes: ../../chaincode/:/opt/gopath/src/github.com/chaincode 으로 변경한 체인코드를 그대로 cli 컨테이너에 볼륨 마운트하므로 도커를 시작하면 변경된 코드를 cli에서 install할 수 있음
  • 30. couchdb 사용하기 ! ./byfn.sh up -c mychannel -s couchdb 값 ’90’ 확인가능 couch db+fabric tutorial : https://hyperledger-fabric.readthedocs.io/en/release-1.4/couchdb_tutorial.html 4개의 couch db가 4개의 peer에 연결되는 구조로 컨테이너 기동
  • 32. 사전 준비 ! docker rm –f $(docker ps –a -q) ! 샘플예제가 있는 디렉토리로 이동(fabric-samples/chaincode-docker-devmode) ! 3개의 터미널을 오픈하여 상기 디렉토리로 이동 ! docker-compose-simple.yaml 구성 확인
 - orderer, peer, cli(체인코드 인스톨 및 인터랙션), chaincode(체인코드 개발 환경) 컨테이너로 구성 cli: container_name: cli image: hyperledger/fabric-tools tty: true …중략… working_dir: /opt/gopath/src/chaincodedev command: /bin/bash -c './script.sh' volumes: …중략… - ./../chaincode:/opt/gopath/src/chaincodedev/chaincode - ./:/opt/gopath/src/chaincodedev/ chaincode: container_name: chaincode image: hyperledger/fabric-ccenv tty: true environment: …중략… - CORE_PEER_ADDRESS=peer:7051 …중략… working_dir: /opt/gopath/src/chaincode command: /bin/bash -c 'sleep 6000000' volumes: …중략… - ./../chaincode:/opt/gopath/src/chaincode source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
  • 33. Terminal 1 - Start the network ! docker-compose -f docker-compose-simple.yaml up source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode
  • 34. Terminal 2 - Build & start the chaincode ! docker exec -it chaincode sh ! cd /opt/gopath/src/chaincode ! cd chaincode_example02/go ! go build -o chaincode_example02 ! CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:0 ./chaincode_example02 docker exec –it chaincode /bin/bash source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode Normally chaincodes are started and maintained by peer. However in “dev mode", chaincode is built and started by the user. ! BYFN 에서는 peer를 통해 시작/관리하고 cli 컨테이너에서 체인코드 설치 및 초기화를 하였으나, 본 예제에서는 사용자가 위 명령을 통해 체인코드를 먼저 실행 상태로 만든다. docker-compose-simple.yaml 의 peer 컨테이너 Command 섹션에 —peer-chaincodedev = true 라고 설정됨
  • 35. Terminal 3 - Use the chaincode ! docker exec -it cli bash ! peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 0 ! peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc ! peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc ! peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc source : https://github.com/hyperledger/fabric-samples/tree/release-1.4/chaincode-docker-devmode source : https://nick-fabric.readthedocs.io/en/latest/commands/peerchaincode.html 여기까지는 Build Your First Network 체인코드와 동일하다. 이제 일부 코드를 추가하여 다시 배포해 보자. terminal2 에서 chaincode를 실행하지 않으면 에러발생
  • 36. local development env. ! visual studio code 설치 + GO addon 추가 설치 ! visual studio code 에서 소스 추적 및 빌드 가능 $GOROOT/src/ 에서 다음과 같이 hlf 라이브러리 추가 mkdir -p github.com/hyperledger cd github.com/hyperledger/ git clone -b release-1.4 https://github.com/wonyongHwang/fabric.git 우측 그림의 소스는 $GOPATH/src/[임의 폴더명]/chiancode_example.go에 위치시킴 % pwd /Users/hwang-won-yong/go/src/sacc % ls chaincode_example02.go Visual studio Go extension의 settings.jon 설정내용: { "go.formatTool": "goimports", "go.useLanguageServer": true } 상기 설정 이후 VS 재시작 —> 라이브러리에 밑 줄이 보이고, 해당 정의부로 이동도 가능하게 됨
  • 37. chaincode download/upload via sftp ! ftp root access/login 허용 ! Visual Studio Code에 ftp simple plugin 설치 ! F1을 누른 다음  ftp-simple:Config - FTP connection setting 를 선택하고 우측
 그림과 같이 편집 ! F1을 누른 다음 tp-simple:Open - Open the file directly from FTP server를 선택
 하고 localhost를 클릭하면 접속됨 ! 접속 이후 체인코드 클릭하여 편집창에서 오픈 ! $GOPATHSRCchaincode_example02 폴더를 생성하고
 해당 폴더 하위에 chaincode_example02.go 파일로 save as… 한다. (소스 분석용) visual studio code 플러그인 설치 출처 : https://www.manualfactory.net/10964
  • 38. chaincode 수정 ! 공식 튜토리얼을 참조하여 아래와 같이 수정 공식 튜토리얼 : https://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html#terminal-1-start-the-network func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {     fmt.Println("ex02 Invoke")     function, args := stub.GetFunctionAndParameters()     if function == "invoke" {         // Make payment of X units from A to B         return t.invoke(stub, args)     } else if function == "delete" {         // Deletes an entity from its state         return t.delete(stub, args)     } else if function == "query" {         // the old "Query" is now implemtned in invoke         return t.query(stub, args)     } else if function == "set" {         // the old "Query" is now implemtned in invoke         return t.set(stub, args)     }     return shim.Error("Invalid invoke function name. Expecting "invoke" "delete" "query"") } func (t *SimpleChaincode) set(stub shim.ChaincodeStubInterface, args []string) pb.Response {     var A string     var Aval int     var err error     if len(args) != 2 {         return shim.Error("Incorrect number of arguments. Expecting 2")     }     A = args[0]     Aval, err = strconv.Atoi(args[1])     fmt.Printf("################### Aval = %d", Aval)     if err != nil {         return shim.Error("IT IS NOT AN INTEGER VALUE")     }     err = stub.PutState(A, []byte(args[1]))     if err != nil {         return shim.Error(err.Error())     }     return shim.Success(nil) } 코드 수정 후 빌드 테스트
  • 39. chaincode 배포 및 테스트 ! docker-compose –f docker-compose-simple.yaml down ! docker-compose –f docker-compose-simple.yaml up ! 이전 terminal2, terminal3에서 수행했던 내용 동일 반복하고 코드에서 추가한 set 명령 에 대해 추가로 확인 peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc peer chaincode invoke -n mycc -c '{"Args":["set","a","1000"]}' -C myc peer chaincode query -n mycc -c '{"Args":["query",“a"]}' -C myc Aval = 100, Bval = 200 ex02 Invoke Aval = 80, Bval = 210 ex02 Invoke Query Response:{"Name":"a","Amount WOW":"80"} ex02 Invoke ################### Aval = 1000 ex02 Invoke Query Response:{"Name":"a","Amount WOW":"1000"} terminal2 terminal3
  • 40. [참고] peer chaincode upgrade ! 모든 컨테이너 기동 상태에서 체인코드 업그레이드 실시 ! VS CODE 에서 소스 변경 및 저장/업로드 terminal2 go build -o chaincode_example02 CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=mycc:1 ./chaincode_example02 terminal3 peer chaincode install -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v 1 peer chaincode upgrade -p chaincodedev/chaincode/chaincode_example02/go -n mycc -v1 -C myc -c '{"Args":["init","a","100","b","200"]}' peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc peer chaincode invoke -n mycc -c '{"Args":["set","a","1000"]}' -C myc 소스 수정 -> 로컬 빌드 -> FTP 업로드 새로운 terminal을 띄워서 위 terminal2의 내용을 수행함 기존 terminal2는 업그레이드 완료시 peer에 대한 응답을 더 이상 하지 않게 됨
  • 41. [chaincode dev.] PutState 실습 func (t *SimpleChaincode) more(stub shim.ChaincodeStubInterface, param []string) pb.Response { if len(param) != 3 { return shim.Error("# of parameter mismatching") } title, text, code := param[0], param[1], param[2] codeNum, err := strconv.ParseInt(code, 10, 32) if err != nil { return shim.Error("code error") } if len(title) == 0 || len(text) == 0 || len(code) == 0 { return shim.Error("value of paramter is not properly formatted") } // make my data of AdditionalInfo addInfo := &AdditionalInfo{Title: title, Text: text, code: codeNum} addInfoBytes, err := json.Marshal(addInfo) if err != nil { return shim.Error("failed to convert bytes " + err.Error()) } err = stub.PutState(title, addInfoBytes) // key value에 공백 들어가면 조회시 값을 찾지 못함 if err != nil { return shim.Error("PutState failure " + err.Error()) } return shim.Success([]byte("invoke success")) } invoke에 more 함수 추가하고 로컬빌드 -> ftp 업로드 -> Terminal2에서 서버빌드 및 실행 -> Terminal3에서 CC인스톨 및 업그레이드 -> 아래와 같이 테스트 peer chaincode invoke -n mycc -c '{"Args":["more","tt","Here your are, this is a book 2","1200"]}' -C myc type AdditionalInfo struct { Title string "json:"title"" Text string "json:"text"" code int64 "json:"code"" }
  • 42. [chaincode dev.] GetState 실습 func (t *SimpleChaincode) morequery(stub shim.ChaincodeStubInterface, args []string) pb.Response { var A string // Entities var err error if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting name of the person to query") } A = args[0] // Get the state from the ledger valbytes, err := stub.GetState(A) if err != nil { jsonResp := "{"Error":"Failed to get state for " + A + ""}" return shim.Error(jsonResp) } valueStr := &AdditionalInfo{} err = json.Unmarshal(valbytes, &valueStr) if err != nil { jsonResp := "{"Error":"Failed to Unmarshal " + A + ""}" return shim.Error(jsonResp) } jsonResp := "{"Title":"" + A + "","Text":"" + string(valueStr.Text) + ""}" fmt.Printf("Query Response:%sn", jsonResp) // history iter, _ := stub.GetHistoryForKey(A) fmt.Println("Here is History for " + A) for iter.HasNext() { kv, _ := iter.Next() fmt.Println(string(kv.GetValue()) + " " + kv.GetTimestamp().String()) } return shim.Success([]byte(string(valueStr.code))) } query에 morequery 함수 추가하고 로컬빌드 -> ftp 업로드 -> Terminal2에서 서버빌드 및 실행 -> Terminal3에서 CC인스톨 및 업그레이드 -> 아래와 같이 테스트 peer chaincode query -n mycc -c '{"Args":["morequery","tt"]}' -C myc GetHistoryForKey 함수로 변경 이력 조회 Git hub : https://github.com/wonyongHwang/chaincode-tutorial/blob/master/kopoChainCode.go
  • 43. [참고] 공식 튜토리얼 체인코드에서… source : https://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html#terminal-1-start-the-network main 함수에서 fabric chaincode의 Start 함수를 호출 이 때 전달되는 파라미터는 type SimpleAsset struct{} 의 객체임. 소스코드상 SimpleAsset의 Init,Invoke 함수를 구현하였으므로 ChainCode 객체로 전달 가능
  • 44. [참고] 체인코드 호출 ! 동일 채널에서 같은/다른 Chaincode 호출(invoke/query) 가능 ! 다른 채널의 chaincode는 조회(query)만 가능 -예시- channel := stub.GetChannelID() stub.InvokeChaincode(chaincodeName, args, channel)
  • 46. Balance transfer example (개요) ! 2 CA, x Orderer, 2 Peer 로 구성 ! 기본적으로는 Build Your Network First와 유사한 구조이나, 여기서는 cli 컨테이너가 없음. 대신 Hyperledger fabric SDK를 이용한 node.js구현체를 통해서 채널생성, 체인코드 설치 등을 진행하게 됨. ! Build Your Network First의 기본 실행 구조에서는 CA 서버 없이 cryptogen을 통해 미리 생성해 놓은 인증서를 사용하여 통신 하였으나, 이번 예제는 미리 생성한 인증서 정보를 토대로 CA서버를 기동하고, Node.js Client에서 요청하는 사용자 등록을 CA 서버에서 인증하고 처리하도록 구성 되었음 * 해당 예제 폴더에 위치한 ~e2e.yaml 로 실행시 ca 서버 기동됨
  • 47. Balance transfer example (실행 준비) ! 노드 버전 확인(node -v) balance transfer 예제는 노드 버전 10.x 이상에서 오류 발생 -> 8.* 또는 9.* 설치 기존 node.js 삭제시 : apt-get --purge remove nodejs node.js 설치 : curl -sL http://deb.nodesource.com/setup_9.x | bash - apt-get install node.js * 해당 예제는 fabric 2.0 기본 샘플예제에서 삭제됨(fabric 1.4에서 실행권장) ! 컨테이너 및 이미지 등 도커관련 파일 삭제 (충돌방지) docker rm -f $(docker ps -a -q) docker rmi -f $(docker images -a -q) docker volume prune docker system prune docker network prune
  • 48. Balance transfer example (fabric 실행) ! ./runApp.sh 실행
  • 49. Balance transfer example (REST 호출) ./testAPIs.sh 을 실행하여 사용자 등록~체인코드 실행까지 정상 진행 되는지 확인 * chaincode instantiate 실행시 time out 으로 오류발생되는 경우, 아래 그림과 같이 testAPIs.sh의 일부분을 수정 (timeout 옵션 추가)
  • 50. [심화] 더 살펴볼 포인트 ! ./testAPIs.sh 의 REST CALL 호출 순서와 내용을 확인 ! Node 소스는 app.js가 시작점 ! 사용자 등록을 위해 /users 호출시에는 fabric ca server를 통해 신규 사용자 등록을 하고 토큰을 부여함 ! /users 이외의 호출 주소는 JWT 토큰 유효성 검사가 이루어짐 ! Proposal을 먼저 endorsing peer에 보내고, 해당 피어에서 사전 검증한 결과를 확인하고 orderer에게 검증결과와 트랜잭션 반영요청을 하는 부분 —> invoke-tansaction.js의 sendTransactionProposal 및 sendTransaction 호출 코드 참조

  • 51. [심화] sdk를 이용한 사용자 등록 과정 ! 기 발급받은 인증서를 이용 ! app.post('/users', async function(req, res) { … let response = await helper.getRegisteredUser(username, orgName, true); …} app.js Network-config.yaml과 org1.yaml 설정파일을 로딩하여 initCredential을 수행 등록된 사용자 없는 경우; config.json의 admin/adminpw 계정정보를 이용해 새로운 사용자를 등록(getCertificateAuthority로 인증서 로딩)
  • 52. [심화] fabric ca container Node sdk client의 config.js에 설정된 계정정보와 일치해야 함 "admins":[ { "username":"admin", "secret":"adminpw" } ]
  • 53. [참고] fabric server <-> node.js(SDK) local —> 로컬에서 node.js 디버깅을 visual studio로 편하게 진행 가능함
  • 54. [참고] fabric server <-> node.js(SDK) local 사전 준비사항 - local pc visual studio code 설치 nvm 설치(https://gofnrk.tistory.com/32) balance transfer 예제 local 복사 + npm rebuild virtual box 포트 오픈 (유저 등록을 위해서 ca 서버 접속필요—> 7054 포트 연결 설정) (체인코드 실행 및 쿼리 등을 위해서 오더러(7050) 등 필요시 추가로 포트 연결 설정해야 함) - 수행 순서 fabric server 기동(./runApp.sh) -> 로컬에서 node 실행해야 하므로 서버측에서는 node 실행부분 주석처리 local의 balance transfer 예제 폴더 중 인증토큰과 관련된 폴더 삭제 rm -rf fabric-client-kv-org* REST 호출 수행 hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST http://localhost:4000/users -H "content-type: application/x-www-form-urlencoded" -d 'username=Jim&orgName=Org1' {"success":true,"secret":"","message":"Jim enrolled Successfully","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjU1NjMsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxODk1NjN9.h2v6HzQJdDSUryGEsqPyUbV9SK91GGgTF4_7LCzg "}% 사용자 등록
  • 55. hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST http://localhost:4000/channels -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" -H "content-type: application/json" -d '{ "channelName":"mychannel", "channelConfigPath":"../artifacts/channel/mychannel.tx" }' {"success":true,"message":"Channel 'mychannel' created Successfully"}% hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST http://localhost:4000/channels/mychannel/peers -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" -H "content-type: application/json" -d '{ "peers": ["peer0.org1.example.com","peer1.org1.example.com"] }' {"success":true,"message":"Successfully joined peers in organization Org1 to the channel:mychannel"} Create channel을 위해서 오더러에 해당하는 7050 포트 설정 필요 Join channel을 위해서 피어에 해당하는 7051와 7056 포트 설정 필요 [참고] fabric server <-> node.js(SDK) local
  • 56. hwang-won-yong@hwang-won-yong-ui-MacBookPro balance-transfer % curl -s -X POST http://localhost:4000/channels/mychannel/anchorpeers -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4v cQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" -H "content-type: application/json" -d '{ "configUpdatePath":"../artifacts/channel/Org1MSPanchors.tx" }' {"success":true,"message":"Successfully update anchor peers in organization Org1 to the channel 'mychannel'"}% [참고] fabric server <-> node.js(SDK) local Anchor Peer Update hwang-won-yong@hwang-won-yong-ui-MacBookPro node % curl -s -X POST http://localhost:4000/chaincodes -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1ODQyMjc3OTIsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Ik9yZzEiLCJpYXQiOjE1ODQxOTE3OTJ9.dnZ7eBzsC4vcQtIiHSHtuLFY2U-E4FH2zcUJ2sftKP0" -H "content-type: application/json" -d "{ "peers": ["peer0.org1.example.com","peer1.org1.example.com"], "chaincodeName":"mycc", "chaincodePath":"/github.com/example_cc/node", "chaincodeType": "golang", "chaincodeVersion":"v0" }" {"success":true,"message":"Successfully installed chaincode"}% Install Chaincode —> 나머지 REST Call도 필요시 포트 설정해가면서 테스트 및 디버깅 진행~
  • 60. git clone -b release-1.4 https://github.com/wonyongHwang/fabric.git FAILED
  • 61. v2.0 부터 devenv 디렉토리 없음 vagrant 디렉토리에서 수행해야 함 FAILED
  • 62. v1.4 v2.0에서는 deprecated make 로 바로 빌드 수행 vagrant@vagrant:~/go/src/github.com/hyperledger/fabric$ cd build/bin vagrant@vagrant:~/go/src/github.com/hyperledger/fabric/build/bin$ ll total 160944 drwxrwxrwx 1 vagrant vagrant 4096 Feb 11 12:44 ./ drwxrwxrwx 1 vagrant vagrant 0 Feb 11 12:53 ../ -rwxrwxrwx 1 vagrant vagrant 20399368 Feb 11 12:44 configtxgen* -rwxrwxrwx 1 vagrant vagrant 17444176 Feb 11 12:44 configtxlator* -rwxrwxrwx 1 vagrant vagrant 13358893 Feb 11 12:44 cryptogen* -rwxrwxrwx 1 vagrant vagrant 19139370 Feb 11 12:44 discover* -rwxrwxrwx 1 vagrant vagrant 12375285 Feb 11 12:44 idemixgen* -rwxrwxrwx 1 vagrant vagrant 32163704 Feb 11 12:44 orderer* -rwxrwxrwx 1 vagrant vagrant 49909440 Feb 11 12:33 peer* vagrant@vagrant:~/go/src/github.com/hyperledger/fabric/build/bin$ ./peer FAILED
  • 63. sudo mkdir -p /var/hyperledger/production sudo chown -R $(whoami):$(whoami) /var/hyperledger FAILED
  • 66. visual studio code 설정 편집 및 
 샘플 프로젝트 생성 ! create project ! go ! browse chaincode.go 의 init, invoke 함수 확인 FAILED
  • 67. 패키지명, 버전명 : 1 fabric 기동 FAILED