Ordering network will help customers and outlets to come together on a platform to interact through BlockChain to create, update and transfer order from one place to another.
- Paticipants - Customer, Outlet
- Assets - Order
- Transactions - updateOrderStatus, transferOrder
- Events - orderStatusUpdateEvent, orderTransferEvent
- orderStatus - placed, received, prepared, dispatched, delivered, settled, cancelled, transferred
// Read as from : [to]
const allowedStateChanges = {
"placed" : ["received", "cancelled", "transferred"],
"received" : ["prepared", "cancelled", "transferred"],
"prepared" : ["dispatched", "cancelled", "transferred"],
"dispatched" : ["delivered", "cancelled"],
"delivered" : ["settled", "cancelled"],
"settled" : ["cancelled"],
"cancelled" : [],
"transferred" : ["received"]
}Events are more of a callback that will be recieved by your client application notifying that some transaction has been initated (either the final transaction state can be successful or aborted). for e.g.
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
const businessNetworkConnection = new BusinessNetworkConnection();
businessNetworkConnection.on('event', (event) => {
// Got an event from Chaincode (SmartContract)
});// From Chaincode
let event = getFactory().newEvent('com.box8', 'orderStatusUpdateEvent');
event.order = tx.order;
event.previousState = oldStatus;
event.newState = tx.newStatus;
emit(event);- Customer can create an Order (asset) at a particular Outlet.
- Customer can check details of their own order.
- Outlet can update order status or transfer order to another outlet.
- NetworkAdmin has all the permission.
- Create Participants e.g. Customers, Outlet.
- Create Asset (Order) and assign a Customer and Outlet.
- Outlet will submit
updateOrderStatustransaction of the order and eventorderStatusUpdateEventwill be invoked from Chaincode, which can in turn notify Customer who have placed the order (only after valid state change allowed). - Outlet can even transfer the order by submitting
transferOrdertransaction. Status of the order will change totransferred, after successful commit of transactionorderTransferEventwill be emitted. - Other outlet apps can listen to the
orderTransferEventand submitupdateOrderStatusto transaction to update Order Status. (e.g.transferredtoreceived).
You can debug the chaincode using composer-playground
Use below snippet to install and start composer-playground
npm install -g composer-playground
composer-playgroundIn web-browser connection, after installing your Business Network Archive use debugger statement inside transaction functions and open Developer Console to stop chaincode at any point. 🎉
For Example,
/**
* Update Order Status.
* @param {com.box8.updateOrderStatus} tx The sample transaction instance.
* @transaction
*/
async function updateOrderStatus(tx) {
// validate transaction parameters
debugger;
// update asset details
// emit events
}While your developer console is open, the chain code will halt at debugger; statement and you can check all available methods, scope variables defined for your transaction.