华为云区块链的跨云联通能力构建(一)(2)

  docker cp core.yaml ${peerCID}:/home

  docker cp silk-road-chain.genesis.block ${peerCID}:/home

  docker cp ordererOrganizations/icn.backbonetestnet.baas.dev.icn.engineering/tlsca/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem ${peerCID}:/home

  docker cp peerOrganizations/org1.huawei.backbonetestnet.baas.dev.icn.engineering/users/Admin@org1.huawei.backbonetestnet.baas.dev.icn.engineering/msp ${peerCID}:/home

  docker cp peerOrganizations/org1.huawei.backbonetestnet.baas.dev.icn.engineering/peers/peer0.org1.huawei.backbonetestnet.baas.dev.icn.engineering/tls ${peerCID}:/home/msp

  •在容器中配置/etc/hosts

  echo "35.158.219.246 orderer0.icn.backbonetestnet.baas.dev.icn.engineering" >> /etc/hosts

  echo "49.4.14.175 peer0.org1.huawei.backbonetestnet.baas.dev.icn.engineering" >> /etc/hosts

  •容器中启动peer命令

  export FABRIC_CFG_PATH=/home

  peer node start

  •启动cli容器

  docker run -it -v /var/run:/host/var/run -e CORE_VM_ENDPOINT="unix:///host/var/run/docker.sock" docker.io/hyperledger/fabric-tools:1.2.0 bash

  echo "35.158.219.246 orderer0.icn.backbonetestnet.baas.dev.icn.engineering" >> /etc/hosts

  echo "49.4.14.175 peer0.org1.huawei.backbonetestnet.baas.dev.icn.engineering" >> /etc/hosts

  CORE_PEER_ADDRESS=peer0.org1.huawei.backbonetestnet.baas.dev.icn.engineering:7051

  export FABRIC_CFG_PATH=/home

  •加入通道 从A云侧部署的Fabric上取到通道的genesis block配置文件(silk-road-chain.genesis.block) 进入cli容器中执行

  peer channel join -b /home/silk-road-chain.genesis.block --orderer orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem --tls true

  •加入成功截图

  •查看已加入通道

  peer channel list --orderer orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem --tls

  •其他 获取通道配置

  peer channel fetch config silk-road.pb --orderer orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 -c silk-road-chain --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem --tls

  3、加入通道中遇到的坑

  •问题

  Error: error getting chaincode code sacc: : failed with error: "exec: not started"

  不能再用peer做cli,需要用fabric-tools

  •问题

  peer channel join -b /home/silk-road-chain.protobuf --orderer orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem --tls true

  2018-08-07 12:11:54.717 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized

  Error: proposal failed (err: bad proposal response 500)

  2018-08-07 12:11:54.723 UTC [ledgermgmt] CreateLedger -> INFO 02c Creating ledger [silk-road-chain] with genesis block

  2018-08-07 12:11:54.728 UTC [endorser] ProcessProposal -> ERRO 02d [][9d432b23] simulateProposal() resulted in chaincode name:"cscc" response status 500 for txid: 9d432b23f3ad660af90e38bb6a4f6079dd60da9132f130b926556fdc29b3b79a

  channel join时报此错,后发现-b参数应该用genesis.block而不是protobuf

  4、加入通道后,实例化链码并进行invoke操作

  •安装链码 进入cli容器中创建链码根目录

  docker exec -it xx bash

  cd $GOPATH/src

  mkdir -p fabbank

  将链码文件拷贝到容器中创建好的链码根目录下

  docker cp fabbankid.go xxx:/opt/gopath/src/fabbank

  放置好链码的目录如下 /opt/gopath/src/fabbank/fabbankio.go

  容器中执行链码安装

  peer chaincode install -n fabbank -v 1.0 -l golang -p fabbank

  •链码实例化

  peer chaincode instantiate -o orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --tls true --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem -C silk-road-chain -n fabbank -v 1.0 -c '{"Args":["init","a","200","b","300"]}' -P "OR ('huaweiMSP.member')

  •链码invoke

  peer chaincode invoke -o orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --tls true --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem -C silk-road-chain -n fabbank -c '{"Args":["creditAccountInfo","bohai","zhangsan","211004197001010000","6225777788889999","15600000000"]}'

  peer chaincode invoke -o orderer0.icn.backbonetestnet.baas.dev.icn.engineering:7050 --tls true --cafile /home/tlsca.icn.backbonetestnet.baas.dev.icn.engineering-cert.pem -C silk-road-chain -n fabbank -c '{"Args":["authAccount","bohai","211004197001010000"]}'

  •链码query

  peer chaincode query -C silk-road-chain -n fabbank -c '{"Args":["authAccount","bohai","234567"]}'

  •查询已安装的链码

标签:区块链 华为云 跨云联通
N本文来源:财经365自媒体综合