BigchainDB Collection
Use BigchainDB (scalable blockchain database) in your Meteor application just like you are using Mongo.
Project stage
Experimental.
Magic behind the scenes
Your application is still reading and writing to Mongo. Anything you write into Mongo is automatically written into BigchainDB in the background (triggered by after.insert hooks). And vice versa: Anything that is written directly into BigchainDB is written into Mongo (triggered by BDB event stream).
In short, Mongo database acts as a buffer between your application and BigchainDB database.
-
You can mix/join "off-chain" and "on-chain" data
-
Database writes are "reactive" (changes are instantly visible to all subscribed clients).
-
You can change any existing Meteor application to use BigchainDB with minimal code modifications (partly or entirelly).
Usage
Step 1
Add perak:bigchaindb-collection
package to your application
meteor add perak:bigchaindb-collection
Step 2
In both client and server scope, instead defining your collection as new Mongo.Collection
define it as new BDBCollection
1import { BDBCollection } from "meteor/bigchaindb-collection"; 2 3export const Fruits = new BDBCollection("fruits"); 4
Step 3
In server scope, define BDBConnection
(not to be confused with BDBCollection
), register your collections with the connection, provide keypair generator function and connect to BDB server:
1import { BDBConnection } from "meteor/bigchaindb-collection"; 2 3import { Fruits } from "path to file where your collection is defined"; 4 5// define BDB connection 6global.BDBC = BDBConection = new BDBConnection({ namespace: "test-app" }); 7 8// register all your BDB collections with the BDB connection 9BDBC.registerCollection(Fruits); 10 11// provide keypair generator 12BDBC.onKeypairRequest = function(userId, collectionName, doc) { 13 // Return keypair which will be used to sign BDB transaction. 14 // Most likely you will keep user's keypair in Meteor.users collection 15 // and here you can retrieve it based on userId argument. 16 // But, for purpose of this demo, let's generate dummy keypair 17 // based on fixed password 18 return BDBC.keypairFromPassword("password"); 19}; 20 21Meteor.startup({ 22 BDBC.connect({ 23 "url": "http://localhost:9984/api/v1/", 24 "eventsUrl": "ws://0.0.0.0:9985/api/v1/streams/valid_transactions", 25 "appId": "", 26 "appKey": "", 27 "namespace": "test-app" 28 }); 29}); 30
And... voilà! Your application is now storing data in BigchainDB - the scalable blockchain database.
To be continued...