Real-time json cache for blockchain data.
feathers-giveth uses Feathersjs as a json cache for blockchain transaction history. The purpose is to ameliorate user wait times.
Feathersjs provides both a rest and websocket interface to database. Data itself is stored on the server file system use NeDB.
While this does nothing to speedup blockchain responses, it allows everyone connected to receive aggregate updates immediately via socketio push (aka pub/sub). This should hopefully simplify the code for the MVP, as it will not have worry about polling for all updates.
Getting up and running is as easy as 1, 2, 3.
-
Install your dependencies
cd path/to/feathers-giveth; npm install
note: due to a bug in yarn,
yarn install
currently does not work -
feathers will need to connect to an ethereum node via websockets. Typically this will be a local TestRPC instance. The configuration param
blockchain.nodeUrl
is used to establish a connection. The default nodeUrl isws://localhost:8546
-
we provide an easy way to start a TestRPC instance...
mkdir data/testrpc
-- this will contain the TestRPC databaseyarn testrpc
-- this will start testrpc with some default parameters
-
1 time only - deploy liquidPledging contract
node --harmony scripts/deploy.js
-
Start your app
yarn start
- note: due to a bug somewhere (testrpc? web3? websocket?) the subscription events may not always be picked-up in feathers.
especially the first time you run
yarn start
. It appears that testrpc is emitting the event correctly, but web3 Subscription is not recieving the message. If this happens, just restart feathers and all past events will be picked up.
- note: due to a bug somewhere (testrpc? web3? websocket?) the subscription events may not always be picked-up in feathers.
especially the first time you run
-
start a production server
yarn serve
The scripts
directory contains a few scripts to help development.
deploy.js
- deploys a new vault & liquidPledging contract
getState.js
- prints the current state of the deployed vault & liquidPledging contracts.
confirm.js
- confirms any payments that are pending in the vault
Simply run yarn test
and all your tests in the test/
directory will be run.
Each of these services are available via rest or websocket:
campaigns
dacs
donations
donationsHistory
milestones
uploads
users
To add another service use (after installing the feathers cli):
feathers generate service
Choose defaults for options as described here
Example to store new json object:
curl 'http://secret.com:3030/skunkworks/' -H 'Content-Type: application/json' --data-binary '{ "name": "Curler", "text": "Hello from the command line!" }'
Example to remove all json objects:
curl 'http://secret.com:3030/skunkworks/' -X "DELETE"
You may call these services from client web app using the feathers api.
Example to connect to donations service:
const socket = io();
const client = feathers();
client.configure(feathers.socketio(socket));
const donations = client.service('donations');
Example to get donation data from server db and do something for each stored json object (notice pagination):
donations.find().then(page => page.data.forEach(doSomethingWithJsonObject));
Example to subscribe to donations service create event assign it to named function:
donations.on('created', doSomethingWithJsonObject);
Using a microservice approach, services are seperated into seperate json databases (which are really just json data files on the server).
Currenlty there are no enforced fields for json objects. Required fields and types may be introduced later with hooks.
Currently there are no hooks but they can and will be added as a convenient way to execute operations that must occur on all requests (e.g. authorization, validation).
Checkout Feathersjs api service methods and service events and database querying.
0.1.0
- Initial release
Copyright (c) 2016
Licensed under the MIT license.