Running the project

Throughout the previous sections we have gone over Chaincode deployment, network setup and many other Fabric features. In this section, we will use the Fabric tool to run an end-to-end application for our food supply chain application. I assume here that you have already downloaded the project code from the Packt website.

To run the network we provide a bash script—fscn.sh—that leverages the Docker images to bootstrap a Hyperledger Fabric network quickly. You can run it using: sudo ./fscn.sh –m up

Once up, the script script.sh defined earlier will be executed. As a consequence, a series of events will be set in motion, including channel creation, the joining of all peers into the channel, the installation and instantiation of Chaincode in all peers, and the execution of different queries. These are all defined in script.sh, which is associated with utils.sh.

The following picture shows the execution results of the first part of the script, ending with the creation of the channel, fscchannel:

All the functions defined in the Chaincode will be called within script.sh. For the sake of brevity, we present here the output showing the result of the invocation of the createRawFood method:

This is the result of the execution of chaincodeInvokeCreateRawFood defined in the utils.sh script as follows:

#create rawfood by invoke chaincode
chaincodeInvokeCreateRawFood() {
PEER=$1
ORG=$2
setGlobals $PEER $ORG
if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; then
peer chaincode invoke -o orderer.fsc.com:7050 -C $CHANNEL_NAME -n fsccc -c '{"Args":["createRawFood","order_001"]}' >&log.txt
else
peer chaincode invoke -o orderer.fsc.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n fsccc -c '{"Args":["createRawFood","order_001"]}' >&log.txt
fi
res=$?
cat log.txt
verifyResult $res "Invoke:CreateRawFood execution on PEER$PEER failed "
echo "Invoke:CreateRawFood transaction on PEER $PEER on channel '$CHANNEL_NAME' is successful. "
echo
}

At the end, we can see the result of querying the Chaincode for the current food state data:

At this level, we are able to communicate with the deployed Chaincode through Linux scripts and commands. I know you might find it a bit tricky, therefore, in the following sections, we will use a more abstract approach using RESTful calls.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset