Demo for MongoDB stitch as a store for blockchains
Revolutionary Blockchain technology meets MongoDB’s empowering backend service and Database for modern applications to create next generation solutions. Using Stitch platform will allow us to design and build the next decentralize, trusted and fraud free applications utilizing its newest features.
- 
In this workshop you will get to see live coding and build a hands-on application that is build with Stitch implementing a decentralized blockchain application. You will be able to use newest Stitch features such as Advanced Javascript functions and event driven notifications (Change Streams).
 - 
The nodes will use the anonymous Stitch authentication consuming only public information. Each node is allowed to edit only its information while the node consensus will be enforced by Stitch functions. Notifications will be the main component that notifies subscribers and pushes the processes forward until completion.
 - 
End peers (example bank accounts) may use a variety of authentication mechanisms available by Stitch to keep their data private and encrypted.
 
- You should have a 3.6+ Atlas cluster running with a new stitch app in place.
 - We are using the following 3rd party service for the demo
 
- https://ipstack.com/ - For IP information gathering. Please obtain your access key.
 - https://www.mapbox.com/ - For map visualization on the frontend app. Please obtain your access token
 
- Setup an Atlas cluster and stitch. See the following documentation.
 - Import the stitch skelaton app from this repo: stitch-blockchain.zip.
 - Create the following view and index in your cluster under database 
transactions: 
db.createView("blockchain","pending_blocks",
			[	{
					"$match" : {
						"index" : 0
					}
				},
				{
					"$graphLookup" : {
						"from" : "pending_blocks",
						"startWith" : "$previousHash",
						"connectFromField" : "hash",
						"connectToField" : "previousHash",
						"as" : "chain"
					}
				},
				{
					"$unwind" : "$chain"
				},
				{
					"$sort" : {
						"chain.index" : 1
					}
				},
				{
					"$group" : {
						"_id" : "$_id",
						"chain" : {
							"$push" : "$chain"
						}
					}
				},
				{
					"$project" : {
						"chain" : 1,
						"_id" : 0
					}
				}
			]);
db.pending_blocks.createIndex({index : 1},{unique : true});
- Create a mongodb readWrite user on databases: 
transactions,assets. Verify that the cluster name in the imported application is associated with your cluster name. - Edit the 
main.jsfile with the MongoDB credentials created in step 4 and the correct connection string for your Atlas cluster/ Stitch appId. Run the production of the blocks and Spin as many nodes as you see fit (Remember to whitelist your nodes IP's to the Atlas cluster). Remember they are scalable: 
npm install
node main.js
- Create a stitch email/password credentials through Authentication tab. Make sure that you update "values" stitch entry named 
ipstack_access_tokenwith value that equals to theipstackaccess token you have. - Edit the dummy 
stitch-blockchain/app.jsapplication with your stitch , editstitch-blockchain/mobileendpoint.htmland replace with your mapbox token. - Open the application 
stitch-blockchain/mobileendppoint.htmland input the credentials created in step 6. The blockchain should now work.