Hyperledger Part 3 - Putting it all together - Video Transcript (English) ### BEGIN ### Hyperledger Composer allows you to quickly build and test Blockchain applications. In this video I'll give you a tour of the final network you'll build as part of the series. Here's what you'll see: * Clone the iot-perishable-network-advanced from GitHub * Tour the model * Tour the chaincode * Tour the network's permissions * Tour the Cucumber tests * Build and run unit tests * Deploy the network * Issue ID cards for all participants * Run transactions through the CLI This video accompanies Part 3 of my Hyperledger Composer Tutorial series which you can find only at IBM Developer A link to the series is in the video description Let's get started. Open a Terminal window, navigate to your COMPOSER_ROOT directory. And enter the git clone command: COMMAND: git clone https://github.com/jstevenperry/IBM-Developer Open the iot-perishable-network-advanced directory in VSCode. When you've finished making changes from Part 3 your model should look like this. Click on the model file to open it in the editor window. Here's what changed from the network you completed in Part 2: There are three new transactions: Shipment Packed Shipment Pickup Shipment Loaded Three new participants: IoTDevice - an abstract participant, and two subclasses of it: TemperatureSensor GpsSensor And four new events: ShipmentPackedEvent ShipmentPickupEvent ShipmentLoadedEvent ShipmentReceivedEvent I renamed the payout() function to receiveShipment() to better reflect what it does Three new functions for each of the three new transactions were added to the model: packShipment() corresponding to the ShipmentPacked transaction pickupShipment() for ShipmentPickup, and loadShipment() for ShipmentLoaded And finally, setupDemo() was modified to add: Temperature sensor, and GPS sensor The rules are named like Participant, underscore, operations, underscore, resource. I added new rules to restrict access for various Participants. So this rule is for Grower, to grant read access to the Grower resource. Growers need read access to Growers. Shippers need read access to Shippers. The Importer needs read AND update access to the importer, and the Grower so it can update the balances when it receives a Shipment. Next up are rules for accessing assets. In this case, any participant can read and update the Contract and Shipment assets. Here are the rules for transactions. Only a Grower can invoke (or Create) a ShipmentPacked transaction. Only a Shipper can invoke a ShipmentPickup or ShipmentLoaded transaction. Only a GpsSensor can invoke the GpsReading transaction. Only a TemperatureSensor can invoke the TemperatureReading transaction. And only an Importer can invoke the ShipmentReceived transaction. Finally, there is the default rule, which denies access to any resource not listed above. This is a catch-all rule, which by default locks down access to anything you forget to explicitly lock down. I cover the Cucumber tests in great detail in the Tutorial, so I won't belabor them here. Each Cucumber feature test is in a file with a .feature extension. iot-perishable.feature contains the basic test scenarios that apply across all participants grower.feature contains test scenarios for Growers sensors.feature contains test scenarios for the IoT Temperature and GPS sensors And shipper.feature contains test scenarios specific to Shippers Open a Terminal window or command prompt, and navigate to the iot-perishable-network-advanced directory. Run this command: COMMAND: npm install && npm test It takes a few minutes to install all of the dependencies, and then build the model. When the npm install script has completed, the unit tests run. When you see this message, you know all of the unit tests ran successfully. Make sure Docker is running. From a separate terminal window or command prompt, completely tear down the Fabric and remove the Docker images. This is just to make sure you get a clean install of your network. First, execute the teardownAllDocker.sh command and choose Option 2 to remove all Docker images. COMMAND: ./teardownAllDocker.sh Now delete the contents of your .composer directory, to clean up all the old cards. COMMAND: rm -Rf ~/.composer Then, start the Fabric COMMAND: ./startFabric.sh It'll take a few minutes to download the Docker images again. This may seem like overkill, but it guarantees your Fabric will be clean from any other networks you've installed during development. Once the Fabric is running, create the PeerAdmin card: COMMAND: ./createPeerAdminCard.sh Now you're ready to deploy your network (END SCREEN CAP) (SCREEN CAP: deploy-network) First, install the network: COMMAND: composer network install --card PeerAdmin@hlfv1 --archiveFile dist/iot-perishable-network.bna Then start the network: COMMAND: composer network start --networkName iot-perishable-network --networkVersion 0.2.6 --networkAdmin admin --networkAdminEnrollSecret adminpw --card PeerAdmin@hlfv1 --file networkadmin.card And import the network admin card: COMMAND: composer card import --file networkadmin.card Finally, run the setupDemo transaction to instantiate the model: COMMAND: composer transaction submit --card admin@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.SetupDemo"}' To verify that the model has been instantiated run the composer network list command: COMMAND: composer network list --card admin@iot-perishable-network All of the assets and participants are present and accounted for. In order for the Participants to interact with the network they need credentials. First, issue an ID card for the Grower: COMMAND: composer identity issue --card admin@iot-perishable-network --file grower1.card --newUserId grower1 --participantId 'resource:org.acme.shipping.perishable.Grower#farmer@email.com' The format for each command is: composer identity issue, and the parameters are: --card and the card name for the network admin --file and the name of the card file to be issued --newUserId and the userid associated with the card --participantId and the fully qualified name of the resource from the model I'll paste in the rest of the commands to save time Next, the shipper: COMMAND: composer identity issue --card admin@iot-perishable-network --file shipper1.card --newUserId shipper1 --participantId 'resource:org.acme.shipping.perishable.Shipper#shipper@email.com' The Importer: COMMAND: composer identity issue --card admin@iot-perishable-network --file importer1.card --newUserId importer1 --participantId 'resource:org.acme.shipping.perishable.Importer#supermarket@email.com' The IoT devices need credentials too so they can interact with the network. First the Temperature sensor: COMMAND: composer identity issue --card admin@iot-perishable-network --file sensor_temp1.card --newUserId sensor_temp1 --participantId 'resource:org.acme.shipping.perishable.TemperatureSensor#SENSOR_TEMP001' And the GPS sensor: COMMAND: composer identity issue --card admin@iot-perishable-network --file sensor_gps1.card --newUserId sensor_gps1 --participantId 'resource:org.acme.shipping.perishable.GpsSensor#SENSOR_GPS001' Now import all of the cards into the network so they can be used. First, the Grower: This command looks like composer card import --file and the name of the card file that was issued. The credentials in the card file will be imported. COMMAND: composer card import --file grower1.card I'll paste in the rest of the commands to save time. The Shipper: COMMAND: composer card import --file shipper1.card The Importer: COMMAND: composer card import --file importer1.card The IoT Temperature sensor: COMMAND: composer card import --file sensor_temp1.card And the IoT GPS sensor: COMMAND: composer card import --file sensor_gps1 To verify all the cards were imported run composer card list: COMMAND: composer card list When the network runs for real transactions will be initiated by the various participants. You can simulate that through the CLI. When a shipment is packed for transport, the Grower submits a ShipmentPacked transaction to let all the participants know the shipment is ready for pickup: COMMAND: composer transaction submit --card grower1@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.ShipmentPacked", "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' Next, the shipper picks up the shipment from the Grower, and submits the ShipmentPickup transaction: COMMAND: composer transaction submit --card shipper1@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.ShipmentPickup", "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' Then the Shipper loads the shipment for transport, and submits the ShipmentLoaded transaction: COMMAND: composer transaction submit --card shipper1@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.ShipmentLoaded", "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' During transport, the Temperature sensors in the shipping container are taking readings, each time a reading is taken, a TemperatureReading transaction is recorded to the blockchain: COMMAND: composer transaction submit --card sensor_temp1@iot-perishable-network -d '{ "$class": "org.acme.shipping.perishable.TemperatureReading", "centigrade": 2, "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' The GPS sensor is sending readings all during the journey. Finally, when the shipment reaches the port of New York/New Jersey, the GPS sensor submits this transaction, which is recorded in the blockchain ledger: COMMAND: composer transaction submit --card sensor_gps1@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.GpsReading", "readingTime": "2200", "readingDate": "20181111", "latitude": "40.6840", "latitudeDir": "N", "longitude": "74.0062", "longitudeDir": "W", "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' The final step in the workflow is the ShipmentReceived transaction, which is submitted by the Importer when they have received the shipment: COMMAND: composer transaction submit --card importer1@iot-perishable-network -d '{"$class": "org.acme.shipping.perishable.ShipmentReceived", "shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"}' To see these transactions, fire up the REST server using the admin@iot-perishable-network card to authenticate, or you won't be able to see all of the transactions. Point your browser to localhost, port 3000 Expand the Shipment asset. Execute the transaction using HTTP GET to see all of the data for the shipment. There it is, SHIP_001, 5000 bananas, and in ARRIVED status. There you can see the temperature readings that were taken. The GPS reading. And the various Shipment-related transactions. Again, the network you've just seen is in GitHub. A link to the repo is in the video description. The iot-perishable-network-advanced, a more realistic blockchain network. Complete with IoT sensors. Be sure to check out my Hyperledger Composer Basics Tutorial series, available only at IBM Developer. You'll find a link in the video description. I hope you enjoyed the video. I'm Steve Perry. Thanks for watching! I'll see you next time. ### END ###