Fabric test network - commercial paper

Keywords: Blockchain fabric

catalogue

Create network

Create network

View the contents of the network-starter.sh file

View Fabric nodes

View docker network

Install and approve smart contracts as MagnetoCorp

Setting environment variables

Package smart contracts into chain codes

Install chain code (long time)

View packageID

Set packageID to an environment variable

Agree chain code definition

Install and approve smart contracts as DigiBank

Setting environment variables

Package smart contracts into chain codes

Install chain code (long time)

View packageID

Save packageID as an environment variable

Agree chain code definition

Submit chain code definition to channel

View chain code container

Run and issue commercial paper as MagnettoCorp (switch to magnetocorp terminal)

Install application dependencies

Add identity to Wallet

View the location of the generated identity

Issuance of commercial paper

Purchase and redeem commercial bills as digibank (switch to digibank terminal)

Install application dependencies

Add identity to Wallet

Purchase of commercial paper

Redemption of commercial paper

Shut down the network (clean up the environment)

Create network

Create network

[root@localhost ~]# cd /home/gopath/src/github.com/hyperledger/fabric/scripts/fabric-samples/commercial-paper                                          #Enter the commercial paper sample directory
[root@localhost commercial-paper]# ./network-starter.sh           #Create network
-bash: ./network-starter.sh: Permission denied                    #No authority
[root@localhost commercial-paper]# chmod +x network-starter.sh    #to grant authorization
[root@localhost commercial-paper]# ./network-starter.sh           #Create network again

View the contents of the network-starter.sh file

#!/bin/bash
#
# SPDX-License-Identifier: Apache-2.0

function _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"

View Fabric nodes

[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

View docker network

[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"
        }
    }
]

Install and approve smart contracts as MagnetoCorp

Setting environment variables

[root@localhost commercial-paper]# cd organization/magnetocorp/  #Enter directory
[root@localhost magnetocorp]# source magnetocorp.sh              #Setting environment variables
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

Package smart contracts into chain codes

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

  After successful packaging, the cp.tar.gz file appears in the directory

Install chain code (long time)

[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

If you encounter the above problems, clear the network and redeploy (use scientific Internet access). The results will be displayed after successful installation  

[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

View packageID

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

Set packageID to an environment variable

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

Agree chain code definition

[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

Install and approve smart contracts as DigiBank

Open a new terminal and enter the diaibank directory,

Setting environment variables

[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

Package smart contracts into chain codes

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

The cp.tar.gz file appears in the digibank directory

Install chain code (long time)

[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

View packageID

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

Save packageID as an environment variable

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

Agree chain code definition

[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

Submit chain code definition to channel

[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

View chain code container

After the chain code definition is submitted to the channel, a new Docker chain code container will be created and started. You can view the chain code container through 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

Run and issue commercial paper as MagnettoCorp (switch to magnetocorp terminal)

Install application dependencies

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

Add identity to Wallet

[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

View the location of the generated identity

[root@localhost application]# tree ../identity/
../identity/
└── user
    └── isabella
        └── wallet
            └── isabella.id

3 directories, 1 file

Issuance of commercial paper

[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.

Purchase and redeem commercial bills as digibank (switch to digibank terminal)

Install application dependencies

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

Add identity to Wallet

[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

Purchase of commercial paper

[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.

Redemption of commercial paper

[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.

Shut down the network (clean up the environment)

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

Reference documents:

Official website document: Commercial paper tutorial - hyperledger fabricdocs master documentation

Posted by xeelee on Fri, 05 Nov 2021 17:23:13 -0700