目录

创建网络

创建网络

查看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.0function _exit(){printf "Exiting:%s\n" "$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

打包成功后,在目录中出现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:<status:200 payload:"\nEcp_0:df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce\022\004cp_0" >
2021-11-05 09:13:47.644 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: cp_0:df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce

查看packageID

[root@localhost magnetocorp]# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: cp_0:df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce, Label: cp_0

将packageID设置为一个环境变量

[root@localhost magnetocorp]# export PACKAGE_ID=cp_0:df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce

同意链码定义

[root@localhost magnetocorp]# peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
2021-11-05 10:07:10.419 CST [chaincodeCmd] ClientWait -> INFO 001 txid [30a5abcabcc4e3d501e7eca1352b611593ad4f012cf52656d1dba770211b91a0] committed with status (VALID) at localhost:9051

以 DigiBank 的身份安装和批准智能合约

打开一个新的终端,进入diaibank目录,

设置环境变量

[root@localhost organization]# cd digibank/
[root@localhost digibank]# source digibank.sh
Using organization 1
Using organization 1
}
}
}
}
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:7051"
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.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/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
export FABRIC_CFG_PATH="/home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/digibank/../../../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/digibank/../../../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.ohOpsakq8B’? n

将智能合约打包成链码

[root@localhost digibank]# peer lifecycle chaincode package cp.tar.gz --lang node --path ./contract --label cp_0

digibank目录中将出现cp.tar.gz文件

安装链码(时间较长)

[root@localhost digibank]# peer lifecycle chaincode install cp.tar.gz
2021-11-05 11:07:39.529 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 001 Installed remotely: response:<status:200 payload:"\nEcp_0:f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599\022\004cp_0" >
2021-11-05 11:07:39.529 CST [cli.lifecycle.chaincode] submitInstallProposal -> INFO 002 Chaincode code package identifier: cp_0:f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599

查看packageID

[root@localhost digibank]# peer lifecycle chaincode queryinstalled
Installed chaincodes on peer:
Package ID: cp_0:f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599, Label: cp_0

将packageID保存为环境变量

[root@localhost digibank]# export PACKAGE_ID=cp_0:f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599

同意链码定义

[root@localhost digibank]# peer lifecycle chaincode approveformyorg --orderer localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name papercontract -v 0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile $ORDERER_CA
2021-11-05 11:11:53.764 CST [chaincodeCmd] ClientWait -> INFO 001 txid [6f6cecf9fccbd03edba91f342a4aa8ef47e868f337ebc25fe89a973aa362f936] committed with status (VALID) at localhost:7051

将链码定义提交到通道

[root@localhost digibank]# peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --peerAddresses localhost:7051 --tlsRootCertFiles ${PEER0_ORG1_CA} --peerAddresses localhost:9051 --tlsRootCertFiles ${PEER0_ORG2_CA} --channelID mychannel --name papercontract -v 0 --sequence 1 --tls --cafile $ORDERER_CA --waitForEvent
2021-11-05 11:15:33.887 CST [chaincodeCmd] ClientWait -> INFO 001 txid [890d56c2e1ae810530302421d53594fb92282bb09f9ce2e06af1b37c152ca9e7] committed with status (VALID) at localhost:9051
2021-11-05 11:15:33.895 CST [chaincodeCmd] ClientWait -> INFO 002 txid [890d56c2e1ae810530302421d53594fb92282bb09f9ce2e06af1b37c152ca9e7] committed with status (VALID) at localhost:7051

查看链码容器

在链码定义提交到通道后,将创建新Docker链码容器且启动,可以通过docker ps查看链码容器:

[root@localhost digibank]# docker ps
CONTAINER ID   IMAGE                                                                                                                                                               COMMAND                  CREATED              STATUS              PORTS                                                                                                                                 NAMES
dda3e381c2fe   dev-peer0.org1.example.com-cp_0-f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599-7da41ed3eed9d0bd6abf71c5063f362152f6aaade865bfaf9da94d1602b35143   "docker-entrypoint.s…"   About a minute ago   Up About a minute                                                                                                                                         dev-peer0.org1.example.com-cp_0-f2316bf21cdc9aa6c3650c815228f88b3ae20cd2a74f30a1db76f02be2c4d599
5cce11d40160   dev-peer0.org2.example.com-cp_0-df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce-52d8f4346bbaab4fe92fb443d269f3cd64ecbbc390c5ca79c30dae96d5f2194e   "docker-entrypoint.s…"   About a minute ago   Up About a minute                                                                                                                                         dev-peer0.org2.example.com-cp_0-df23cfaa2d118a48df5002d95521e14df1070e44d7858da6d2da2d9df3f138ce
0945acd25401   gliderlabs/logspout                                                                                                                                                 "/bin/logspout"          2 hours ago          Up 2 hours          127.0.0.1:8000->80/tcp                                                                                                                logspout
084d8ac91972   hyperledger/fabric-tools:latest                                                                                                                                     "/bin/bash"              2 hours ago          Up 2 hours                                                                                                                                                cli
1d0ad0da1a01   hyperledger/fabric-peer:latest                                                                                                                                      "peer node start"        2 hours ago          Up 2 hours          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
97c24717ec67   hyperledger/fabric-peer:latest                                                                                                                                      "peer node start"        2 hours ago          Up 2 hours          0.0.0.0:7051->7051/tcp, :::7051->7051/tcp, 0.0.0.0:17051->17051/tcp, :::17051->17051/tcp                                              peer0.org1.example.com
ce6f3394ed3a   hyperledger/fabric-orderer:latest                                                                                                                                   "orderer"                2 hours ago          Up 2 hours          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
1c7659f9d566   couchdb:3.1.1                                                                                                                                                       "tini -- /docker-ent…"   2 hours ago          Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:7984->5984/tcp, :::7984->5984/tcp                                                                         couchdb1
ace56266acc3   couchdb:3.1.1                                                                                                                                                       "tini -- /docker-ent…"   2 hours ago          Up 2 hours          4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp, :::5984->5984/tcp                                                                         couchdb0
cd8ea5ad0ebe   hyperledger/fabric-ca:latest                                                                                                                                        "sh -c 'fabric-ca-se…"   2 hours ago          Up 2 hours          0.0.0.0:7054->7054/tcp, :::7054->7054/tcp, 0.0.0.0:17054->17054/tcp, :::17054->17054/tcp                                              ca_org1
8bba7383a710   hyperledger/fabric-ca:latest                                                                                                                                        "sh -c 'fabric-ca-se…"   2 hours ago          Up 2 hours          0.0.0.0:9054->9054/tcp, :::9054->9054/tcp, 7054/tcp, 0.0.0.0:19054->19054/tcp, :::19054->19054/tcp                                    ca_orderer
dd52a30af8ac   hyperledger/fabric-ca:latest                                                                                                                                        "sh -c 'fabric-ca-se…"   2 hours ago          Up 2 hours          0.0.0.0:8054->8054/tcp, :::8054->8054/tcp, 7054/tcp, 0.0.0.0:18054->18054/tcp, :::18054->18054/tcp                                    ca_org2
7fb9f53875b6   hyperledger/fabric-nodeenv:2.3                                                                                                                                      "docker-entrypoint.s…"   12 hours ago         Up 12 hours                                                                                                                                               mystifying_nash

以MagnettoCorp身份运行发行商业票据(切换至magnetocorp终端)

安装应用程序依赖

[root@localhost magnetocorp]# cd application
[root@localhost application]# npm install

将身份信息添加至钱包中

[root@localhost application]# node enrollUser.js
Wallet path: /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/magnetocorp/identity/user/isabella/wallet
Successfully enrolled client user "isabella" and imported it into the wallet

查看生成身份的位置

[root@localhost application]# tree ../identity/
../identity/
└── user└── isabella└── wallet└── isabella.id3 directories, 1 file

发行商业票据

[root@localhost application]# node issue.js
Connect to Fabric gateway.
Use network channel: mychannel.
Use org.papernet.commercialpaper smart contract.
Submit commercial paper issue transaction.
Process issue transaction response.{"class":"org.papernet.commercialpaper","currentState":1,"issuer":"MagnetoCorp","paperNumber":"00001","issueDateTime":"2020-05-31","maturityDateTime":"2020-11-30","faceValue":5000000,"mspid":"Org2MSP","owner":"MagnetoCorp"}
MagnetoCorp commercial paper : 00001 successfully issued for value 5000000
Transaction complete.
Disconnect from Fabric gateway.
Issue program complete.

以DigiBank身份运行购买、赎回商业票据(切换至digibank终端)

安装 应用程序依赖

[root@localhost digibank]# cd application
[root@localhost application]# npm install

将身份信息添加至钱包中

[root@localhost application]# node enrollUser.js
Wallet path: /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper/organization/digibank/identity/user/balaji/wallet
Successfully enrolled client user "balaji" and imported it into the wallet

购买商业票据

[root@localhost application]# node buy.js
Connect to Fabric gateway.
Use network channel: mychannel.
Use org.papernet.commercialpaper smart contract.
Submit commercial paper buy transaction.
Process buy transaction response.
MagnetoCorp commercial paper : 00001 successfully purchased by DigiBank
Transaction complete.
Disconnect from Fabric gateway.
Buy program complete.

赎回商业票据

[root@localhost application]# node redeem.js
Connect to Fabric gateway.
Use network channel: mychannel.
Use org.papernet.commercialpaper smart contract.
Submit commercial paper redeem transaction.
Process redeem transaction response.
MagnetoCorp commercial paper : 00001 successfully redeemed with MagnetoCorp
Transaction complete.
Disconnect from Fabric gateway.
Redeem program complete.

关闭网络(清理环境)

cd fabric-samples/commercial-paper
./network-clean.sh

参考文档:

官网文档:Commercial paper tutorial — hyperledger-fabricdocs master documentation

Fabric 测试网络 - 商业票据相关推荐

  1. M1芯片下Fabric测试网络环境配置

    M1芯片下Fabric测试网络环境配置 系统配置 系统:Ubuntu 20.04 LTS 内核:Arm64 硬盘大小:10GB 1.技术框架环境搭建 安装Vim sudo apt install -y ...

  2. 【区块链】使用 Fabric 测试网络

    首先,我们要回到官方文档 https://hyperledger-fabric.readthedocs.io/en/release-2.4/test_network.html 运行 fabric 测试 ...

  3. Hyperledger Fabric2.3 环境搭建及Fabric 测试网络使用

    一.安装ubuntu20 Download Ubuntu Desktop | Download | Ubuntu 二.安装环境 参考: Prerequisites - hyperledger-fabr ...

  4. Hyperledger Fabric 环境搭建及Fabric 测试网络使用(区块链、联盟链)

    一篇博文体验Hyperledger Fabric区块链 系统环境(CentOS): [root@localhost ~]# cat /proc/version Linux version 3.10.0 ...

  5. fabric测试网络启动警告解决:Local fabric binaries and docker images are out of sync. This may cause problems.

    警告信息: Local fabric binaries and docker images are out of sync. This may cause problems. Local fabric ...

  6. fabric测试网络运行与安装详细步骤

    建议在root命令下进行 如果在root下,输入go version后出现 Command 'go' not found, but can be installed with: snap instal ...

  7. fabric测试网络在peer节点上安装链码时报错解决

    报错信息: Error: chaincode install failed with status: 500 - failed to invoke backing implementation of ...

  8. Fabric 搭建测试网络并部署智能合约

    1.搭建网络: 详见博客 2.对Test Network的创建和关闭 cd ${HOME}/fabric-samples/test-network 创建网络: ./network.sh up关闭网络: ...

  9. Hyperledger Fabric 使用测试网络

    目录 1.先决条件 安装git.curl.wget 安装go语言 安装JDK 安装docker 安装docker-compose 2.使用测试网络 2.1下载fabric源码 2.2 启动网络 2.3 ...

最新文章

  1. #6284. 数列分块 8 分块
  2. 【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)
  3. 基础算法 —— 递归算法
  4. RabbitMQ小结
  5. java 反复器_java集合类中的枚举器(反复器)
  6. IOS开发比较实用的框架总结(上)
  7. Yii在控制层中引入模版进行渲染的几种方式。
  8. python股票交易系统是如何实现自动交易的?
  9. HMC5883L磁力计使用
  10. 超简洁WIN10桌面分享
  11. 实时系统vxWorks - 配置多网口
  12. Amlogic A311D2 八核 Arm 处理器支持高达 16GB RAM
  13. 车间生产管理系统(工厂数字化管理系统软件)
  14. SQL SERVER 2019卸载和安装
  15. XML中PCDATA与CDATA的区别
  16. nba全明星java_2018nba全明星阵容
  17. iFixit:苹果AirTag拆解,内部结构紧凑
  18. 【Java SE】抽象类和接口
  19. 雷达数据采集DCA1000EVM使用指南
  20. Direct3D 11 Devices

热门文章

  1. 温度传感器Pt100 热电阻的原理
  2. Forward warping and backward warping
  3. 35Java抽象类与抽象方法
  4. 中美知识产权博弈:保护力度标准成最大分歧
  5. 服务器主板开关电源维修,个人经验:开关电源不通电的修复
  6. mifi抓包实践一二三
  7. 4G双卡工业CPE及MIFI
  8. NSFC 国家自然科学基金查询
  9. 网络设备配置与管理-综合实验1
  10. Linux下配置网卡信息