fabric hyledger 开发模式

fabric hyledger 开发模式 http://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html

准备:

//下载go 相关库

go get -u --tags nopkcs11 github.com/hyperledger/fabric/core/chaincode/shim
go build --tags nopkcs11

//下载sample

git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples

//下载 Platform-specific Binaries

curl -sSL https://goo.gl/iX9dek | bash (被墙)

脚本内容

#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

export VERSION=1.0.0
export ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
#Set MARCH variable i.e ppc64le,s390x,x86_64,i386
MARCH=`uname -m`

dockerFabricPull() {
  local FABRIC_TAG=$1
  for IMAGES in peer orderer couchdb ccenv javaenv kafka zookeeper tools; do
      echo "==> FABRIC IMAGE: $IMAGES"
      echo
      docker pull hyperledger/fabric-$IMAGES:$FABRIC_TAG
      docker tag hyperledger/fabric-$IMAGES:$FABRIC_TAG hyperledger/fabric-$IMAGES
  done
}

dockerCaPull() {
      local CA_TAG=$1
      echo "==> FABRIC CA IMAGE"
      echo
      docker pull hyperledger/fabric-ca:$CA_TAG
      docker tag hyperledger/fabric-ca:$CA_TAG hyperledger/fabric-ca
}

: ${CA_TAG:="$MARCH-$VERSION"}
: ${FABRIC_TAG:="$MARCH-$VERSION"}

echo "===> Downloading platform binaries"
curl https://nexus.hyperledger.org/content/repositories/releases/org/hyperledger/fabric/hyperledger-fabric/${ARCH}-${VERSION}/hyperledger-fabric-${ARCH}-${VERSION}.tar.gz | tar xz

echo "===> Pulling fabric Images"
dockerFabricPull ${FABRIC_TAG}

echo "===> Pulling fabric ca Image"
dockerCaPull ${CA_TAG}
echo
echo "===> List out hyperledger docker images"
docker images | grep hyperledger*

//开发时要启动 3个 terminal,并执行相应命令

1.Terminal: 启动 docker 运行环境

cd chaincode-docker-devmode
sudo docker-compose -f docker-compose-simple.yaml up

2.Terminal - Build & start the chaincode, 编译 和启动 合约

docker exec -it chaincode bash
cd sacc
go build  //编译
//启动,在调用合约时,这里必须一直保持 开启状态
CORE_PEER_ADDRESS=peer:7051 CORE_CHAINCODE_ID_NAME=mycc:0 ./sacc  

3.Terminal - Use the chaincode

docker exec -it cli bash

peer chaincode install -p chaincodedev/chaincode/sacc -n mycc -v 0
peer chaincode instantiate -n mycc -v 0 -c '{"Args":["a","100"]}' -C myc

//查询
peer chaincode query -n mycc -c '{"Args":["query","a"]}' -C myc

//执行
peer chaincode invoke -n mycc -c '{"Args":["set","a","333"]}' -C myc

你可能感兴趣的:(fabric hyledger 开发模式)