目录
创建网络
创建网络
查看network-starter.sh文件内容
查看Fabric节点
查看docker网络
以 MagnetoCorp 的身份安装和批准智能合约
设置环境变量
将智能合约打包成链码
安装链码(时间较长)
查看packageID
将packageID设置为一个环境变量
同意链码定义
以 DigiBank 的身份安装和批准智能合约
设置环境变量
将智能合约打包成链码
安装链码(时间较长)
查看packageID
将packageID保存为环境变量
同意链码定义
将链码定义提交到通道
查看链码容器
以MagnettoCorp身份运行发行商业票据(切换至magnetocorp终端)
安装应用程序依赖
将身份信息添加至钱包中
查看生成身份的位置
发行商业票据
以DigiBank身份运行购买、赎回商业票据(切换至digibank终端)
安装 应用程序依赖
将身份信息添加至钱包中
购买商业票据
赎回商业票据
关闭网络(清理环境)
创建网络
创建网络
[root@localhost ~]# cd /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper #进入商业票据示例目录
[root@localhost commercial-paper]# ./network-starter.sh #创建网络
-bash: ./network-starter.sh: Permission denied #没权限
[root@localhost commercial-paper]# chmod +x network-starter.sh #授权
[root@localhost commercial-paper]# ./network-starter.sh #再次创建网络
查看network-starter.sh文件内容
#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
function _exit(){
printf "Exiting:%sn" "$1"
exit -1
}
# Exit on first error, print all commands.
set -ev
set -o pipefail
# Where am I?
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export FABRIC_CFG_PATH="${DIR}/../config"
cd "${DIR}/../test-network/"
docker kill cliDigiBank cliMagnetoCorp logspout || true
./network.sh down
./network.sh up createChannel -ca -s couchdb
# Copy the connection profiles so they are in the correct organizations.
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "${DIR}/organization/digibank/gateway/"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "${DIR}/organization/magnetocorp/gateway/"
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/"* "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem"
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/"* "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/"* "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/"* "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/priv_sk"
echo Suggest that you monitor the docker containers by running
echo "./organization/magnetocorp/configuration/cli/monitordocker.sh fabric_test"
查看Fabric节点
[root@localhost commercial-paper]# docker ps
ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3addaffd339e hyperledger/fabric-tools:latest "/bin/bash" 47 seconds ago Up 46 seconds cli
6e8833987da0 hyperledger/fabric-peer:latest "peer node start" 48 seconds ago Up 47 seconds 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:19051->19051/tcp, :::19051->19051/tcp peer0.org2.example.com
75e5b674b6fd hyperledger/fabric-peer:latest "peer node start" 48 seconds ago Up 47 seconds 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:17051->17051/tcp, :::17051->17051/tcp peer0.org1.example.com
62b5223ab179 couchdb:3.1.1 "tini -- /docker-ent…" 49 seconds ago Up 48 seconds 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp, :::7984->5984/tcp couchdb1
6f9c7675ca57 couchdb:3.1.1 "tini -- /docker-ent…" 49 seconds ago Up 48 seconds 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp couchdb0
4f0d317822f4 hyperledger/fabric-orderer:latest "orderer" 49 seconds ago Up 48 seconds 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:17050->17050/tcp, :::17050->17050/tcp orderer.example.com
283048518f2f hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 52 seconds 0.0.0.0:8054->8054/tcp, :::8054->8054/tcp, 7054/tcp, 0.0.0.0:18054->18054/tcp, :::18054->18054/tcp ca_org2
5f7d10f52f01 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 52 seconds 0.0.0.0:9054->9054/tcp, :::9054->9054/tcp, 7054/tcp, 0.0.0.0:19054->19054/tcp, :::19054->19054/tcp ca_orderer
368f87b53f5d hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 53 seconds 0.0.0.0:7054->7054/tcp, :::7054->7054/tcp, 0.0.0.0:17054->17054/tcp, :::17054->17054/tcp ca_org1
查看docker网络
[root@localhost commercial-paper]# docker network inspect fabric_test
[
{
"Name": "fabric_test",
"Id": "228737590b752f95ee62ac611297f499b78de7ef21e65b74031c796e94156935",
"Created": "2021-11-04T16:05:59.781298969+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"283048518f2f96fc6a5f651503d40a482abb829502254fc1003d4018040c1f9c": {
"Name": "ca_org2",
"EndpointID": "c1f8e8d645148e4d294617179e94127017088663720ae15fd60e7082ca076520",
"MacAddress": "02:42:ac:16:00:04",
"IPv4Address": "172.22.0.4/16",
"IPv6Address": ""
},
"368f87b53f5d656dfb34c44cbf2f29a21d7211d1034bfcc7d6b747699fcaf6c1": {
"Name": "ca_org1",
"EndpointID": "671aa068533e608a50ae766d9c417905d73f103da9ec6872cb2c8c17f21e8952",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
},
"3addaffd339e7a06d2bdb58ab122eca4acd3ebc25c8eb65451e64340bbe140cf": {
"Name": "cli",
"EndpointID": "c3124ad0dd1e106f0ed56290db31736e9b79c8689c75690f4ad8f59b2df6035c",
"MacAddress": "02:42:ac:16:00:0a",
"IPv4Address": "172.22.0.10/16",
"IPv6Address": ""
},
"4f0d317822f46d1ef6804747813e3568e5401b23f5b9c3152627a8332f1338ee": {
"Name": "orderer.example.com",
"EndpointID": "9df310943d4439ec931cb54d8be5ad12de2890992d773f9a6fa840d9cd3ebcc9",
"MacAddress": "02:42:ac:16:00:06",
"IPv4Address": "172.22.0.6/16",
"IPv6Address": ""
},
"5f7d10f52f01bb994dc3da0c1bc35e31ffa8bf45314da2154eb4fb3ed30fe6ce": {
"Name": "ca_orderer",
"EndpointID": "88178b8a694a2ac7fca7517547631b108d241ae0cf294144be7d686318e41d43",
"MacAddress": "02:42:ac:16:00:03",
"IPv4Address": "172.22.0.3/16",
"IPv6Address": ""
},
"62b5223ab17972801eca0c7830be5296e4756e3e6ea6d3b60a032595f63b1a33": {
"Name": "couchdb1",
"EndpointID": "425068c1768dd87aedc6daf5090c64d9e9bac1e299afb54173ef92cdfcc3ab7c",
"MacAddress": "02:42:ac:16:00:07",
"IPv4Address": "172.22.0.7/16",
"IPv6Address": ""
},
"6e8833987da0f92cb9de473abe8812c8d06ddae3f3faef2309b7783ea5f5f329": {
"Name": "peer0.org2.example.com",
"EndpointID": "7aa6c57c6fae04422a8ad4e396643c421874704ca4b0a960aa97213b9e868689",
"MacAddress": "02:42:ac:16:00:09",
"IPv4Address": "172.22.0.9/16",
"IPv6Address": ""
},
"6f9c7675ca57aed7862b0e6c2915b02c9c556aaffefa1850a5d93c1a8996a5f6": {
"Name": "couchdb0",
"EndpointID": "4acbe9da3f9b9658d37fea620d9a7de9c7bc0af00c8cb6b2936ed7c91ee6aac4",
"MacAddress": "02:42:ac:16:00:05",
"IPv4Address": "172.22.0.5/16",
"IPv6Address": ""
},
"75e5b674b6fd49c865bee13494ea01fe0ff0f7fe4ec826da6eb41e29e26d4978": {
"Name": "peer0.org1.example.com",
"EndpointID": "10aa99cddb90ebae38b96699fa280236948f160e61c0f1ba8264bf501b3aa05d",
"MacAddress": "02:42:ac:16:00:08",
"IPv4Address": "172.22.0.8/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "fabric_test",
"com.docker.compose.project": "docker",
"com.docker.compose.version": "1.29.2"
}
}
]
以 MagnetoCorp 的身份安装和批准智能合约
设置环境变量
[root@localhost commercial-paper]# cd organization/magnetocorp/ #进入目录
[root@localhost magnetocorp]# source magnetocorp.sh #设置环境变量
Using organization 2
Using organization 2
}
}
}
}
export BASH_FUNC_errorln()="() { println "${C_RED}${1}${C_RESET}""
export BASH_FUNC_infoln()="() { println "${C_BLUE}${1}${C_RESET}""
export BASH_FUNC_successln()="() { println "${C_GREEN}${1}${C_RESET}""
export BASH_FUNC_warnln()="() { println "${C_YELLOW}${1}${C_RESET}""
export CORE_PEER_ADDRESS="localhost:9051"
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_MSPConFIGPATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp"
export CORE_PEER_TLS_ENABLED="true"
export CORE_PEER_TLS_ROOTCERT_FILE="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export FABRIC_CFG_PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../config"
export ORDERER_ADMIN_TLS_PRIVATE_KEY="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"
export ORDERER_ADMIN_TLS_SIGN_CERT="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt"
export ORDERER_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
export PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../bin:/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/go/bin:/home/gopath/bin:/root/bin"
export PEER0_ORG1_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
export PEER0_ORG2_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export PEER0_ORG3_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt"
rm: remove regular file ‘/tmp/tmp.92iNHZWxed’? y
将智能合约打包成链码
[root@localhost magnetocorp]# peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0
function _exit(){
printf "Exiting:%sn" "$1"
exit -1
}
# Exit on first error, print all commands.
set -ev
set -o pipefail
# Where am I?
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export FABRIC_CFG_PATH="${DIR}/../config"
cd "${DIR}/../test-network/"
docker kill cliDigiBank cliMagnetoCorp logspout || true
./network.sh down
./network.sh up createChannel -ca -s couchdb
# Copy the connection profiles so they are in the correct organizations.
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml" "${DIR}/organization/digibank/gateway/"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/connection-org2.yaml" "${DIR}/organization/magnetocorp/gateway/"
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/"* "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem"
cp "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/"* "${DIR}/../test-network/organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/"* "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/signcerts/User1@org2.example.com-cert.pem"
cp "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/"* "${DIR}/../test-network/organizations/peerOrganizations/org2.example.com/users/User1@org2.example.com/msp/keystore/priv_sk"
echo Suggest that you monitor the docker containers by running
echo "./organization/magnetocorp/configuration/cli/monitordocker.sh fabric_test"
查看Fabric节点
[root@localhost commercial-paper]# docker ps
ConTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3addaffd339e hyperledger/fabric-tools:latest "/bin/bash" 47 seconds ago Up 46 seconds cli
6e8833987da0 hyperledger/fabric-peer:latest "peer node start" 48 seconds ago Up 47 seconds 0.0.0.0:9051->9051/tcp, :::9051->9051/tcp, 7051/tcp, 0.0.0.0:19051->19051/tcp, :::19051->19051/tcp peer0.org2.example.com
75e5b674b6fd hyperledger/fabric-peer:latest "peer node start" 48 seconds ago Up 47 seconds 0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:17051->17051/tcp, :::17051->17051/tcp peer0.org1.example.com
62b5223ab179 couchdb:3.1.1 "tini -- /docker-ent…" 49 seconds ago Up 48 seconds 4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp, :::7984->5984/tcp couchdb1
6f9c7675ca57 couchdb:3.1.1 "tini -- /docker-ent…" 49 seconds ago Up 48 seconds 4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp couchdb0
4f0d317822f4 hyperledger/fabric-orderer:latest "orderer" 49 seconds ago Up 48 seconds 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp, 0.0.0.0:7053->7053/tcp, :::7053->7053/tcp, 0.0.0.0:17050->17050/tcp, :::17050->17050/tcp orderer.example.com
283048518f2f hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 52 seconds 0.0.0.0:8054->8054/tcp, :::8054->8054/tcp, 7054/tcp, 0.0.0.0:18054->18054/tcp, :::18054->18054/tcp ca_org2
5f7d10f52f01 hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 52 seconds 0.0.0.0:9054->9054/tcp, :::9054->9054/tcp, 7054/tcp, 0.0.0.0:19054->19054/tcp, :::19054->19054/tcp ca_orderer
368f87b53f5d hyperledger/fabric-ca:latest "sh -c 'fabric-ca-se…" 53 seconds ago Up 53 seconds 0.0.0.0:7054->7054/tcp, :::7054->7054/tcp, 0.0.0.0:17054->17054/tcp, :::17054->17054/tcp ca_org1
查看docker网络
[root@localhost commercial-paper]# docker network inspect fabric_test
[
{
"Name": "fabric_test",
"Id": "228737590b752f95ee62ac611297f499b78de7ef21e65b74031c796e94156935",
"Created": "2021-11-04T16:05:59.781298969+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"283048518f2f96fc6a5f651503d40a482abb829502254fc1003d4018040c1f9c": {
"Name": "ca_org2",
"EndpointID": "c1f8e8d645148e4d294617179e94127017088663720ae15fd60e7082ca076520",
"MacAddress": "02:42:ac:16:00:04",
"IPv4Address": "172.22.0.4/16",
"IPv6Address": ""
},
"368f87b53f5d656dfb34c44cbf2f29a21d7211d1034bfcc7d6b747699fcaf6c1": {
"Name": "ca_org1",
"EndpointID": "671aa068533e608a50ae766d9c417905d73f103da9ec6872cb2c8c17f21e8952",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
},
"3addaffd339e7a06d2bdb58ab122eca4acd3ebc25c8eb65451e64340bbe140cf": {
"Name": "cli",
"EndpointID": "c3124ad0dd1e106f0ed56290db31736e9b79c8689c75690f4ad8f59b2df6035c",
"MacAddress": "02:42:ac:16:00:0a",
"IPv4Address": "172.22.0.10/16",
"IPv6Address": ""
},
"4f0d317822f46d1ef6804747813e3568e5401b23f5b9c3152627a8332f1338ee": {
"Name": "orderer.example.com",
"EndpointID": "9df310943d4439ec931cb54d8be5ad12de2890992d773f9a6fa840d9cd3ebcc9",
"MacAddress": "02:42:ac:16:00:06",
"IPv4Address": "172.22.0.6/16",
"IPv6Address": ""
},
"5f7d10f52f01bb994dc3da0c1bc35e31ffa8bf45314da2154eb4fb3ed30fe6ce": {
"Name": "ca_orderer",
"EndpointID": "88178b8a694a2ac7fca7517547631b108d241ae0cf294144be7d686318e41d43",
"MacAddress": "02:42:ac:16:00:03",
"IPv4Address": "172.22.0.3/16",
"IPv6Address": ""
},
"62b5223ab17972801eca0c7830be5296e4756e3e6ea6d3b60a032595f63b1a33": {
"Name": "couchdb1",
"EndpointID": "425068c1768dd87aedc6daf5090c64d9e9bac1e299afb54173ef92cdfcc3ab7c",
"MacAddress": "02:42:ac:16:00:07",
"IPv4Address": "172.22.0.7/16",
"IPv6Address": ""
},
"6e8833987da0f92cb9de473abe8812c8d06ddae3f3faef2309b7783ea5f5f329": {
"Name": "peer0.org2.example.com",
"EndpointID": "7aa6c57c6fae04422a8ad4e396643c421874704ca4b0a960aa97213b9e868689",
"MacAddress": "02:42:ac:16:00:09",
"IPv4Address": "172.22.0.9/16",
"IPv6Address": ""
},
"6f9c7675ca57aed7862b0e6c2915b02c9c556aaffefa1850a5d93c1a8996a5f6": {
"Name": "couchdb0",
"EndpointID": "4acbe9da3f9b9658d37fea620d9a7de9c7bc0af00c8cb6b2936ed7c91ee6aac4",
"MacAddress": "02:42:ac:16:00:05",
"IPv4Address": "172.22.0.5/16",
"IPv6Address": ""
},
"75e5b674b6fd49c865bee13494ea01fe0ff0f7fe4ec826da6eb41e29e26d4978": {
"Name": "peer0.org1.example.com",
"EndpointID": "10aa99cddb90ebae38b96699fa280236948f160e61c0f1ba8264bf501b3aa05d",
"MacAddress": "02:42:ac:16:00:08",
"IPv4Address": "172.22.0.8/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "fabric_test",
"com.docker.compose.project": "docker",
"com.docker.compose.version": "1.29.2"
}
}
]
以 MagnetoCorp 的身份安装和批准智能合约
设置环境变量
[root@localhost commercial-paper]# cd organization/magnetocorp/ #进入目录
[root@localhost magnetocorp]# source magnetocorp.sh #设置环境变量
Using organization 2
Using organization 2
}
}
}
}
export BASH_FUNC_errorln()="() { println "${C_RED}${1}${C_RESET}""
export BASH_FUNC_infoln()="() { println "${C_BLUE}${1}${C_RESET}""
export BASH_FUNC_successln()="() { println "${C_GREEN}${1}${C_RESET}""
export BASH_FUNC_warnln()="() { println "${C_YELLOW}${1}${C_RESET}""
export CORE_PEER_ADDRESS="localhost:9051"
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_MSPConFIGPATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp"
export CORE_PEER_TLS_ENABLED="true"
export CORE_PEER_TLS_ROOTCERT_FILE="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export FABRIC_CFG_PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../config"
export ORDERER_ADMIN_TLS_PRIVATE_KEY="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"
export ORDERER_ADMIN_TLS_SIGN_CERT="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt"
export ORDERER_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
export PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../bin:/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/go/bin:/home/gopath/bin:/root/bin"
export PEER0_ORG1_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
export PEER0_ORG2_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export PEER0_ORG3_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt"
rm: remove regular file ‘/tmp/tmp.92iNHZWxed’? y
将智能合约打包成链码
[root@localhost magnetocorp]# peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
[root@localhost commercial-paper]# docker network inspect fabric_test
[
{
"Name": "fabric_test",
"Id": "228737590b752f95ee62ac611297f499b78de7ef21e65b74031c796e94156935",
"Created": "2021-11-04T16:05:59.781298969+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": true,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"283048518f2f96fc6a5f651503d40a482abb829502254fc1003d4018040c1f9c": {
"Name": "ca_org2",
"EndpointID": "c1f8e8d645148e4d294617179e94127017088663720ae15fd60e7082ca076520",
"MacAddress": "02:42:ac:16:00:04",
"IPv4Address": "172.22.0.4/16",
"IPv6Address": ""
},
"368f87b53f5d656dfb34c44cbf2f29a21d7211d1034bfcc7d6b747699fcaf6c1": {
"Name": "ca_org1",
"EndpointID": "671aa068533e608a50ae766d9c417905d73f103da9ec6872cb2c8c17f21e8952",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
},
"3addaffd339e7a06d2bdb58ab122eca4acd3ebc25c8eb65451e64340bbe140cf": {
"Name": "cli",
"EndpointID": "c3124ad0dd1e106f0ed56290db31736e9b79c8689c75690f4ad8f59b2df6035c",
"MacAddress": "02:42:ac:16:00:0a",
"IPv4Address": "172.22.0.10/16",
"IPv6Address": ""
},
"4f0d317822f46d1ef6804747813e3568e5401b23f5b9c3152627a8332f1338ee": {
"Name": "orderer.example.com",
"EndpointID": "9df310943d4439ec931cb54d8be5ad12de2890992d773f9a6fa840d9cd3ebcc9",
"MacAddress": "02:42:ac:16:00:06",
"IPv4Address": "172.22.0.6/16",
"IPv6Address": ""
},
"5f7d10f52f01bb994dc3da0c1bc35e31ffa8bf45314da2154eb4fb3ed30fe6ce": {
"Name": "ca_orderer",
"EndpointID": "88178b8a694a2ac7fca7517547631b108d241ae0cf294144be7d686318e41d43",
"MacAddress": "02:42:ac:16:00:03",
"IPv4Address": "172.22.0.3/16",
"IPv6Address": ""
},
"62b5223ab17972801eca0c7830be5296e4756e3e6ea6d3b60a032595f63b1a33": {
"Name": "couchdb1",
"EndpointID": "425068c1768dd87aedc6daf5090c64d9e9bac1e299afb54173ef92cdfcc3ab7c",
"MacAddress": "02:42:ac:16:00:07",
"IPv4Address": "172.22.0.7/16",
"IPv6Address": ""
},
"6e8833987da0f92cb9de473abe8812c8d06ddae3f3faef2309b7783ea5f5f329": {
"Name": "peer0.org2.example.com",
"EndpointID": "7aa6c57c6fae04422a8ad4e396643c421874704ca4b0a960aa97213b9e868689",
"MacAddress": "02:42:ac:16:00:09",
"IPv4Address": "172.22.0.9/16",
"IPv6Address": ""
},
"6f9c7675ca57aed7862b0e6c2915b02c9c556aaffefa1850a5d93c1a8996a5f6": {
"Name": "couchdb0",
"EndpointID": "4acbe9da3f9b9658d37fea620d9a7de9c7bc0af00c8cb6b2936ed7c91ee6aac4",
"MacAddress": "02:42:ac:16:00:05",
"IPv4Address": "172.22.0.5/16",
"IPv6Address": ""
},
"75e5b674b6fd49c865bee13494ea01fe0ff0f7fe4ec826da6eb41e29e26d4978": {
"Name": "peer0.org1.example.com",
"EndpointID": "10aa99cddb90ebae38b96699fa280236948f160e61c0f1ba8264bf501b3aa05d",
"MacAddress": "02:42:ac:16:00:08",
"IPv4Address": "172.22.0.8/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "fabric_test",
"com.docker.compose.project": "docker",
"com.docker.compose.version": "1.29.2"
}
}
]
以 MagnetoCorp 的身份安装和批准智能合约
设置环境变量
[root@localhost commercial-paper]# cd organization/magnetocorp/ #进入目录
[root@localhost magnetocorp]# source magnetocorp.sh #设置环境变量
Using organization 2
Using organization 2
}
}
}
}
export BASH_FUNC_errorln()="() { println "${C_RED}${1}${C_RESET}""
export BASH_FUNC_infoln()="() { println "${C_BLUE}${1}${C_RESET}""
export BASH_FUNC_successln()="() { println "${C_GREEN}${1}${C_RESET}""
export BASH_FUNC_warnln()="() { println "${C_YELLOW}${1}${C_RESET}""
export CORE_PEER_ADDRESS="localhost:9051"
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_MSPConFIGPATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp"
export CORE_PEER_TLS_ENABLED="true"
export CORE_PEER_TLS_ROOTCERT_FILE="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export FABRIC_CFG_PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../config"
export ORDERER_ADMIN_TLS_PRIVATE_KEY="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"
export ORDERER_ADMIN_TLS_SIGN_CERT="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt"
export ORDERER_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
export PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../bin:/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/go/bin:/home/gopath/bin:/root/bin"
export PEER0_ORG1_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
export PEER0_ORG2_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export PEER0_ORG3_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt"
rm: remove regular file ‘/tmp/tmp.92iNHZWxed’? y
将智能合约打包成链码
[root@localhost magnetocorp]# peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
[root@localhost commercial-paper]# cd organization/magnetocorp/ #进入目录
[root@localhost magnetocorp]# source magnetocorp.sh #设置环境变量
Using organization 2
Using organization 2
}
}
}
}
export BASH_FUNC_errorln()="() { println "${C_RED}${1}${C_RESET}""
export BASH_FUNC_infoln()="() { println "${C_BLUE}${1}${C_RESET}""
export BASH_FUNC_successln()="() { println "${C_GREEN}${1}${C_RESET}""
export BASH_FUNC_warnln()="() { println "${C_YELLOW}${1}${C_RESET}""
export CORE_PEER_ADDRESS="localhost:9051"
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_MSPConFIGPATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp"
export CORE_PEER_TLS_ENABLED="true"
export CORE_PEER_TLS_ROOTCERT_FILE="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export FABRIC_CFG_PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../config"
export ORDERER_ADMIN_TLS_PRIVATE_KEY="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"
export ORDERER_ADMIN_TLS_SIGN_CERT="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt"
export ORDERER_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
export PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/../../../bin:/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/go/bin:/home/gopath/bin:/root/bin"
export PEER0_ORG1_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
export PEER0_ORG2_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
export PEER0_ORG3_CA="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt"
rm: remove regular file ‘/tmp/tmp.92iNHZWxed’? y
将智能合约打包成链码
[root@localhost magnetocorp]# peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0
打包成功后,在目录中出现cp.tar.gz文件
安装链码(时间较长)
[root@localhost magnetocorp]# peer lifecycle chaincode install cp.tar.gz
Error: chaincode install failed with status: 500 - error in simulation: failed to execute transaction 0cd37fe0b8e10c31bc1c2828d99e2479c803bc29860b56c756b388c86791f8a9: error sending: timeout expired while executing transaction
如遇到以上问题,则清除网络,重新部署即可(使用科学上网),安装成功后显示结果
[root@localhost magnetocorp]# peer lifecycle chaincode install cp.tar.gz 2021-11-05 09:13:47.644 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:


