11. Fablic Sambles - First Network 에서 체인코드 실습
페이지 정보
작성자 관리자 댓글 2건 조회 5,935회 작성일 19-11-27 16:19본문
11. Fablic Sambles - First Network 에서 체인코드 실습
체인코드 작성하기
root@client:~# cd ~/hyperledger/fabric-samples/chaincode
root@client:~/hyperledger/fabric-samples/chaincode# mkdir -p PS/go
root@client:~/hyperledger/fabric-samples/chaincode# cd PS/go
root@client:~/hyperledger/fabric-samples/chaincode/PS/go# vi PS.go
개발모드에서 실습한 PS.go를 복사한다.
root@client:~/hyperledger/fabric-samples/chaincode/PS/go# cp /root/gopath/src/PS/PS* ./
root@client:~/hyperledger/fabric-samples/chaincode/PS/go# ls
PS PS.go
구동 스크립트 다운받기
root@client:~# cd hyperledger/fabric-samples/first-network/
root@client:~/hyperledger/fabric-samples/first-network# wget https://www.leelab.co.kr/down/fabric-samples/byfn2.sh -O byfn2.sh
--2019-11-27 16:14:54-- https://www.leelab.co.kr/down/fabric-samples/byfn2.sh
Resolving www.leelab.co.kr (www.leelab.co.kr)... 202.31.147.218
접속 www.leelab.co.kr (www.leelab.co.kr)|202.31.147.218|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 23796 (23K) [application/x-sh]
Saving to: ‘byfn2.sh’
byfn2.sh 100%[===================================================>] 23.24K --.-KB/s in 0s
2019-11-27 16:14:54 (113 MB/s) - ‘byfn2.sh’ saved [23796/23796]
root@client:~/hyperledger/fabric-samples/first-network# chmod 755 byfn2.sh
스크립트 다운
root@client:~/hyperledger/fabric-samples/first-network#
root@client:~/hyperledger/fabric-samples/first-network/# ls scripts/
capabilities.json step1org3.sh step3org3.sh upgrade_to_v14.sh
script.sh step2org3.sh testorg3.sh utils.sh
root@client:~/hyperledger/fabric-samples/first-network# wget https://www.leelab.co.kr/down/fabric-samples/script2.sh -O scripts/script2.sh
--2019-11-27 16:53:27-- https://www.leelab.co.kr/down/fabric-samples/script2.sh
Resolving www.leelab.co.kr (www.leelab.co.kr)... 202.31.147.218
접속 www.leelab.co.kr (www.leelab.co.kr)|202.31.147.218|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 3229 (3.2K) [application/x-sh]
Saving to: ‘script2.sh’
script2.sh 100%[========================>] 3.15K --.-KB/s in 0s
2019-11-27 16:53:27 (32.6 MB/s) - ‘scripts/script2.sh’ saved [3229/3229]
root@client:~/hyperledger/fabric-samples/first-network# wget https://www.leelab.co.kr/down/fabric-samples/utils2.sh -O scripts/utils2.sh
--2019-11-27 19:16:39-- https://www.leelab.co.kr/down/fabric-samples/utils2.sh
Resolving www.leelab.co.kr (www.leelab.co.kr)... 202.31.147.218
접속 www.leelab.co.kr (www.leelab.co.kr)|202.31.147.218|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 11653 (11K) [application/x-sh]
Saving to: ‘scripts/utils2.sh’
scripts/utils2.sh 100%[========================>] 11.38K --.-KB/s in 0s
2019-11-27 19:16:39 (49.8 MB/s) - ‘scripts/utils2.sh’ saved [11653/11653]
root@client:~/hyperledger/fabric-samples/first-network# ls scripts
capabilities.json script2.sh step2org3.sh testorg3.sh utils.sh
script.sh step1org3.sh step3org3.sh upgrade_to_v14.sh utils2.sh
root@client:~/hyperledger/fabric-samples/first-network# chmod 755 scripts/utils2.sh scripts/script2.sh
root@client:~/hyperledger/fabric-samples/first-network# wget https://www.leelab.co.kr/down/fabric-samples/script_query.sh -O scripts/script_query.sh
--2019-11-27 19:53:01-- https://www.leelab.co.kr/down/fabric-samples/script_query.sh
Resolving www.leelab.co.kr (www.leelab.co.kr)... 202.31.147.218
접속 www.leelab.co.kr (www.leelab.co.kr)|202.31.147.218|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 2227 (2.2K) [application/x-sh]
Saving to: ‘scripts/script_query.sh’
scripts/script_query. 100%[========================>] 2.17K --.-KB/s in 0s
2019-11-27 19:53:01 (22.9 MB/s) - ‘scripts/script_query.sh’ saved [2227/2227]
root@client:~/hyperledger/fabric-samples/first-network# chmod 755 scripts/script_query.sh
root@client:~/hyperledger/fabric-samples/first-network# wget https://www.leelab.co.kr/down/fabric-samples/script_invoke.sh -O scripts/script_invoke.sh
--2019-11-27 19:55:48-- https://www.leelab.co.kr/down/fabric-samples/script_invoke.sh
Resolving www.leelab.co.kr (www.leelab.co.kr)... 202.31.147.218
접속 www.leelab.co.kr (www.leelab.co.kr)|202.31.147.218|:443... 접속됨.
HTTP request sent, awaiting response... 200 OK
Length: 2261 (2.2K) [application/x-sh]
Saving to: ‘scripts/script_invoke.sh’
scripts/script_invoke 100%[========================>] 2.21K --.-KB/s in 0s
2019-11-27 19:55:48 (23.1 MB/s) - ‘scripts/script_invoke.sh’ saved [2261/2261]
root@client:~/hyperledger/fabric-samples/first-network# chmod 755 scripts/script_invoke.sh
root@client:~/hyperledger/fabric-samples/first-network#
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.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]
proceeding ...
/root/hyperledger/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
Generate CCP files for Org1 and Org2
/root/hyperledger/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
2019-11-27 16:58:20.103 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-11-27 16:58:20.536 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 002 orderer type: solo
2019-11-27 16:58:20.537 KST [common.tools.configtxgen.localconfig] Load -> INFO 003 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:20.957 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 004 orderer type: solo
2019-11-27 16:58:20.957 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 005 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:20.961 KST [common.tools.configtxgen] doOutputBlock -> INFO 006 Generating genesis block
2019-11-27 16:58:20.962 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
2019-11-27 16:58:21.051 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-11-27 16:58:21.471 KST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:21.900 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-11-27 16:58:21.900 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:21.900 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 005 Generating new channel configtx
2019-11-27 16:58:21.906 KST [common.tools.configtxgen] doOutputChannelCreateTx -> INFO 006 Writing new channel tx
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
2019-11-27 16:58:21.992 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-11-27 16:58:22.412 KST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:22.820 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-11-27 16:58:22.820 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:22.821 KST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-11-27 16:58:22.822 KST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x
#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
+ configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
2019-11-27 16:58:22.906 KST [common.tools.configtxgen] main -> INFO 001 Loading configuration
2019-11-27 16:58:23.337 KST [common.tools.configtxgen.localconfig] Load -> INFO 002 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:23.762 KST [common.tools.configtxgen.localconfig] completeInitialization -> INFO 003 orderer type: solo
2019-11-27 16:58:23.762 KST [common.tools.configtxgen.localconfig] LoadTopLevel -> INFO 004 Loaded configuration: /root/hyperledger/fabric-samples/first-network/configtx.yaml
2019-11-27 16:58:23.762 KST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 005 Generating anchor peer update
2019-11-27 16:58:23.763 KST [common.tools.configtxgen] doOutputAnchorPeersUpdate -> INFO 006 Writing anchor peer update
+ res=0
+ set +x
root@client:~/hyperledger/fabric-samples/first-network#
./byfn2.sh up 은 docker-compose를 구동한다.
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh up
./byfn2.sh init 은 체인코드를 install , instantiate를 실행한다.
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh init
./byfn2.sh invoke 은 체인코드의 invoke를 실행한다.
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh invoke
Running invoke Scripts for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n]
proceeding ...
Channel name : 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:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["user_insert","admin","LeeJinKwan","1234"]}'
+ res=0
+ set +x
2019-11-27 11:01:17.793 UTC [chaincodeCmd] chaincodeInvokeOrQuery -> INFO 001 Chaincode invoke successful. result: status:200
===================== Invoke transaction successful on peer0.org1 peer0.org2 on channel 'mychannel' =====================
./byfn2.sh query 은 체인코드의 query 를 실행한다.
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh query
Running query Scripts for channel 'mychannel' with CLI timeout of '10' seconds and CLI delay of '3' seconds
Continue? [Y/n]
proceeding ...
Channel name : mychannel
Querying chaincode on peer0.org1...
===================== Querying on peer0.org1 on channel 'mychannel'... =====================
+ peer chaincode query -C mychannel -n mycc -c '{"Args":["user_read","admin"]}'
Attempting to Query peer0.org1 ...3 secs
+ res=0
+ set +x
{"NM":"LeeJinKwan","PW":"1234","PN":"0","CC":"0","AP":"0"}
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh down
초기화 시킬때 인증서와 genesis.block 파일을 삭제시킨다.
root@leelab:~/hyperledger/fabric-samples/first-network# rm -fr crypto-config channel-artifacts/genesis.block
docker 이미지는 가급적 삭제 하지 않는다.
root@leelab:~/hyperledger/fabric-samples/first-network# docker images -q | xargs docker rmi -f
첨부파일
- PS.go (3.7K) 31회 다운로드 | DATE : 2019-11-27 16:37:41
댓글목록
관리자님의 댓글
관리자 작성일
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh down
root@client:~/hyperledger/fabric-samples/first-network# rm -fr crypto-config channel-artifacts/genesis.block
root@client:~/hyperledger/fabric-samples/first-network# vi scripts/utils2.sh
chaincodeInvoke() {
parsePeerConnectionParameters $@
res=$?
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
# while 'peer chaincode' command can get the orderer endpoint from the
# peer (if join was successful), let's supply it directly as we know
# it using the "-o" option
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
set -x
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c '{"Args":["user_insert","admin","LeeJinKwan","1234"]}' >&log.txt
res=$?
set +x
else
set -x
peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c '{"Args":["user_insert","admin","LeeJinKwan","1234"]}' >&log.txt
res=$?
set +x
fi
cat log.txt
#verifyResult $res "Invoke execution on $PEERS failed "
echo "===================== Invoke transaction successful on $PEERS on channel '$CHANNEL_NAME' ===================== "
echo
}
관리자님의 댓글
관리자 작성일
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh generate
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh up
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh init
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh invoke
root@client:~/hyperledger/fabric-samples/first-network# ./byfn2.sh query